| | |
| | | <view class="upload-tip" v-if="!readonly"> |
| | | 支持文档(doc, docx, xls, xlsx, pdf, txt)和图片(jpg, jpeg, png, gif)格式 |
| | | </view> |
| | | <view class="file-list" v-if="form.commonFileList && form.commonFileList.length > 0"> |
| | | <view v-for="(file, index) in form.commonFileList" :key="index" class="file-item"> |
| | | <view class="file-list" v-if="form.files && form.files.length > 0"> |
| | | <view v-for="(file, index) in form.files" :key="index" class="file-item"> |
| | | <up-icon name="file-text" size="20" color="#667eea"></up-icon> |
| | | <text class="file-name" @click="previewFile(file)">{{ file.name || file.fileName }}</text> |
| | | <text class="file-name">{{ file.name || file.fileName }}</text> |
| | | <up-icon v-if="!readonly" name="close-circle-fill" size="18" color="#ff4d4f" @click="handleRemoveFile(index)"></up-icon> |
| | | </view> |
| | | </view> |
| | |
| | | import { |
| | | addKnowledgeBase, |
| | | updateKnowledgeBase, |
| | | delKnowledgeBaseFile, |
| | | } from "@/api/managementMeetings/knowledgeBase"; |
| | | import { userListNoPageByTenantId } from "@/api/system/user"; |
| | | import upload from "@/utils/upload"; |
| | | import { getToken } from "@/utils/auth"; |
| | | import config from "@/config"; |
| | | |
| | | defineOptions({ name: "knowledge-base-detail" }); |
| | | |
| | |
| | | creator: userStore.nickName || "", |
| | | usageCount: 0, |
| | | tempFileIds: [], |
| | | commonFileList: [] |
| | | files: [] |
| | | }); |
| | | |
| | | // 选择器状态 |
| | |
| | | if (!form.value.tempFileIds) form.value.tempFileIds = []; |
| | | form.value.tempFileIds.push(res.data.tempId); |
| | | |
| | | if (!form.value.commonFileList) form.value.commonFileList = []; |
| | | form.value.commonFileList.push({ |
| | | id: res.data.tempId, |
| | | if (!form.value.files) form.value.files = []; |
| | | form.value.files.push({ |
| | | tempId: res.data.tempId, |
| | | name: item.name || '未命名文件', |
| | | url: res.data.url |
| | | url: res.data.url || res.data.tempPath |
| | | }); |
| | | |
| | | showToast('上传成功'); |
| | |
| | | |
| | | const deleteFile = (event) => { |
| | | const { index } = event; |
| | | form.value.commonFileList.splice(index, 1); |
| | | if (form.value.tempFileIds) { |
| | | form.value.tempFileIds.splice(index, 1); |
| | | } |
| | | handleRemoveFile(index); |
| | | }; |
| | | |
| | | const handleRemoveFile = (index) => { |
| | | form.value.commonFileList.splice(index, 1); |
| | | if (form.value.tempFileIds) { |
| | | form.value.tempFileIds.splice(index, 1); |
| | | const handleRemoveFile = async (index) => { |
| | | const list = Array.isArray(form.value.files) |
| | | ? form.value.files |
| | | : []; |
| | | const file = list[index]; |
| | | if (!file) return; |
| | | |
| | | const fileId = file.id; |
| | | const tempId = file.tempId || file.tempFileId; |
| | | const isEditMode = detailType.value === 2; |
| | | const canDeleteRemote = isEditMode && !!fileId; |
| | | |
| | | try { |
| | | if (canDeleteRemote) { |
| | | uni.showLoading({ title: "删除中...", mask: true }); |
| | | const res = await delKnowledgeBaseFile([fileId]); |
| | | uni.hideLoading(); |
| | | if (res.code !== 200) { |
| | | showToast(res.msg || "删除失败"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | form.value.files.splice(index, 1); |
| | | if (form.value.tempFileIds) { |
| | | const idx = form.value.tempFileIds.findIndex( |
| | | v => String(v) === String(tempId || fileId) |
| | | ); |
| | | if (idx > -1) form.value.tempFileIds.splice(idx, 1); |
| | | } |
| | | } catch (e) { |
| | | uni.hideLoading(); |
| | | console.error("删除附件失败:", e); |
| | | showToast("删除失败"); |
| | | } |
| | | }; |
| | | |
| | | const previewFile = (file) => { |
| | | console.log("previewFile", file); |
| | | if (file.url) { |
| | | // 如果是图片,预览图片 |
| | | const isImage = /\.(jpg|jpeg|png|gif)$/i.test(file.name || file.fileName || file.url); |
| | |
| | | } else { |
| | | // 其他文件尝试打开 |
| | | uni.downloadFile({ |
| | | url: file.url, |
| | | url: file.url.startsWith("http") ? file.url : (config.baseUrl + file.url), |
| | | header: { |
| | | Authorization: "Bearer " + getToken(), |
| | | }, |
| | | success: (res) => { |
| | | if (res.statusCode === 200) { |
| | | uni.openDocument({ |
| | |
| | | if (!knowledgeId.value || String(data.id) === String(knowledgeId.value)) { |
| | | form.value = JSON.parse(JSON.stringify(data)); |
| | | // 兼容处理文件列表 |
| | | if (form.value.commonFileList) { |
| | | form.value.tempFileIds = form.value.commonFileList.map(f => f.id || f.tempId); |
| | | if (form.value.files) { |
| | | const ids = (form.value.files || []) |
| | | .map(f => f?.tempId || f?.tempFileId || f?.id) |
| | | .filter(v => v !== undefined && v !== null && v !== ""); |
| | | form.value.tempFileIds = ids; |
| | | } |
| | | if (!Array.isArray(form.value.files)) { |
| | | form.value.files = []; |
| | | } |
| | | } |
| | | } |