From af4f913751c08fd6ef70cb183de2fb3c604bab38 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 31 十月 2025 16:33:15 +0800
Subject: [PATCH] 人力资源-添加导出功能
---
src/views/collaborativeApproval/knowledgeBase/index.vue | 240 +++++++++++++++++++++++++++--------------------------------
1 files changed, 109 insertions(+), 131 deletions(-)
diff --git a/src/views/collaborativeApproval/knowledgeBase/index.vue b/src/views/collaborativeApproval/knowledgeBase/index.vue
index 06fdeca..cb643ad 100644
--- a/src/views/collaborativeApproval/knowledgeBase/index.vue
+++ b/src/views/collaborativeApproval/knowledgeBase/index.vue
@@ -24,11 +24,12 @@
</el-button>
</div>
<div>
+ <el-button @click="handleExport" style="margin-right: 10px">瀵煎嚭</el-button>
<el-button type="primary" @click="openForm('add')">鏂板鐭ヨ瘑</el-button>
<el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>
</div>
</div>
-
+
<div class="table_list">
<PIMTable
rowKey="id"
@@ -221,7 +222,7 @@
<span class="dialog-footer">
<el-button @click="viewDialogVisible = false">鍏抽棴</el-button>
<el-button type="primary" @click="copyKnowledge">澶嶅埗鐭ヨ瘑</el-button>
- <el-button type="success" @click="markAsFavorite">鏀惰棌</el-button>
+ <!-- <el-button type="success" @click="markAsFavorite">鏀惰棌@</el-button> -->
</span>
</template>
</el-dialog>
@@ -230,9 +231,10 @@
<script setup>
import { Search } from "@element-plus/icons-vue";
-import { onMounted, ref, reactive, toRefs } from "vue";
+import { onMounted, ref, reactive, toRefs, getCurrentInstance } 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";
// 琛ㄥ崟楠岃瘉瑙勫垯
const rules = {
@@ -259,7 +261,7 @@
tableLoading: false,
page: {
current: 1,
- size: 100,
+ size: 20,
total: 0,
},
tableData: [],
@@ -268,7 +270,7 @@
title: "",
type: "",
scenario: "",
- efficiency: "medium",
+ efficiency: "",
problem: "",
solution: "",
keyPoints: "",
@@ -282,11 +284,11 @@
currentKnowledge: {}
});
-const {
- searchForm,
- tableLoading,
- page,
- tableData,
+const {
+ searchForm,
+ tableLoading,
+ page,
+ tableData,
selectedIds,
form,
dialogVisible,
@@ -400,47 +402,47 @@
]);
// 妯℃嫙鏁版嵁
-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"
- }
-];
+// 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 = [
@@ -472,13 +474,13 @@
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,
@@ -488,19 +490,19 @@
problem: `鍦�${randomScenario}杩囩▼涓亣鍒扮殑闂鎻忚堪...`,
solution: `閽堝${randomScenario}鐨勮В鍐虫柟妗堝拰鎿嶄綔姝ラ...`,
keyPoints: "鍏抽敭瑕佺偣1,鍏抽敭瑕佺偣2,鍏抽敭瑕佺偣3,鍏抽敭瑕佺偣4",
- creator: ["闄堝織寮�", "鍒橀泤濠�", "鐜嬪缓鍥�", "璧典附鍗�"][Math.floor(Math.random() * 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}`);
};
@@ -526,24 +528,14 @@
const getList = () => {
tableLoading.value = true;
-
- setTimeout(() => {
- let filteredData = [...mockData];
-
- if (searchForm.value.title) {
- filteredData = filteredData.filter(item =>
- item.title.toLowerCase().includes(searchForm.value.title.toLowerCase())
- );
- }
-
- if (searchForm.value.type) {
- filteredData = filteredData.filter(item => item.type === searchForm.value.type);
- }
-
- tableData.value = filteredData;
- page.value.total = filteredData.length;
+ listKnowledgeBase({...page.value, ...searchForm.value})
+ .then(res => {
tableLoading.value = false;
- }, 500);
+ tableData.value = res.data.records
+ page.total = res.data.total;
+ }).catch(err => {
+ tableLoading.value = false;
+ })
};
// 鍒嗛〉澶勭悊
@@ -568,7 +560,7 @@
title: "",
type: "",
scenario: "",
- efficiency: "medium",
+ efficiency: "",
problem: "",
solution: "",
keyPoints: "",
@@ -578,6 +570,7 @@
} else if (type === "edit" && row) {
dialogTitle.value = "缂栬緫鐭ヨ瘑";
Object.assign(form.value, {
+ id: row.id,
title: row.title,
type: row.type,
scenario: row.scenario,
@@ -665,15 +658,15 @@
// 澶嶅埗鐭ヨ瘑
const copyKnowledge = () => {
const knowledgeText = `
-鐭ヨ瘑鏍囬锛�${currentKnowledge.value.title}
-鐭ヨ瘑绫诲瀷锛�${getTypeLabel(currentKnowledge.value.type)}
-閫傜敤鍦烘櫙锛�${currentKnowledge.value.scenario}
-闂鎻忚堪锛�${currentKnowledge.value.problem}
-瑙e喅鏂规锛�${currentKnowledge.value.solution}
-鍏抽敭瑕佺偣锛�${currentKnowledge.value.keyPoints}
-鍒涘缓浜猴細${currentKnowledge.value.creator}
+ 鐭ヨ瘑鏍囬锛�${currentKnowledge.value.title}
+ 鐭ヨ瘑绫诲瀷锛�${getTypeLabel(currentKnowledge.value.type)}
+ 閫傜敤鍦烘櫙锛�${currentKnowledge.value.scenario}
+ 闂鎻忚堪锛�${currentKnowledge.value.problem}
+ 瑙e喅鏂规锛�${currentKnowledge.value.solution}
+ 鍏抽敭瑕佺偣锛�${currentKnowledge.value.keyPoints}
+ 鍒涘缓浜猴細${currentKnowledge.value.creator}
`.trim();
-
+
// 澶嶅埗鍒板壀璐存澘
navigator.clipboard.writeText(knowledgeText).then(() => {
ElMessage.success("鐭ヨ瘑鍐呭宸插鍒跺埌鍓创鏉�");
@@ -690,7 +683,7 @@
mockData[index].usageCount += 1;
currentKnowledge.value.usageCount += 1;
}
-
+
ElMessage.success("宸叉敹钘忥紝浣跨敤娆℃暟+1");
};
@@ -698,46 +691,28 @@
const submitForm = async () => {
try {
await formRef.value.validate();
-
if (dialogType.value === "add") {
// 鏂板鐭ヨ瘑
- const newKnowledge = {
- id: (mockData.length + 1).toString(),
- title: form.value.title,
- type: form.value.type,
- scenario: form.value.scenario,
- efficiency: form.value.efficiency,
- problem: form.value.problem,
- solution: form.value.solution,
- keyPoints: form.value.keyPoints,
- creator: form.value.creator,
- usageCount: form.value.usageCount,
- createTime: new Date().toLocaleString()
- };
-
- mockData.unshift(newKnowledge);
- ElMessage.success("鐭ヨ瘑鍒涘缓鎴愬姛");
+ addKnowledgeBase({...form.value}).then(res => {
+ if(res.code == 200){
+ ElMessage.success("娣诲姞鎴愬姛");
+ dialogVisible.value = false;
+ getList();
+ }
+ }).catch(err => {
+ ElMessage.error(err.msg);
+ })
} else {
- // 缂栬緫鐭ヨ瘑
- const index = mockData.findIndex(item => item.id === selectedIds.value[0]);
- if (index !== -1) {
- Object.assign(mockData[index], {
- title: form.value.title,
- type: form.value.type,
- scenario: form.value.scenario,
- efficiency: form.value.efficiency,
- problem: form.value.problem,
- solution: form.value.solution,
- keyPoints: form.value.keyPoints,
- creator: form.value.creator,
- usageCount: form.value.usageCount
- });
- ElMessage.success("鐭ヨ瘑鏇存柊鎴愬姛");
- }
+ updateKnowledgeBase({...form.value}).then(res => {
+ if(res.code == 200){
+ ElMessage.success("鏇存柊鎴愬姛");
+ dialogVisible.value = false;
+ getList();
+ }
+ }).catch(err => {
+ ElMessage.error(err.msg);
+ })
}
-
- dialogVisible.value = false;
- getList();
} catch (error) {
console.error("琛ㄥ崟楠岃瘉澶辫触:", error);
}
@@ -749,27 +724,30 @@
ElMessage.warning("璇烽�夋嫨瑕佸垹闄ょ殑鐭ヨ瘑");
return;
}
-
+
ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚垹闄わ紝鏄惁纭鍒犻櫎锛�", "鍒犻櫎", {
confirmButtonText: "纭",
cancelButtonText: "鍙栨秷",
type: "warning",
}).then(() => {
- // 浠巑ockData涓垹闄ら�変腑鐨勯」
- selectedIds.value.forEach(id => {
- const index = mockData.findIndex(item => item.id === id);
- if (index !== -1) {
- mockData.splice(index, 1);
+ // console.log(selectedIds.value);
+ delKnowledgeBase(selectedIds.value).then(res => {
+ if(res.code == 200){
+ ElMessage.success("鍒犻櫎鎴愬姛");
+ selectedIds.value = [];
+ getList();
}
- });
-
- ElMessage.success("鍒犻櫎鎴愬姛");
- selectedIds.value = [];
- getList();
+ })
}).catch(() => {
// 鐢ㄦ埛鍙栨秷
});
};
+
+// 瀵煎嚭
+const { proxy } = getCurrentInstance()
+const handleExport = () => {
+ proxy.download('/knowledgeBase/export', { ...searchForm.value }, '鐭ヨ瘑搴�.xlsx')
+}
</script>
<style scoped>
--
Gitblit v1.9.3