tangning недель назад: 3
Родитель
Сommit
4e3787034e

+ 0 - 1
src/components/company-select/index.vue

@@ -21,7 +21,6 @@ const emit = defineEmits<{
   (e: "update:path", path: string[]): void;
   (e: "update:path", path: string[]): void;
 }>();
 }>();
 const props = defineProps<Props>();
 const props = defineProps<Props>();
-
 const state = useTreeSelect(
 const state = useTreeSelect(
   props,
   props,
   getOrganizationTree,
   getOrganizationTree,

+ 33 - 1
src/hook/treeSelect.ts

@@ -16,6 +16,7 @@ export type Props = {
   allText?: string;
   allText?: string;
   notDefault?: boolean;
   notDefault?: boolean;
   disabled?: boolean;
   disabled?: boolean;
+  currentId?: string | number;
 };
 };
 
 
 export type Mapper = {
 export type Mapper = {
@@ -58,6 +59,7 @@ const getTreeSelect = (
   options: TreeOption[],
   options: TreeOption[],
   value: string
   value: string
 ): null | TreeOption => {
 ): null | TreeOption => {
+  console.log('options', options, value);
   for (const option of options) {
   for (const option of options) {
     if (option.value === value) {
     if (option.value === value) {
       return option;
       return option;
@@ -71,6 +73,30 @@ const getTreeSelect = (
   return null;
   return null;
 };
 };
 
 
+const recursiveSearch = (nodes, currentId) => {
+    // 如果没有节点,直接返回
+    if (!nodes || !nodes.length) return;
+    
+    // 遍历当前节点
+    for (const node of nodes) {
+      // 检查是否符合条件
+      if (node.value === currentId) {
+        // 如果只需要第一个,直接返回
+            return [node]; // 终止递归
+      }
+      
+      // 如果有子节点,递归查询
+      if (node.children && node.children.length) {
+        const found = recursiveSearch(node.children, currentId);
+        // 如果已经找到第一个,终止递归
+        if(found){
+          return found;
+        }
+      }
+    }
+    
+    return false;
+  }
 const allOption: TreeOption = { label: "全部", value: "" };
 const allOption: TreeOption = { label: "全部", value: "" };
 
 
 export const useTreeSelect = <T>(
 export const useTreeSelect = <T>(
@@ -84,7 +110,13 @@ export const useTreeSelect = <T>(
   // 级联控件需要数据
   // 级联控件需要数据
   const options = computed<TreeOption[]>(() => {
   const options = computed<TreeOption[]>(() => {
     const dataOptions = treeSelectOptionCover(optionsRaw.value, mapping);
     const dataOptions = treeSelectOptionCover(optionsRaw.value, mapping);
-    return props.hideAll ? dataOptions : [allOption, ...dataOptions];
+    let listOptions = props.hideAll ? dataOptions : [allOption, ...dataOptions]
+    console.log('listOptions1', listOptions, props.currentId);
+    console.log('listOptions2', recursiveSearch(listOptions, props.currentId));
+    if (props.currentId){
+      return recursiveSearch(listOptions, props.currentId) || listOptions
+    }
+    return listOptions;
   });
   });
 
 
   // 级联控件续高亮value
   // 级联控件续高亮value

+ 2 - 2
src/view/newFireCase/newdispatch/header.vue

@@ -27,7 +27,7 @@
       </el-form-item>
       </el-form-item>
 
 
       <el-form-item label="承办单位:">
       <el-form-item label="承办单位:">
-        <com-company v-model="pagging.state.query.deptId" />
+        <com-company :currentId="deptId == 0 ? '' : deptId" v-model="pagging.state.query.deptId" />
       </el-form-item>
       </el-form-item>
       <el-form-item label="事故日期:">
       <el-form-item label="事故日期:">
         <el-date-picker
         <el-date-picker
@@ -80,7 +80,7 @@ const canShowAll = computed(() => {
   const roleList = user.value.info?.roleList || [];
   const roleList = user.value.info?.roleList || [];
   return roleList.includes("admin") || roleList.includes("admin-super");
   return roleList.includes("admin") || roleList.includes("admin-super");
 });
 });
-
+const deptId = computed(() => user.value.info.deptId);
 const head = computed(() => {
 const head = computed(() => {
   const options = [
   const options = [
     { name: "火调列表", value: "0" },
     { name: "火调列表", value: "0" },