|
@@ -31,8 +31,10 @@
|
|
|
// import recursive from './recursive'
|
|
|
import { getDict } from '@/hooks/web/useDictionaries'
|
|
|
import { reactive, ref } from 'vue'
|
|
|
+import { useRoute } from 'vue-router'
|
|
|
defineOptions({ name:'common-components-areaTree'})
|
|
|
-const emits = defineEmits('input')
|
|
|
+const emits = defineEmits('checkedInput')
|
|
|
+const route = useRoute()
|
|
|
|
|
|
const props = defineProps({
|
|
|
// items: Object,
|
|
@@ -57,18 +59,40 @@ const show = ref(false)
|
|
|
getDict('areaTreeData', {}, 'areaTreeData').then(({ data }) => {
|
|
|
const arr = data?.length && data || []
|
|
|
treeList.value = [arr]
|
|
|
- show.value = true
|
|
|
|
|
|
- // 默认展开
|
|
|
- if (props.defaultOpen > 0) {
|
|
|
- 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)
|
|
|
+ if (route?.query && Object.keys(route?.query).length && route?.query.level1) {
|
|
|
+ // 刷新回显
|
|
|
+ console.log('route?.query', route?.query)
|
|
|
+ Object.keys(route?.query).forEach(key => {
|
|
|
+ console.log('key', key)
|
|
|
+ if(key.includes('level')) {
|
|
|
+ const levelIndex = key.split('level')[1] - 1
|
|
|
+ if (levelIndex !== -1 && treeList.value[levelIndex]?.length) {
|
|
|
+ if (route.query[key]) {
|
|
|
+ const arr = route.query[key].split('_')
|
|
|
+ if (arr?.length) {
|
|
|
+ arr.forEach(idItem => {
|
|
|
+ const dataItem = treeList.value[levelIndex].find(findItem => findItem.id === (idItem - 0))
|
|
|
+ if (dataItem) handleNext(dataItem, levelIndex)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 默认展开
|
|
|
+ if (props.defaultOpen > 0) {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- emits('input', idChecked)
|
|
|
}
|
|
|
+ show.value = true
|
|
|
})
|
|
|
|
|
|
// 设置选中ids
|
|
@@ -91,6 +115,7 @@ const getIdChecked = (item, levelIndex) => {
|
|
|
// 展开下一级
|
|
|
const handleNext = (item, index, stopExpand) => { // stopExpand:不展开下级
|
|
|
getIdChecked(item, index)
|
|
|
+ emits('checkedInput', idChecked)
|
|
|
if (!stopExpand &&item.children && item.children.length) {
|
|
|
treeList.value[index + 1] = item.children
|
|
|
treeList.value.splice(index + 2, treeList.value.length)
|
|
@@ -104,7 +129,8 @@ const calcAct = (id, levelIndex) => {
|
|
|
if (!id) return false
|
|
|
if (Array.isArray(idChecked) && Array.isArray(idChecked[levelIndex])) {
|
|
|
const index = idChecked[levelIndex].findIndex(itemToCheck => itemToCheck=== id)
|
|
|
- return index !== -1 ? true : false; // 如果找到返回索引,否则返回 false
|
|
|
+ const bool = index !== -1
|
|
|
+ return bool ? true : false; // 如果找到返回索引,否则返回 false
|
|
|
}
|
|
|
else return false
|
|
|
}
|