Merge pull request #968 from smallclover/main

追加快捷键
This commit is contained in:
Tim
2025-09-10 18:09:18 +08:00
committed by GitHub
2 changed files with 54 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
package com.openisle.schdule; package com.openisle.scheduler;
import com.openisle.config.CachingConfig; import com.openisle.config.CachingConfig;
import com.openisle.model.User; import com.openisle.model.User;

View File

@@ -6,8 +6,15 @@
</div> </div>
<div class="comment-bottom-container"> <div class="comment-bottom-container">
<div class="comment-submit" :class="{ disabled: isDisabled }" @click="submit"> <div class="comment-submit" :class="{ disabled: isDisabled }" @click="submit">
<template v-if="!loading"> 发布评论 </template> <template v-if="!loading">
<template v-else> <loading-four /> 发布中... </template> 发布评论
<span class="shortcut-icon" v-if="!isMobile">
{{ isMac ? '' : 'Ctrl' }}
</span>
</template>
<template v-else>
<loading-four /> 发布中...
</template>
</div> </div>
</div> </div>
</div> </div>
@@ -24,6 +31,7 @@ import {
} from '~/utils/vditor' } from '~/utils/vditor'
import '~/assets/global.css' import '~/assets/global.css'
import LoginOverlay from '~/components/LoginOverlay.vue' import LoginOverlay from '~/components/LoginOverlay.vue'
import { useIsMobile } from '~/utils/screen'
export default { export default {
name: 'CommentEditor', name: 'CommentEditor',
@@ -52,12 +60,22 @@ export default {
}, },
components: { LoginOverlay }, components: { LoginOverlay },
setup(props, { emit }) { setup(props, { emit }) {
const isMobile = useIsMobile()
const vditorInstance = ref(null) const vditorInstance = ref(null)
const text = ref('') const text = ref('')
const editorId = ref(props.editorId) const editorId = ref(props.editorId)
if (!editorId.value) { if (!editorId.value) {
editorId.value = 'editor-' + useId() editorId.value = 'editor-' + useId()
} }
const isMac = ref(false)
if (navigator.userAgentData) {
isMac.value = navigator.userAgentData.platform === 'macOS'
} else {
isMac.value = /Mac|iPhone|iPad|iPod/.test(navigator.userAgent)
}
const getEditorTheme = getEditorThemeUtil const getEditorTheme = getEditorThemeUtil
const getPreviewTheme = getPreviewThemeUtil const getPreviewTheme = getPreviewThemeUtil
const applyTheme = () => { const applyTheme = () => {
@@ -96,7 +114,27 @@ export default {
applyTheme() applyTheme()
}, },
}) })
// applyTheme() // 不是手机的情况下不添加快捷键
if(!isMobile.value){
// 添加快捷键监听 (Ctrl+Enter 或 Cmd+Enter)
const handleKeydown = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault()
submit()
}
}
const el = document.getElementById(editorId.value)
if (el) {
el.addEventListener('keydown', handleKeydown)
}
onUnmounted(() => {
if (el) {
el.removeEventListener('keydown', handleKeydown)
}
})
}
}) })
onUnmounted(() => { onUnmounted(() => {
@@ -134,7 +172,7 @@ export default {
}, },
) )
return { submit, isDisabled, editorId } return { submit, isDisabled, editorId, isMac, isMobile}
}, },
} }
</script> </script>
@@ -174,10 +212,16 @@ export default {
.comment-submit:hover { .comment-submit:hover {
background-color: var(--primary-color-hover); background-color: var(--primary-color-hover);
} }
/** 评论按钮快捷键样式 */
@media (max-width: 768px) { .shortcut-icon {
.comment-editor-container { padding: 2px 6px;
margin-bottom: 10px; border-radius: 6px;
} font-size: 12px;
font-weight: 500;
line-height: 1.2;
background-color: rgba(0, 0, 0, 0.25);
}
.comment-submit.disabled .shortcut-icon {
background-color: rgba(0, 0, 0, 0);
} }
</style> </style>