From 9506b4ba45a478ff5132d04587d56a64cce079c1 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 13 一月 2026 15:16:38 +0800
Subject: [PATCH] fix: 完成知识库,用印管理

---
 src/views/collaborativeApproval/knowledgeBase/index.vue |  181 +++++++--------------------------------------
 1 files changed, 28 insertions(+), 153 deletions(-)

diff --git a/src/views/collaborativeApproval/knowledgeBase/index.vue b/src/views/collaborativeApproval/knowledgeBase/index.vue
index cb643ad..aeb1ba4 100644
--- a/src/views/collaborativeApproval/knowledgeBase/index.vue
+++ b/src/views/collaborativeApproval/knowledgeBase/index.vue
@@ -13,11 +13,12 @@
         />
         <span class="search_title ml10">鐭ヨ瘑绫诲瀷锛�</span>
         <el-select v-model="searchForm.type" clearable @change="handleQuery" style="width: 240px">
-          <el-option label="鍚堝悓鐗规壒" :value="'contract'" />
-          <el-option label="瀹℃壒妗堜緥" :value="'approval'" />
-          <el-option label="瑙e喅鏂规" :value="'solution'" />
-          <el-option label="缁忛獙鎬荤粨" :value="'experience'" />
-          <el-option label="鎿嶄綔鎸囧崡" :value="'guide'" />
+          <el-option
+              v-for="item in knowledgeTypeOptions"
+              :key="item.value"
+              :label="item.label"
+              :value="item.value"
+          />
         </el-select>
         <el-button type="primary" @click="handleQuery" style="margin-left: 10px">
           鎼滅储
@@ -61,11 +62,12 @@
           <el-col :span="12">
             <el-form-item label="鐭ヨ瘑绫诲瀷" prop="type">
               <el-select v-model="form.type" placeholder="璇烽�夋嫨鐭ヨ瘑绫诲瀷" style="width: 100%">
-                <el-option label="鍚堝悓鐗规壒" value="contract" />
-                <el-option label="瀹℃壒妗堜緥" value="approval" />
-                <el-option label="瑙e喅鏂规" value="solution" />
-                <el-option label="缁忛獙鎬荤粨" value="experience" />
-                <el-option label="鎿嶄綔鎸囧崡" value="guide" />
+                <el-option
+                    v-for="item in knowledgeTypeOptions"
+                    :key="item.value"
+                    :label="item.label"
+                    :value="item.value"
+                />
               </el-select>
             </el-form-item>
           </el-col>
@@ -231,7 +233,7 @@
 
 <script setup>
 import { Search } from "@element-plus/icons-vue";
-import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
+import { onMounted, ref, reactive, toRefs, getCurrentInstance, computed } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
 import PIMTable from "@/components/PIMTable/PIMTable.vue";
 import { listKnowledgeBase, delKnowledgeBase,addKnowledgeBase,updateKnowledgeBase } from "@/api/collaborativeApproval/knowledgeBase.js";
@@ -313,24 +315,10 @@
     prop: "type",
     dataType: "tag",
     formatData: (params) => {
-      const typeMap = {
-        contract: "鍚堝悓鐗规壒",
-        approval: "瀹℃壒妗堜緥",
-        solution: "瑙e喅鏂规",
-        experience: "缁忛獙鎬荤粨",
-        guide: "鎿嶄綔鎸囧崡"
-      };
-      return typeMap[params] || params;
+      return getKnowledgeTypeLabel(params);
     },
     formatType: (params) => {
-      const typeMap = {
-        contract: "success",
-        approval: "warning",
-        solution: "primary",
-        experience: "info",
-        guide: "danger"
-      };
-      return typeMap[params] || "info";
+      return getKnowledgeTypeTagType(params);
     }
   },
   {
@@ -401,111 +389,6 @@
   }
 ]);
 
