2024-01-09 13:49:21 +08:00
|
|
|
<template>
|
2026-03-06 09:36:42 +08:00
|
|
|
<Tree
|
|
|
|
|
ref="treRef"
|
|
|
|
|
:width="width"
|
|
|
|
|
:data="tree"
|
|
|
|
|
default-expand-all
|
|
|
|
|
@changePointType="changePointType"
|
2026-06-04 09:08:37 +08:00
|
|
|
@changeTreeType="loadTree"
|
2026-06-09 19:51:31 +08:00
|
|
|
:height="height"
|
2026-03-06 09:36:42 +08:00
|
|
|
/>
|
2024-01-09 13:49:21 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2026-06-04 09:08:37 +08:00
|
|
|
import { ref, nextTick } from 'vue'
|
2024-06-27 09:39:53 +08:00
|
|
|
import Tree from '../point.vue'
|
2024-01-11 08:54:09 +08:00
|
|
|
import { getLineTree } from '@/api/cs-device-boot/csLedger'
|
2024-01-09 13:49:21 +08:00
|
|
|
import { useConfig } from '@/stores/config'
|
2026-01-27 16:32:33 +08:00
|
|
|
import { querySysExcel } from '@/api/harmonic-boot/luckyexcel'
|
2026-06-04 09:08:37 +08:00
|
|
|
import {
|
|
|
|
|
createLineTreeDecorators,
|
|
|
|
|
decorateLineTree,
|
|
|
|
|
waitForTreeRef,
|
|
|
|
|
type LineTreeLeaves,
|
|
|
|
|
type TreeRefKey
|
|
|
|
|
} from './lineTreeUtils'
|
|
|
|
|
|
2024-10-17 15:42:07 +08:00
|
|
|
interface Props {
|
|
|
|
|
template?: boolean
|
2026-06-09 19:51:31 +08:00
|
|
|
height?: number
|
2024-10-17 15:42:07 +08:00
|
|
|
}
|
2026-06-04 09:08:37 +08:00
|
|
|
|
2024-10-17 15:42:07 +08:00
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2026-06-09 19:51:31 +08:00
|
|
|
template: false,
|
|
|
|
|
height: 0
|
2024-10-17 15:42:07 +08:00
|
|
|
})
|
2026-06-04 09:08:37 +08:00
|
|
|
|
2024-01-09 13:49:21 +08:00
|
|
|
defineOptions({
|
2026-06-04 09:08:37 +08:00
|
|
|
name: 'govern/pointTree'
|
2024-01-09 13:49:21 +08:00
|
|
|
})
|
2024-10-17 15:42:07 +08:00
|
|
|
|
|
|
|
|
const emit = defineEmits(['init', 'checkChange', 'pointTypeChange', 'Policy'])
|
2026-06-04 09:08:37 +08:00
|
|
|
|
2024-01-09 13:49:21 +08:00
|
|
|
const config = useConfig()
|
2026-06-04 09:08:37 +08:00
|
|
|
const tree = ref<any[]>([])
|
|
|
|
|
const treRef = ref<InstanceType<typeof Tree>>()
|
2024-08-23 08:51:36 +08:00
|
|
|
const width = ref('')
|
2024-10-17 15:42:07 +08:00
|
|
|
|
2026-06-04 09:08:37 +08:00
|
|
|
const decorators = createLineTreeDecorators(() => config.getColorVal('elementUiPrimary'))
|
2026-03-30 09:03:53 +08:00
|
|
|
|
2024-10-17 15:42:07 +08:00
|
|
|
const changePointType = (val: any, obj: any) => {
|
|
|
|
|
emit('pointTypeChange', val, obj)
|
|
|
|
|
}
|
2026-06-04 09:08:37 +08:00
|
|
|
|
|
|
|
|
async function selectInitialNode(type: string | undefined, leaves: LineTreeLeaves) {
|
|
|
|
|
const candidates: { refKey: TreeRefKey; list: any[]; level: number }[] =
|
|
|
|
|
type === '2'
|
|
|
|
|
? [{ refKey: 'treeRef4', list: leaves.engineering, level: 3 }]
|
|
|
|
|
: [
|
|
|
|
|
{ refKey: 'treeRef1', list: leaves.govern, level: 2 },
|
|
|
|
|
{ refKey: 'treeRef2', list: leaves.portable, level: 2 },
|
|
|
|
|
{ refKey: 'treeRef3', list: leaves.monitor, level: 2 }
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for (const { refKey, list, level } of candidates) {
|
|
|
|
|
const node = list[0]
|
|
|
|
|
if (!node) continue
|
|
|
|
|
|
|
|
|
|
const treeInstance = await waitForTreeRef(treRef.value, refKey)
|
|
|
|
|
treeInstance?.setCurrentKey(node.id)
|
2026-06-04 19:06:36 +08:00
|
|
|
emit('init', { ...node })
|
2026-06-04 09:08:37 +08:00
|
|
|
|
|
|
|
|
if (type === '2') {
|
|
|
|
|
changePointType('4', node)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit('init')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const loadTree = (type?: string) => {
|
2026-06-16 08:34:45 +08:00
|
|
|
// console.log("🚀 ~ loadTree ~ type:", type)
|
2026-06-04 09:08:37 +08:00
|
|
|
tree.value = []
|
|
|
|
|
getLineTree({ type: type === '2' ? 'engineering' : '' }).then(res => {
|
|
|
|
|
const leaves = decorateLineTree(res.data, type, decorators, { disableParents: false })
|
|
|
|
|
tree.value = res.data
|
|
|
|
|
nextTick(() => selectInitialNode(type, leaves))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bootstrap() {
|
|
|
|
|
if (props.template) {
|
|
|
|
|
querySysExcel({})
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
emit('Policy', res.data)
|
2026-06-08 18:34:49 +08:00
|
|
|
loadTree('2')
|
2026-06-04 09:08:37 +08:00
|
|
|
})
|
|
|
|
|
.catch(() => loadTree())
|
2026-06-08 18:34:49 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadTree('2')
|
2026-06-04 09:08:37 +08:00
|
|
|
}
|
2024-10-17 15:42:07 +08:00
|
|
|
}
|
2026-06-04 09:08:37 +08:00
|
|
|
|
|
|
|
|
bootstrap()
|
|
|
|
|
|
|
|
|
|
defineExpose({ treRef })
|
2024-01-09 13:49:21 +08:00
|
|
|
</script>
|