|
@@ -30,7 +30,7 @@
|
|
|
<script setup>
|
|
|
// import recursive from './recursive'
|
|
|
import { getDict } from '@/hooks/web/useDictionaries'
|
|
|
-import { reactive, ref } from 'vue'
|
|
|
+import { inject, reactive, ref } from 'vue'
|
|
|
import { useRoute } from 'vue-router'
|
|
|
defineOptions({ name:'common-components-areaTree'})
|
|
|
const emits = defineEmits('checkedInput')
|
|
@@ -55,16 +55,14 @@ const num = 10
|
|
|
|
|
|
let treeList = ref()
|
|
|
const show = ref(false)
|
|
|
+const query = inject('routeQuery')
|
|
|
// 获取区域数据
|
|
|
getDict('areaTreeData', {}, 'areaTreeData').then(({ data }) => {
|
|
|
const arr = data?.length && data || []
|
|
|
treeList.value = [arr]
|
|
|
-
|
|
|
- if (route?.query && Object.keys(route?.query).length && route?.query.level1) {
|
|
|
+ if (query && query.level1) {
|
|
|
// 刷新回显
|
|
|
- console.log('route?.query', route?.query)
|
|
|
- Object.keys(route?.query).forEach(key => {
|
|
|
- console.log('key', key)
|
|
|
+ Object.keys(query).forEach(key => {
|
|
|
if(key.includes('level')) {
|
|
|
const levelIndex = key.split('level')[1] - 1
|
|
|
if (levelIndex !== -1 && treeList.value[levelIndex]?.length) {
|
|
@@ -74,7 +72,7 @@ getDict('areaTreeData', {}, 'areaTreeData').then(({ data }) => {
|
|
|
if (arr?.length) {
|
|
|
arr.forEach(idItem => {
|
|
|
const dataItem = treeList.value[levelIndex].find(findItem => findItem.id === (idItem - 0))
|
|
|
- if (dataItem) handleNext(dataItem, levelIndex)
|
|
|
+ if (dataItem) handleNext(dataItem, levelIndex, false, false)
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -88,7 +86,7 @@ getDict('areaTreeData', {}, 'areaTreeData').then(({ data }) => {
|
|
|
for (let index = 0; index < props.defaultOpen; index++) {
|
|
|
if (treeList.value?.length && treeList.value[index]?.length && treeList.value[index][0]) {
|
|
|
const stopExpand = (index + 1) === props.defaultOpen
|
|
|
- handleNext(treeList.value[index][0], index, stopExpand)
|
|
|
+ handleNext(treeList.value[index][0], index, stopExpand, true)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -111,12 +109,12 @@ const getIdChecked = (item, levelIndex) => {
|
|
|
}
|
|
|
}
|
|
|
idChecked.splice(levelIndex + 1, treeList.value.length) // 取消其下级数据
|
|
|
- emits('checkedInput', idChecked)
|
|
|
}
|
|
|
|
|
|
// 展开下一级
|
|
|
-const handleNext = (item, index, stopExpand) => { // stopExpand:不展开下级
|
|
|
+const handleNext = (item, index, stopExpand, isEmit = true) => { // stopExpand:不展开下级
|
|
|
getIdChecked(item, index)
|
|
|
+ if (isEmit) emits('checkedInput', idChecked)
|
|
|
if (!stopExpand &&item.children && item.children.length) {
|
|
|
treeList.value[index + 1] = item.children
|
|
|
treeList.value.splice(index + 2, treeList.value.length)
|