-
![]()
+
@@ -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 '';