Prechádzať zdrojové kódy

修复加载后不自动选中第一项

Yue 2 rokov pred
rodič
commit
98c3f16626
1 zmenil súbory, kde vykonal 13 pridanie a 2 odobranie
  1. 13 2
      src/components/Tree/OrgCompany.vue

+ 13 - 2
src/components/Tree/OrgCompany.vue

@@ -12,6 +12,7 @@ const emits = defineEmits<{
   (e: "clear"): void
   (e: "selected", type: string, key: string): void
 }>()
+const companyId = ref("")
 const expandedKeys = ref<Array<string>>([])
 const selectedKeys = ref<Array<string>>([])
 const searchWord = ref("")
@@ -27,6 +28,15 @@ function loadData(fun: () => void) {
     (res) => {
       data.value = res.data
       fun && fun()
+      if (!companyId.value && data.value[0]) {
+        const key = data.value[0].key
+        const arr = key.split("_")
+        emits("selected", arr[0], key)
+        setTimeout(() => {
+          expandedKeys.value = [key]
+          selectedKeys.value = [key]
+        }, 100)
+      }
     }
   )
 }
@@ -48,7 +58,7 @@ function findCompany(hasKey = true) {
   let key = ""
   //console.log(searchWord)
   data.value.forEach((v: any) => {
-    if ((hasKey && v.title == searchWord.value) || v.title.search(searchWord.value) >= 0) {
+    if ((hasKey && v.title == searchWord.value) || (searchWord.value && v.title.search(searchWord.value) >= 0)) {
       key = v.key
     } else {
       if (v.children) {
@@ -59,7 +69,7 @@ function findCompany(hasKey = true) {
   function _findCompany(list: Array<any>, key: string, fatherKey: string) {
     list.forEach((v) => {
       if (
-        (hasKey && v.key == "10_" + route.query.company_id) ||
+        (hasKey && v.key == "10_" + companyId.value) ||
         (v.key.search("10_") >= 0 && v.title.search(searchWord.value) >= 0)
       ) {
         key = v.key
@@ -118,6 +128,7 @@ function onNodeClick(nodeData: any) {
   emits("node-click", nodeData)
 }
 function init() {
+  companyId.value = route.query.company_id as string
   const name = route.query.comName as string
   if (name) {
     searchWord.value = name