diff --git a/src/views/biz/device/index.vue b/src/views/biz/device/index.vue index 67f8f5c..3fbcc93 100644 --- a/src/views/biz/device/index.vue +++ b/src/views/biz/device/index.vue @@ -112,12 +112,17 @@ /> - --> + @@ -267,12 +272,14 @@ import {deviceApi, type Device} from '@/api/device' import {dictDataApi} from '@/api/org' import {sectionApi} from '@/api/section' -import {SysUser, userApi} from '@/api/system' +import {deptApi, type SysDept , userApi} from '@/api/system' import {DeviceAbnormalRecord, deviceAbnormalRecordApi} from "@/api/deviceAbnormalRecord.ts"; + import DeviceAbnormalRecordPage from '@/views/biz/device/DeviceAbnomarlRecord.vue' import DeviceOperationLogPage from "@/views/biz/device/DeviceOperationLog.vue"; - import DeviceDispatchLogPage from "@/views/biz/device/DeviceDispatchLog.vue"; +import { S } from 'vue-router/dist/router-CWoNjPRp.mjs' + const message = useMessage() const dialog = useDialog() const router = useRouter() @@ -283,8 +290,15 @@ const deviceId = ref(undefined) //设备负责人列表 const deviceManagerList = ref<{ label: string, value: any }[]>([]) -let sectionList = reactive<{ label: string, value: any }[]>([]) +// 树形下拉选项递归接口 +interface TreeNode { + label: string; + key: number | string; + children?: TreeNode[]; +} + let sectionList = reactive([]) +// const sectionList = ref([]) // 树形数据 //设备异常记录 const deviceErrorLogList = ref([]) const deviceAbnormalRecordDrawerVisible = ref(false) //异常记录抽屉显示 @@ -664,11 +678,26 @@ async function loadDictOptions() { } } - //加载工段 async function loadSection() { - const data = await sectionApi.listNoParam() - sectionList = data.map((d: any) => ({label: d.sectionName, value: (Number(d.id) || d.id)})) + const data = await deptApi.tree() + sectionList = buildOptions(data); +} + +function buildOptions(d: any[]): TreeNode[] { + return d.map(item => { + // 安全id转换:0也能正常转为数字,不会被||过滤 + const idNum = Number(item.id); + const key = !isNaN(idNum) ? idNum : item.id; + return { + label: item.deptName, + key, + // 子节点存在且为数组才递归处理 + children: Array.isArray(item.children) && item.children.length + ? buildOptions(item.children) + : undefined + }; + }); } //加载人员