Sfoglia il codice sorgente

pms 组织架构树部门按照 sort 排序

zhangcl 1 settimana fa
parent
commit
b1593ba3a5
1 ha cambiato i file con 27 aggiunte e 1 eliminazioni
  1. 27 1
      src/views/pms/iotrhdailyreport/DeptTree2.vue

+ 27 - 1
src/views/pms/iotrhdailyreport/DeptTree2.vue

@@ -94,10 +94,36 @@ const handleMenuClick = (action) => {
 const getTree = async () => {
   const res = await DeptApi.specifiedSimpleDepts(props.deptId)
   deptList.value = []
-  deptList.value.push(...handleTree(res))
+  const treeData = handleTree(res)
+
+  // 对树进行排序
+  const sortedTree = sortTreeBySort(treeData)
+
+  deptList.value.push(...sortedTree)
   firstLevelKeys.value = deptList.value.map((node) => node.id)
 }
 
+/** 递归对树节点按sort排序 */
+const sortTreeBySort = (treeNodes: Tree[]) => {
+  if (!treeNodes || !Array.isArray(treeNodes)) return treeNodes
+
+  // 对当前层级节点按sort升序排序
+  const sortedNodes = [...treeNodes].sort((a, b) => {
+    const sortA = a.sort != null ? a.sort : 999999
+    const sortB = b.sort != null ? b.sort : 999999
+    return sortA - sortB
+  })
+
+  // 递归处理子节点
+  sortedNodes.forEach(node => {
+    if (node.children && Array.isArray(node.children)) {
+      node.children = sortTreeBySort(node.children)
+    }
+  })
+
+  return sortedNodes
+}
+
 /** 基于名字过滤 */
 const filterNode = (name: string, data: Tree) => {
   if (!name) return true