-// 妯℃嫙鏁版嵁
-// let mockData = [
-//   {
-//     id: "1",
-//     title: "鐗规畩鍚堝悓瀹℃壒娴佺▼浼樺寲鏂规",
-//     type: "contract",
-//     scenario: "澶ч鍚堝悓蹇�熷鎵�",
-//     efficiency: "high",
-//     problem: "澶ч鍚堝悓瀹℃壒娴佺▼澶嶆潅锛屽鎵规椂闂撮暱锛屽奖鍝嶄笟鍔¤繘灞�",
-//     solution: "寤虹珛缁胯壊閫氶亾锛屽绗﹀悎鏉′欢鐨勫悎鍚岄噰鐢ㄧ畝鍖栧鎵规祦绋嬶紝鐢遍儴闂ㄨ礋璐d汉鐩存帴瀹℃壒锛屽钩鍧囧鎵规椂闂翠粠3澶╃缉鐭嚦1澶�",
-//     keyPoints: "缁胯壊閫氶亾鏉′欢,绠�鍖栨祦绋�,瀹℃壒鏉冮檺,鏃堕棿鎺у埗",
-//     creator: "寮犵粡鐞�",
-//     usageCount: 15,
-//     createTime: "2024-01-15 10:30:00"
-//   },
-//   {
-//     id: "2",
-//     title: "璺ㄩ儴闂ㄥ崗浣滃鎵圭粡楠屾�荤粨",
-//     type: "experience",
-//     scenario: "澶氶儴闂ㄥ崗浣滈」鐩�",
-//     efficiency: "medium",
-//     problem: "璺ㄩ儴闂ㄩ」鐩鎵规椂锛屽悇閮ㄩ棬鎰忚涓嶇粺涓�锛屽鎵硅繘搴︾紦鎱�",
-//     solution: "寤虹珛椤圭洰鍗忚皟鏈哄埗锛屾寚瀹氶」鐩礋璐d汉锛屽畾鏈熷彫寮�鍗忚皟浼氳锛岀粺涓�鍚勬柟鎰忚鍚庡啀杩涜瀹℃壒",
-//     keyPoints: "椤圭洰鍗忚皟,瀹氭湡浼氳,缁熶竴鎰忚,璐熻矗浜哄埗搴�",
-//     creator: "鏉庝富绠�",
-//     usageCount: 8,
-//     createTime: "2024-01-14 15:20:00"
-//   },
-//   {
-//     id: "3",
-//     title: "绱ф�ラ噰璐鎵规搷浣滄寚鍗�",
-//     type: "guide",
-//     scenario: "绱ф�ラ噰璐渶姹�",
-//     efficiency: "high",
-//     problem: "绱ф�ラ噰璐椂瀹℃壒娴佺▼澶嶆潅锛屾棤娉曟弧瓒崇揣鎬ラ渶姹�",
-//     solution: "鍒跺畾绱ф�ラ噰璐鎵规爣鍑嗭紝鏄庣‘绱ф�ョ▼搴﹀垎绾э紝涓嶅悓绾у埆閲囩敤涓嶅悓瀹℃壒娴佺▼锛岀‘淇濈揣鎬ラ渶姹傚緱鍒板強鏃跺鐞�",
-//     keyPoints: "绱ф�ュ垎绾�,鏍囧噯鍒跺畾,娴佺▼绠�鍖�,鍙婃椂澶勭悊",
-//     creator: "鐜嬩笓鍛�",
-//     usageCount: 12,
-//     createTime: "2024-01-13 09:15:00"
-//   }
-// ];
-
-// 鐭ヨ瘑鏍囬妯℃澘
-const titleTemplates = [
-  "{type}瀹℃壒娴佺▼浼樺寲鏂规",
-  "{scenario}澶勭悊缁忛獙鎬荤粨",
-  "{type}鐗规畩鎯呭喌澶勭悊鎸囧崡",
-  "{scenario}蹇�熷鎵规柟妗�",
-  "{type}鏍囧噯鍖栨搷浣滄祦绋�",
-  "{scenario}闂瑙e喅鏂规",
-  "{type}鏈�浣冲疄璺垫�荤粨",
-  "{scenario}鏁堢巼鎻愬崌鏂规"
-];
-
-// 鐭ヨ瘑绫诲瀷閰嶇疆
-const knowledgeTypes = [
-  { type: "contract", label: "鍚堝悓鐗规壒", efficiency: "high" },
-  { type: "approval", label: "瀹℃壒妗堜緥", efficiency: "medium" },
-  { type: "solution", label: "瑙e喅鏂规", efficiency: "high" },
-  { type: "experience", label: "缁忛獙鎬荤粨", efficiency: "medium" },
-  { type: "guide", label: "鎿嶄綔鎸囧崡", efficiency: "low" }
-];
-
-// 鍦烘櫙鍒楄〃
-const scenarios = ["澶ч鍚堝悓瀹℃壒", "璺ㄩ儴闂ㄥ崗浣�", "绱ф�ラ噰璐�", "鐗规畩鐢宠", "娴佺▼浼樺寲", "闂澶勭悊", "鏍囧噯鍖栧缓璁�", "鏁堢巼鎻愬崌"];
-
-// 鑷姩鐢熸垚鏂版暟鎹�
-const generateNewData = () => {
-  const newId = (mockData.length + 1).toString();
-  const now = new Date();
-  const randomType = knowledgeTypes[Math.floor(Math.random() * knowledgeTypes.length)];
-  const randomScenario = scenarios[Math.floor(Math.random() * scenarios.length)];
-
-  // 鐢熸垚闅忔満鏍囬
-  let title = titleTemplates[Math.floor(Math.random() * titleTemplates.length)];
-  title = title
-    .replace('{type}', randomType.label)
-    .replace('{scenario}', randomScenario);
-
-  const newKnowledge = {
-    id: newId,
-    title: title,
-    type: randomType.type,
-    scenario: randomScenario,
-    efficiency: randomType.efficiency,
-    problem: `鍦�${randomScenario}杩囩▼涓亣鍒扮殑闂鎻忚堪...`,
-    solution: `閽堝${randomScenario}鐨勮В鍐虫柟妗堝拰鎿嶄綔姝ラ...`,
-    keyPoints: "鍏抽敭瑕佺偣1,鍏抽敭瑕佺偣2,鍏抽敭瑕佺偣3,鍏抽敭瑕佺偣4",
-    creator: ["寮犵粡鐞�", "鏉庝富绠�", "鐜嬩笓鍛�", "鍒樻�荤洃"][Math.floor(Math.random() * 4)],
-    usageCount: Math.floor(Math.random() * 20) + 1,
-    createTime: now.toLocaleString()
-  };
-
-  // 娣诲姞鍒版暟鎹紑澶�
-  mockData.unshift(newKnowledge);
-
-  // 淇濇寔鏁版嵁閲忓湪鍚堢悊鑼冨洿鍐咃紙鏈�澶氫繚鐣�30鏉★級
-  if (mockData.length > 30) {
-    mockData = mockData.slice(0, 30);
-  }
-
-  console.log(`[${new Date().toLocaleString()}] 鑷姩鐢熸垚鏂扮煡璇�: ${title}`);
-};
-
 // 鐢熷懡鍛ㄦ湡
 onMounted(() => {
   getList();
@@ -515,7 +398,6 @@
 // 寮�濮嬭嚜鍔ㄥ埛鏂�
 const startAutoRefresh = () => {
   setInterval(() => {
-    generateNewData();
     getList();
   }, 600000); // 10鍒嗛挓鍒锋柊涓�娆� (10 * 60 * 1000 = 600000ms)
 };
@@ -605,14 +487,7 @@
 
 // 鑾峰彇绫诲瀷鏍囩鏂囨湰
 const getTypeLabel = (type) => {
-  const typeMap = {
-    contract: "鍚堝悓鐗规壒",
-    approval: "瀹℃壒妗堜緥",
-    solution: "瑙e喅鏂规",
-    experience: "缁忛獙鎬荤粨",
-    guide: "鎿嶄綔鎸囧崡"
-  };
-  return typeMap[type] || type;
+  return getKnowledgeTypeLabel(type);
 };
 
 // 鑾峰彇鏁堢巼鏍囩绫诲瀷
@@ -675,18 +550,6 @@
   });
 };
 
