富文本编辑器优化

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

View File

@ -95,7 +95,7 @@
</el-col> </el-col>
<el-col :lg="24"> <el-col :lg="24">
<el-form-item label="内容" prop="noticeContent"> <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-form-item>
</el-col> </el-col>
</el-row> </el-row>
@ -140,6 +140,33 @@ const data = reactive({
noticeType: [{ required: true, message: '公告类型不能为空', trigger: 'change' }] 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 statusOptions = ref([])
const typeOptions = ref([]) const typeOptions = ref([])
proxy.getDicts('sys_notice_status').then((response) => { proxy.getDicts('sys_notice_status').then((response) => {