diff --git a/src/components/TEditor/index.vue b/src/components/TEditor/index.vue index 7bf39eb..810c5a5 100644 --- a/src/components/TEditor/index.vue +++ b/src/components/TEditor/index.vue @@ -96,7 +96,7 @@ const props = defineProps({ }); const loading = ref(false); const tinymceId = ref( - "vue-tinymce-" + +new Date() + ((Math.random() * 1000).toFixed(0) + "") + "vue-tinymce-" + +new Date() + ((Math.random() * 1000).toFixed(0) + "") ); const baseUrl = import.meta.env.VITE_APP_BASE_API @@ -217,8 +217,10 @@ const init = reactive({ // 设置初始化内容(初始化结束后执行) init_instance_callback: function (editor) { console.log('初始化内容', props.value) - editor.setContent(props.value); // 设置默认文本内容 - emits('update:modelValue', editor.getContent()) //更新 + if (props.value) { + editor.setContent(props.value); // 设置默认文本内容 + emits('update:modelValue', editor.getContent()) //更新 + } // 设置高度 editor.getContainer().setAttribute("style", `height: ${props.height}px;`); }, @@ -234,19 +236,19 @@ const myValue = computed({ }, }); - + // 监听富文本中的数据变化 -watch( - () => myValue.value, - () => { - emits( - "setHtml", - tinymce.activeEditor.getContent({ format: "text" }), - myValue.value - ); - } -); +// watch( +// () => myValue.value, +// () => { +// emits( +// "setHtml", +// tinymce.activeEditor.getContent({ format: "text" }), +// myValue.value +// ); +// } +// ); // 设置编辑器只读模式 watch( @@ -277,13 +279,13 @@ window.onresize = function temp() { }; // 设置值 -const handleSetContent = (content) => { +const handleSetContent = (content) => { tinymce.activeEditor.setContent(content); }; // 获取值 const handleGetContent = () => { - return tinymce.activeEditor.getContent(); + return tinymce.activeEditor.getContent(); }; const updateModelValue = (val) => { @@ -305,14 +307,14 @@ const updateModelValue = (val) => { }) } const checkEmptyContent = (editor) => { - const plainText = editor.getContent({ format: 'text' }).trim() - const htmlContent = editor.getContent() - - // 检测常见空内容情况 - return plainText === '' || - htmlContent === '' || - htmlContent === '


' || - htmlContent === '

 

' + const plainText = editor.getContent({ format: 'text' }).trim() + const htmlContent = editor.getContent() + + // 检测常见空内容情况 + return plainText === '' || + htmlContent === '' || + htmlContent === '


' || + htmlContent === '

 

' } diff --git a/src/views/databaseLibary/components/card.vue b/src/views/databaseLibary/components/card.vue index 64f1b52..295698d 100644 --- a/src/views/databaseLibary/components/card.vue +++ b/src/views/databaseLibary/components/card.vue @@ -12,7 +12,7 @@
- +
@@ -46,6 +46,7 @@ import deleteIcon from '@/assets/images/deleteIcon.png' import { getBusEncyclopediaDatabasePage } from "@/api/databaseLibary" const router = useRouter() +const baseUrl = import.meta.env.VITE_APP_BASE_API const queryParams = ref({ pageIndex: 1, pageSize: 10, diff --git a/src/views/databaseLibary/components/libaryForm.vue b/src/views/databaseLibary/components/libaryForm.vue index f94c5f5..05f0cde 100644 --- a/src/views/databaseLibary/components/libaryForm.vue +++ b/src/views/databaseLibary/components/libaryForm.vue @@ -54,7 +54,7 @@ :label="item.label" :value="item.value" @change="handleChangeTwoType(item.value)" /> - + @@ -152,6 +152,7 @@ const levelList = ref([ { title: '新建', path: '/databaseLibaryForm' }, ]) const baseUrl = import.meta.env.VITE_APP_BASE_API +const organPicRef = ref(null) const formTitle = ref('新建') // 显示相关链接数据 const showTableData = ref([]) @@ -178,25 +179,28 @@ const { ruleForm, rules } = toRefs(data) // 初始化 onMounted(() => { - getLast10Years(); - getBusDependencyData(); - const id = route.params && route.params.Id - if (id) { - ruleForm.value.id = id - formTitle.value = '编辑' - getDetailInfo(id) - levelList.value = [ - { title: '百科数据库', path: '/databaseLibary' }, - { title: '编辑', path: '/databaseLibaryForm' }, - ] - } else { - ruleForm.value.id = null - formTitle.value = '新建' - levelList.value = [ - { title: '百科数据库', path: '/databaseLibary' }, - { title: '新建', path: '/databaseLibaryForm' }, - ] - } + nextTick(() => { + getLast10Years(); + getBusDependencyData(); + const id = route.params && route.params.Id + if (id) { + ruleForm.value.id = id + formTitle.value = '编辑' + getDetailInfo(id) + levelList.value = [ + { title: '百科数据库', path: '/databaseLibary' }, + { title: '编辑', path: '/databaseLibaryForm' }, + ] + } else { + ruleForm.value.id = null + formTitle.value = '新建' + levelList.value = [ + { title: '百科数据库', path: '/databaseLibary' }, + { title: '新建', path: '/databaseLibaryForm' }, + ] + } + }); + }); // 年度数据 @@ -230,16 +234,38 @@ const getDetailInfo = (id) => { getBusEncyclopediaDatabase(id).then(res => { if (res.code == 200) { ruleForm.value = res.data - categorySelectedValue.value = [res.data.category] - categoryTwoSelectedValue.value = [res.data.categoryTwo] - editorRef.value.handleSetContent(res.data.mainText) - docUploadList.value = JSON.parse(res.data.fileContent) - - res.data.encyclopediaDatabaseLinkList.forEach(item => { - item.editFlag = false - showTableData.value.push(item) - cachShowTableData.value.push(item) + // 确保分类数据是数组 + categorySelectedValue.value = res.data.category ? [res.data.category] : [] + categoryTwoSelectedValue.value = res.data.categoryTwo ? [res.data.categoryTwo] : [] + + // 处理链接数据 + if (Array.isArray(res.data.encyclopediaDatabaseLinkList)) { + res.data.encyclopediaDatabaseLinkList.forEach(item => { + item.editFlag = false + showTableData.value.push({ ...item }) // 深拷贝避免污染 + cachShowTableData.value.push({ ...item }) + }) + } + // 安全解析 + 默认值处理 + const parsedFiles = res.data.fileContent + ? JSON.parse(res.data.fileContent) + : [] + + // 确保是数组且包含必要字段 + docUploadList.value = Array.isArray(parsedFiles) + ? parsedFiles.map(file => ({ + name: file.name || String(file.name), + url: file.url || '', + status: 'success', + uid: file.uid || Date.now() + })) + : [] + + + nextTick(() => { + if (res.data.organPic) organPicRef.value.setFileInfo(res.data.organPic) }); + } }) } @@ -256,6 +282,9 @@ const handleChangeTwoType = (value) => { console.log('二级类目选择值', value) categoryTwoSelectedValue.value = [value] // 始终保持数组只有一个元素 ruleForm.value.categoryTwo = value + nextTick(() => { + if (res.data.organPic) organPicRef.value.setFileInfo(ruleForm.value.organPic) + }); } // 设置组织架构图 const handleSetorganPic = (filePath) => { @@ -308,11 +337,15 @@ const requestDocUpload = (options) => { formData.append('file', file); uploadFile(formData).then(res => { if (res.code == 200) { - docUploadList.value.push({ - name: res.originalFilename, - url: baseUrl + res.fileName, - suffix: res.suffix - }) + docUploadList.value = [ + ...docUploadList.value, + { + name: res.originalFilename, + url: baseUrl + res.fileName, + status: 'success', // 必须字段 + uid: Date.now() + Math.random() + } + ] } else { proxy.$modal.msgError(res.msg); } @@ -321,8 +354,8 @@ const requestDocUpload = (options) => { // 移除已上传文件列表 const removeDocUpload = (file, fileList) => { docUploadList.value = docUploadList.value.filter( - item => item.name != file.name - ); + item => item.uid !== file.uid // 通过唯一标识符比对 + ) } diff --git a/src/views/databaseLibary/components/myFileUpload.vue b/src/views/databaseLibary/components/myFileUpload.vue index 3f71d2c..1fed0af 100644 --- a/src/views/databaseLibary/components/myFileUpload.vue +++ b/src/views/databaseLibary/components/myFileUpload.vue @@ -41,6 +41,7 @@ const dialogVisible = ref(false) const suffix = ref('') const setFileInfo = (filePath) => { + console.log('接收', filePath) // 处理无后缀名情况 if (!filePath || filePath.indexOf('.') === -1) return '';