富文本编辑器优化

This commit is contained in:
不做码农 2023-08-07 18:17:45 +08:00
parent e62a10a6f2
commit f411cda24e
2 changed files with 44 additions and 13 deletions

View File

@ -21,17 +21,21 @@ export default {
props: {
placeholder: {
type: String,
default: () => '请输入内容',
default: () => '请输入内容'
},
modelValue: String,
//
toolbarConfig: {
type: [Object],
default: () => {}
}
},
setup(props, { emit }) {
const editorRef = shallowRef()
const valueHtml = ref(props.modelValue)
const toolbarConfig = {}
const editorConfig = {
MENU_CONF: {},
placeholder: props.placeholder,
placeholder: props.placeholder
}
//
editorConfig.MENU_CONF['uploadImage'] = {
@ -49,7 +53,7 @@ export default {
// http header
headers: {
Authorization: 'Bearer ' + getToken(),
userid: useUserStore().userId,
userid: useUserStore().userId
},
// cookie false
withCredentials: true,
@ -61,7 +65,7 @@ export default {
// res url alt href
insertFn(res.data.url)
)
},
}
}
//
editorConfig.MENU_CONF['uploadVideo'] = {
@ -84,7 +88,7 @@ export default {
// http header
headers: {
Authorization: 'Bearer ' + getToken(),
userid: useUserStore().userId,
userid: useUserStore().userId
},
// cookie false
@ -97,7 +101,7 @@ export default {
// res url alt href
insertFn(res.data.url)
)
},
}
}
onBeforeUnmount(() => {
const editor = editorRef.value
@ -118,18 +122,18 @@ export default {
editor.clear()
return
}
valueHtml.value = value;
},
valueHtml.value = value
}
)
return {
editorRef,
valueHtml,
mode: 'default',
toolbarConfig,
editorConfig,
handleCreated,
handleChange,
toolbarConfig: props.toolbarConfig
}
},
}
}
</script>

View File

@ -95,7 +95,7 @@
</el-col>
<el-col :lg="24">
<el-form-item label="内容" prop="noticeContent">
<editor v-model="form.noticeContent" :min-height="196" />
<editor v-model="form.noticeContent" :toolbarConfig="toolbarConfig" :min-height="196" />
</el-form-item>
</el-col>
</el-row>
@ -140,6 +140,33 @@ const data = reactive({
noticeType: [{ required: true, message: '公告类型不能为空', trigger: 'change' }]
}
})
const toolbarConfig = ref({
toolbarKeys: [
// key
'headerSelect',
'bold', //
'italic', //
'through', // 线
'underline', // 线
'bulletedList', //
'numberedList', //
'color', //
'uploadImage', //
'delIndent', //
'indent', //
'insertLink', //
'fontSize', //
'clearStyle', //
'divider', // 线
'insertTable', //
'justifyCenter', //
'justifyJustify', //
'justifyLeft', //
'justifyRight', //
'fullScreen' //
]
})
const statusOptions = ref([])
const typeOptions = ref([])
proxy.getDicts('sys_notice_status').then((response) => {