Merge pull request #410 from WoJiaoFuXiaoYun/main

feat: vditor add loading
This commit is contained in:
Tim
2025-08-06 17:25:58 +08:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -19,10 +19,9 @@ import { clearVditorStorage } from '../utils/clearVditorStorage'
import { hatch } from 'ldrs' import { hatch } from 'ldrs'
hatch.register() hatch.register()
export default { export default {
name: 'PostEditor', name: 'PostEditor',
emits: ['update:modelValue'], emits: ['update:modelValue', 'update:loading'],
props: { props: {
modelValue: { modelValue: {
type: String, type: String,
@@ -43,6 +42,8 @@ export default {
}, },
setup(props, { emit }) { setup(props, { emit }) {
const vditorInstance = ref(null) const vditorInstance = ref(null)
let vditorRender = false
const getEditorTheme = getEditorThemeUtil const getEditorTheme = getEditorThemeUtil
const getPreviewTheme = getPreviewThemeUtil const getPreviewTheme = getPreviewThemeUtil
const applyTheme = () => { const applyTheme = () => {
@@ -54,6 +55,7 @@ export default {
watch( watch(
() => props.loading, () => props.loading,
val => { val => {
if (!vditorRender) return
if (val) { if (val) {
vditorInstance.value.disabled() vditorInstance.value.disabled()
} else { } else {
@@ -91,12 +93,15 @@ export default {
) )
onMounted(() => { onMounted(() => {
emit('update:loading', true)
vditorInstance.value = createVditor(props.editorId, { vditorInstance.value = createVditor(props.editorId, {
placeholder: '请输入正文...', placeholder: '请输入正文...',
input(value) { input(value) {
emit('update:modelValue', value) emit('update:modelValue', value)
}, },
after() { after() {
vditorRender = true
emit('update:loading', false)
vditorInstance.value.setValue(props.modelValue) vditorInstance.value.setValue(props.modelValue)
if (props.loading || props.disabled) { if (props.loading || props.disabled) {
vditorInstance.value.disabled() vditorInstance.value.disabled()
@@ -120,6 +125,7 @@ export default {
.post-editor-container { .post-editor-container {
border: 1px solid var(--normal-border-color); border: 1px solid var(--normal-border-color);
position: relative; position: relative;
min-height: 200px;
} }
.editor-loading-overlay { .editor-loading-overlay {

View File

@@ -3,7 +3,7 @@
<div class="new-post-form"> <div class="new-post-form">
<input class="post-title-input" v-model="title" placeholder="标题" /> <input class="post-title-input" v-model="title" placeholder="标题" />
<div class="post-editor-container"> <div class="post-editor-container">
<PostEditor v-model="content" :loading="isAiLoading" :disabled="!isLogin" /> <PostEditor v-model="content" v-model:loading="isAiLoading" :disabled="!isLogin" />
<LoginOverlay v-if="!isLogin" /> <LoginOverlay v-if="!isLogin" />
</div> </div>
<div class="post-options"> <div class="post-options">