-// 鏀惰棌鐭ヨ瘑
-const markAsFavorite = () => {
-  // 澧炲姞浣跨敤娆℃暟
-  const index = mockData.findIndex(item => item.id === currentKnowledge.value.id);
-  if (index !== -1) {
-    mockData[index].usageCount += 1;
-    currentKnowledge.value.usageCount += 1;
-  }
-
-  ElMessage.success("宸叉敹钘忥紝浣跨敤娆℃暟+1");
-};
-
 // 鎻愪氦鐭ヨ瘑琛ㄥ崟
 const submitForm = async () => {
   try {
@@ -745,6 +608,18 @@
 
 // 瀵煎嚭
 const { proxy } = getCurrentInstance()
+const { knowledge_type } = proxy.useDict("knowledge_type")
+
+// 瀛楀吀宸ュ叿
+const knowledgeTypeOptions = computed(() => knowledge_type?.value || [])
+const getKnowledgeTypeLabel = (val) => {
+  const item = knowledgeTypeOptions.value.find(i => String(i.value) === String(val))
+  return item ? item.label : val
+}
+const getKnowledgeTypeTagType = (val) => {
+  const item = knowledgeTypeOptions.value.find(i => String(i.value) === String(val))
+  return item?.elTagType || "info"
+}
 const handleExport = () => {
   proxy.download('/knowledgeBase/export', { ...searchForm.value }, '鐭ヨ瘑搴�.xlsx')
 }

--
Gitblit v1.9.3