From 67aebf4dcaa249d99893a88685ea273cc46606f4 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期五, 06 十一月 2026 11:48:19 +0800
Subject: [PATCH] 流程优化

---
 src/views/projectManagement/projectCategory/index.vue |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/views/projectManagement/projectCategory/index.vue b/src/views/projectManagement/projectCategory/index.vue
index d9f299a..465e2e4 100644
--- a/src/views/projectManagement/projectCategory/index.vue
+++ b/src/views/projectManagement/projectCategory/index.vue
@@ -77,8 +77,8 @@
 const form = reactive({ id: null, parentId: null, categoryName: '', sort: 0, remark: '' })
 const rules = { categoryName: [{ required: true, message: '璇疯緭鍏ュ垎绫诲悕绉�', trigger: 'blur' }] }
 
-function buildTree(list, excludedId = null) {
-  const source = list.filter(item => String(item.id) !== String(excludedId ?? ''))
+function buildTree(list, excludedIds = new Set()) {
+  const source = list.filter(item => !excludedIds.has(String(item.id)))
   const map = new Map(source.map(item => [String(item.id), { ...item, children: [] }]))
   const roots = []
   map.forEach(item => {
@@ -92,8 +92,21 @@
   return sortRows(roots)
 }
 
+function categoryBranchIds(id) {
+  const excluded = new Set(id == null ? [] : [String(id)])
+  let changed = true
+  while (changed) {
+    changed = false
+    rows.value.forEach(item => {
+      if (excluded.has(String(item.parentId)) && !excluded.has(String(item.id))) {
+        excluded.add(String(item.id)); changed = true
+      }
+    })
+  }
+  return excluded
+}
 const treeRows = computed(() => buildTree(rows.value))
-const parentOptions = computed(() => buildTree(rows.value, form.id))
+const parentOptions = computed(() => buildTree(rows.value, categoryBranchIds(form.id)))
 
 async function loadData() {
   loading.value = true

--
Gitblit v1.9.3