From e226f444f7e796f43e205b5f6df7de9cc5f303bd Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 26 Sep 2025 19:21:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 支持自动添加父级部门 --- .../manage/components/TeamManagement.vue | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/resources/assets/js/pages/manage/components/TeamManagement.vue b/resources/assets/js/pages/manage/components/TeamManagement.vue index 095ce9c9c..5a0a20794 100644 --- a/resources/assets/js/pages/manage/components/TeamManagement.vue +++ b/resources/assets/js/pages/manage/components/TeamManagement.vue @@ -962,6 +962,46 @@ export default { }); }, immediate: true + }, + 'departmentEditData.department': { + handler(value, oldValue = []) { + if (!Array.isArray(value) || value.length === 0 || this.departmentList.length === 0) { + return; + } + + const previous = Array.isArray(oldValue) ? new Set(oldValue) : new Set(); + const selected = new Set(value); + + const hasNewSelection = Array.from(selected).some(id => !previous.has(id)); + if (!hasNewSelection) { + return; + } + + const departmentMap = this.departmentList.reduce((acc, item) => { + acc[item.id] = item; + return acc; + }, {}); + + const needAdd = new Set(); + + value.forEach((id) => { + let cursor = departmentMap[id]; + while (cursor && cursor.parent_id && cursor.parent_id > 0) { + if (!selected.has(cursor.parent_id)) { + needAdd.add(cursor.parent_id); + } + cursor = departmentMap[cursor.parent_id]; + } + }); + + if (needAdd.size > 0) { + const merged = Array.from(new Set([...value, ...needAdd])).sort((a, b) => a - b); + if (merged.length !== value.length || merged.some((id, index) => id !== value[index])) { + this.$set(this.departmentEditData, 'department', merged); + } + } + }, + deep: true } }, computed: {