From 98a53588c381bdcdea111cb1deddc06f6c7f1c28 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期四, 09 四月 2026 14:12:09 +0800
Subject: [PATCH] fix(用户管理): 修复编辑用户时部门显示问题并增加员工密码初始化

---
 src/views/collaborativeApproval/knowledgeBase/index.vue |  197 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 187 insertions(+), 10 deletions(-)

diff --git a/src/views/collaborativeApproval/knowledgeBase/index.vue b/src/views/collaborativeApproval/knowledgeBase/index.vue
index bdaf0b4..ff8da1b 100644
--- a/src/views/collaborativeApproval/knowledgeBase/index.vue
+++ b/src/views/collaborativeApproval/knowledgeBase/index.vue
@@ -133,6 +133,41 @@
             </el-form-item>
           </el-col>
         </el-row>
+        <el-form-item label="闄勪欢鏉愭枡" prop="files">
+          <el-upload
+            v-model:file-list="fileList"
+            :action="upload.url"
+            multiple
+            ref="fileUpload"
+            auto-upload
+            :headers="upload.headers"
+            :before-upload="handleBeforeUpload"
+            :on-error="handleUploadError"
+            :on-success="handleUploadSuccess"
+            :on-remove="handleRemove"
+            :on-preview="handlePreview"
+            :show-file-list="true"
+          >
+            <el-button type="primary">涓婁紶</el-button>
+            <template #file="{ file }">
+              <div style="display:flex; align-items:center; gap: 10px; width: 100%;">
+                <span style="flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
+                  {{ file.name }}
+                </span>
+                <div style="display:flex; align-items:center; gap: 6px;">
+                  <el-button link type="success" :icon="Download" @click="handleDownload(file)" />
+                  <el-button link type="primary" :icon="View" @click="handlePreview(file)" />
+                  <el-button link type="danger" :icon="Delete" @click="triggerRemoveFile(file)" />
+                </div>
+              </div>
+            </template>
+            <template #tip>
+              <div class="el-upload__tip">
+                鏀寔鏂囨。锛坉oc, docx, xls, xlsx, pdf, txt锛夊拰鍥剧墖锛坖pg, jpeg, png, gif锛夋牸寮�
+              </div>
+            </template>
+          </el-upload>
+        </el-form-item>
       </el-form>
     </FormDialog>
 
@@ -198,6 +233,17 @@
           </div>
         </div>
 
+        <div class="detail-section" v-if="currentKnowledge.commonFileList && currentKnowledge.commonFileList.length > 0">
+          <h4>闄勪欢鏉愭枡</h4>
+          <div class="file-list">
+            <div v-for="file in currentKnowledge.commonFileList" :key="file.id" class="file-item">
+              <div class="file-info">
+                <el-link :href="file.url" target="_blank" :download="file.name">{{ file.name }}</el-link>
+              </div>
+            </div>
+          </div>
+        </div>
+
         <div class="detail-section">
           <h4>浣跨敤缁熻</h4>
           <div class="usage-stats">
@@ -225,18 +271,21 @@
         </div>
       </div>
     </FormDialog>
+    <filePreview ref="filePreviewRef" />
   </div>
 </template>
 
 <script setup>
-import { Search } from "@element-plus/icons-vue";
+import { Search, Download, View, Delete } from "@element-plus/icons-vue";
 import { onMounted, ref, reactive, toRefs, getCurrentInstance, computed, watch } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
 import PIMTable from "@/components/PIMTable/PIMTable.vue";
 import FormDialog from '@/components/Dialog/FormDialog.vue';
-import { listKnowledgeBase, delKnowledgeBase,addKnowledgeBase,updateKnowledgeBase } from "@/api/collaborativeApproval/knowledgeBase.js";
+import filePreview from '@/components/filePreview/index.vue'
+import { listKnowledgeBase, delKnowledgeBase,addKnowledgeBase,updateKnowledgeBase, delKnowledgeBaseFile } from "@/api/collaborativeApproval/knowledgeBase.js";
 import useUserStore from '@/store/modules/user';
 import { userListNoPageByTenantId } from '@/api/system/user.js';
