fix(richtext): 为富文本编辑器上传图片添加token认证头

添加用户token到图片上传请求头中,确保有权限的用户才能上传文件
This commit is contained in:
piexlMax(奇淼 2025-09-01 15:17:58 +08:00
parent 8b0a00b98a
commit 9e688c65d3
1 changed files with 5 additions and 0 deletions

View File

@ -27,6 +27,7 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { getUrl } from '@/utils/image' import { getUrl } from '@/utils/image'
import { useUserStore } from '@/pinia/modules/user'
const emits = defineEmits(['change', 'update:modelValue']) const emits = defineEmits(['change', 'update:modelValue'])
@ -35,6 +36,7 @@
emits('update:modelValue', valueHtml.value) emits('update:modelValue', valueHtml.value)
} }
const userStore = useUserStore()
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
type: String, type: String,
@ -53,6 +55,9 @@
editorConfig.MENU_CONF['uploadImage'] = { editorConfig.MENU_CONF['uploadImage'] = {
fieldName: 'file', fieldName: 'file',
server: basePath + '/fileUploadAndDownload/upload?noSave=1', server: basePath + '/fileUploadAndDownload/upload?noSave=1',
headers: {
'x-token': userStore.token,
},
customInsert(res, insertFn) { customInsert(res, insertFn) {
if (res.code === 0) { if (res.code === 0) {
const urlPath = getUrl(res.data.file.url) const urlPath = getUrl(res.data.file.url)