fix: 切换语言/主题 编辑器禁用状态不匹配
This commit is contained in:
parent
610c007558
commit
460a5ff494
@ -109,7 +109,7 @@ const contentCss = computed(() => {
|
|||||||
* 通过v-if来挂载/卸载组件
|
* 通过v-if来挂载/卸载组件
|
||||||
* 来完成主题切换/语言切换
|
* 来完成主题切换/语言切换
|
||||||
*/
|
*/
|
||||||
const changeTheme = ref(true);
|
const init = ref(true);
|
||||||
watch(
|
watch(
|
||||||
() => [preferences.theme.mode, preferences.app.locale],
|
() => [preferences.theme.mode, preferences.app.locale],
|
||||||
() => {
|
() => {
|
||||||
@ -117,10 +117,16 @@ watch(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destroy();
|
destroy();
|
||||||
changeTheme.value = false;
|
init.value = false;
|
||||||
// 放在下一次tick来切换
|
// 放在下一次tick来切换
|
||||||
|
// 需要先加载组件 也就是v-if为true 然后需要拿到editorRef 必须放在setTimeout(相当于onMounted)
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
changeTheme.value = true;
|
init.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
// 需要手动设置只读/编辑状态
|
||||||
|
const mode = props.options.readonly ? 'readonly' : 'design';
|
||||||
|
editorRef.value?.mode.set(mode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -144,7 +150,7 @@ const initOptions = computed((): InitOptions => {
|
|||||||
content_css: contentCss.value,
|
content_css: contentCss.value,
|
||||||
content_style:
|
content_style:
|
||||||
'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
|
'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
|
||||||
// contextmenu: 'link image table',
|
contextmenu: 'link image table',
|
||||||
default_link_target: '_blank',
|
default_link_target: '_blank',
|
||||||
height,
|
height,
|
||||||
image_advtab: true, // 图片高级选项
|
image_advtab: true, // 图片高级选项
|
||||||
@ -161,8 +167,8 @@ const initOptions = computed((): InitOptions => {
|
|||||||
*/
|
*/
|
||||||
paste_data_images: true,
|
paste_data_images: true,
|
||||||
plugins,
|
plugins,
|
||||||
// quickbars_selection_toolbar:
|
quickbars_selection_toolbar:
|
||||||
// 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
|
'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
|
||||||
skin: skinName.value,
|
skin: skinName.value,
|
||||||
toolbar,
|
toolbar,
|
||||||
toolbar_mode: 'sliding',
|
toolbar_mode: 'sliding',
|
||||||
@ -210,17 +216,6 @@ watch(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
|
||||||
() => attrs.disabled,
|
|
||||||
() => {
|
|
||||||
const editor = unref(editorRef);
|
|
||||||
if (!editor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editor.mode.set(attrs.disabled ? 'readonly' : 'design');
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!initOptions.value.inline) {
|
if (!initOptions.value.inline) {
|
||||||
tinymceId.value = buildShortUUID('tiny-vue');
|
tinymceId.value = buildShortUUID('tiny-vue');
|
||||||
@ -298,15 +293,7 @@ function bindModelHandlers(editor: any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
const disabled = computed(() => props.options.readonly ?? false);
|
||||||
* disabled
|
|
||||||
* 可使用:options="{readonly: true}"
|
|
||||||
* 或者:disabled="true"
|
|
||||||
*/
|
|
||||||
const disabled = computed(
|
|
||||||
() =>
|
|
||||||
(props.options.readonly ?? false) || ((attrs.disabled as boolean) ?? false),
|
|
||||||
);
|
|
||||||
|
|
||||||
function getUploadingImgName(name: string) {
|
function getUploadingImgName(name: string) {
|
||||||
return `[uploading:${name}]`;
|
return `[uploading:${name}]`;
|
||||||
@ -345,7 +332,7 @@ function handleDone(name: string, url: string) {
|
|||||||
@uploading="handleImageUploading"
|
@uploading="handleImageUploading"
|
||||||
/>
|
/>
|
||||||
<Editor
|
<Editor
|
||||||
v-if="!initOptions.inline && changeTheme"
|
v-if="!initOptions.inline && init"
|
||||||
v-model="modelValue"
|
v-model="modelValue"
|
||||||
:init="initOptions"
|
:init="initOptions"
|
||||||
:style="{ visibility: 'hidden' }"
|
:style="{ visibility: 'hidden' }"
|
||||||
|
@ -16,7 +16,7 @@ const content = ref('');
|
|||||||
<span>只读</span>
|
<span>只读</span>
|
||||||
<a-switch v-model:checked="readonly" />
|
<a-switch v-model:checked="readonly" />
|
||||||
</div>
|
</div>
|
||||||
<Tinymce v-model="content" :disabled="readonly" :height="800" />
|
<Tinymce v-model="content" :height="800" :options="{ readonly }" />
|
||||||
</div>
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user