+import { getToken } from "@/utils/auth";
 
 // 琛ㄥ崟楠岃瘉瑙勫垯
 const rules = {
@@ -268,6 +317,13 @@
   },
   tableData: [],
   selectedIds: [],
+  fileList: [],
+  upload: {
+    // 涓婁紶鐨勫湴鍧�
+    url: import.meta.env.VITE_APP_BASE_API + "/file/upload",
+    // 璁剧疆涓婁紶鐨勮姹傚ご閮�
+    headers: { Authorization: "Bearer " + getToken() },
+  },
   form: {
     title: "",
     type: "",
@@ -277,7 +333,8 @@
     solution: "",
     keyPoints: "",
     creator: "",
-    usageCount: 0
+    usageCount: 0,
+    files: []
   },
   dialogVisible: false,
   dialogTitle: "",
@@ -292,6 +349,8 @@
   page,
   tableData,
   selectedIds,
+  fileList,
+  upload,
   form,
   dialogVisible,
   dialogTitle,
@@ -302,9 +361,30 @@
 
 // 琛ㄥ崟寮曠敤
 const formRef = ref();
+const fileUpload = ref()
+const filePreviewRef = ref()
 // 鐢ㄦ埛鐩稿叧
 const userStore = useUserStore();
 const userList = ref([]);
