:zap:富文本编辑器优化

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
+15 -11
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>
+28 -1
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) => {