+
+const normalizeKnowledgeFiles = (files = []) => {
+  const list = Array.isArray(files) ? files : []
+  return list.map((f, index) => {
+    const name = f?.name || f?.originalName || f?.fileName || ''
+    const url = f?.url || f?.path || ''
+    return {
+      ...f,
+      name,
+      url,
+      uid: f?.uid || f?.id || `${Date.now()}_${index}`,
+      status: f?.status || 'success',
+    }
+  })
+}
+
+const getUploadFileUrl = (file) => {
+  return file?.url || file?.response?.data?.tempPath || file?.response?.data?.url
+}
 
 // 琛ㄦ牸鍒楅厤缃�
 const tableColumn = ref([
@@ -462,6 +542,7 @@
   if (type === "add") {
     dialogTitle.value = "鏂板鐭ヨ瘑";
     // 閲嶇疆琛ㄥ崟锛岄粯璁ゅ垱寤轰汉涓哄綋鍓嶇敤鎴�
+    fileList.value = [];
     Object.assign(form.value, {
       title: "",
       type: "",
@@ -471,10 +552,14 @@
       solution: "",
       keyPoints: "",
       creator: userStore.nickName || "",
-      usageCount: 0
+      usageCount: 0,
+      files: []
     });
   } else if (type === "edit" && row) {
     dialogTitle.value = "缂栬緫鐭ヨ瘑";
+    const existingFiles = row.files || row.commonFileList || [];
+    const normalizedFiles = normalizeKnowledgeFiles(existingFiles);
+    fileList.value = normalizedFiles;
     Object.assign(form.value, {
       id: row.id,
       title: row.title,
@@ -485,7 +570,15 @@
       solution: row.solution,
       keyPoints: row.keyPoints,
       creator: row.creator,
-      usageCount: row.usageCount
+      usageCount: row.usageCount,
+      files: normalizedFiles.map(f => ({
+        id: f.id,
+        tempId: f.tempId,
+        name: f.name,
+        url: f.url,
+        uid: f.uid
+      })),
+      
     });
   }
   dialogVisible.value = true;
@@ -577,6 +670,7 @@
 // 鍏抽棴鐭ヨ瘑琛ㄥ崟瀵硅瘽妗�
 const closeKnowledgeDialog = () => {
   // 娓呯┖琛ㄥ崟鏁版嵁锛岄粯璁ゅ垱寤轰汉涓哄綋鍓嶇敤鎴�
+  fileList.value = [];
   Object.assign(form.value, {
     id: undefined,
     title: "",
@@ -587,7 +681,8 @@
     solution: "",
     keyPoints: "",
     creator: userStore.nickName || "",
-    usageCount: 0
+    usageCount: 0,
+    files: []
   });
   // 娓呴櫎琛ㄥ崟楠岃瘉鐘舵��
   if (formRef.value) {
@@ -606,6 +701,88 @@
   copyKnowledge();
   closeViewDialog();
 };
+
+// 涓婁紶鍓嶆牎妫�
+function handleBeforeUpload(file) {
+  proxy.$modal.loading("姝e湪涓婁紶鏂囦欢锛岃绋嶅��...");
+  return true;
+}
+// 涓婁紶澶辫触
+function handleUploadError(err) {
+  proxy.$modal.msgError("涓婁紶鏂囦欢澶辫触");
+  proxy.$modal.closeLoading();
+}
+// 涓婁紶鎴愬姛鍥炶皟
+function handleUploadSuccess(res, file, uploadFiles) {
+  proxy.$modal.closeLoading();
+  if (res.code === 200) {
+    if (!form.value.files) {
+      form.value.files = [];
+    }
+    file.tempId = res?.data?.tempId
+    file.url = res?.data?.tempPath || res?.data?.url
+    file.name = res?.data?.originalName || file?.name
+    form.value.files.push({
+      tempId: file.tempId,
+      url: file.url,
+      name: file.name,
+      uid: file.uid,
+    });
+    proxy.$modal.msgSuccess("涓婁紶鎴愬姛");
+  } else {
+    proxy.$modal.msgError(res.msg);
+    fileUpload.value?.handleRemove?.(file) || proxy.$refs.fileUpload?.handleRemove?.(file);
+  }
+}
+// 绉婚櫎鏂囦欢
+function handleRemove(file, fileList) {
+  // 濡傛灉鏄紪杈戞ā寮忎笖鏂囦欢鏈塱d锛岃皟鐢ˋPI鍒犻櫎
+  if (dialogType.value === "edit" && file.id) {
+    delKnowledgeBaseFile([file.id]).then((res) => {
+      if (res.code === 200) {
+        proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+        // 浠巉orm.value.files涓Щ闄�
+        const index = form.value.files.findIndex(f => f.id === file.id);
+        if (index > -1) {
+          form.value.files.splice(index, 1);
+        }
+      } else {
+        proxy.$modal.msgError(res.msg || "鍒犻櫎澶辫触");
+        // 濡傛灉鍒犻櫎澶辫触锛岄噸鏂版坊鍔犲洖鏂囦欢鍒楄〃
+        fileList.push(file);
+      }
+    }).catch((error) => {
+      proxy.$modal.msgError("鍒犻櫎澶辫触");
+      // 濡傛灉鍒犻櫎澶辫触锛岄噸鏂版坊鍔犲洖鏂囦欢鍒楄〃
+      fileList.push(file);
+    });
+  } else {
+    // 鏂颁笂浼犵殑鏂囦欢锛岀洿鎺ヤ粠form.value.files涓Щ闄�
+    const index = form.value.files.findIndex(f => f.name === file.name && f.url === file.url);
+    if (index > -1) {
+      form.value.files.splice(index, 1);
+    }
+  }
+}
+
+// 鏂囦欢棰勮/涓嬭浇
+const handleDownload = (file) => {
+  const url = getUploadFileUrl(file)
+  if (!url) return
+  proxy?.$modal?.loading?.("姝e湪涓嬭浇鏂囦欢锛岃绋嶅��...")
+  proxy.$download.name(url);
+  proxy?.$modal?.closeLoading?.()
+}
+
+function handlePreview(file) {
+  const url = getUploadFileUrl(file)
+  if (!url) return
+  filePreviewRef.value?.open?.(url)
+}
+
+function triggerRemoveFile(file) {
+  fileUpload.value?.handleRemove?.(file) || proxy.$refs.fileUpload?.handleRemove?.(file);
+}
 
 // 鎻愪氦鐭ヨ瘑琛ㄥ崟
 const submitForm = async () => {
@@ -719,12 +896,12 @@
 }
 
 .detail-content {
-  background: #f8f9fa;
-  padding: 16px;
-  border-radius: 6px;
   line-height: 1.6;
   color: #606266;
-  white-space: pre-wrap;
+}
+
+.detail-section {
+  margin-top: 24px;
 }
 
 .key-points {

--
Gitblit v1.9.3