| | |
| | | |
| | | onMounted(async () => { |
| | | try { |
| | | await getData(); |
| | | await loadDeviceList(selectValue.value); |
| | | if (simStore.devices && simStore.devices.length > 0) { |
| | | await loadDeviceList(selectValue.value); |
| | | } |
| | | // initeWaterPrimitiveView(); |
| | | } finally { |
| | | isLoading.value = false; |
| | |
| | | clearAllPoints(); |
| | | } |
| | | }); |
| | | watch( |
| | | () => simStore.DeviceShowSwitch, |
| | | (newValue, oldValue) => { |
| | | if (newValue) { |
| | | initializeDevicePoints(); |
| | | } else { |
| | | clearAllPoints(); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | // watch( |
| | | // () => simStore.DeviceShowSwitch, |
| | | // (newValue, oldValue) => { |
| | | // if (newValue) { |
| | | // initializeDevicePoints(); |
| | | // } else { |
| | | // clearAllPoints(); |
| | | // } |
| | | // } |
| | | // ); |
| | | |
| | | const deviceListAll = ref([]); |
| | | const deviceEntities = ref([]); |
| | | |
| | | // const initializeDevicePoints = (val) => { |
| | | const initializeDevicePoints = () => { |
| | | const list = []; |
| | | // val.forEach((item, index) => { |
| | |
| | | // console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`); |
| | | createPoint(item); |
| | | }); |
| | | deviceEntities.value = list; |
| | | }; |
| | | const allDevices = ref([]); |
| | | const getData = async () => { |
| | | const res = await getDeviceInfoShg(); |
| | | allDevices.value = res.data.pageData; |
| | | }; |
| | | |
| | | // 根据区域名称加载设备列表 |
| | | const loadDeviceList = async (areaName) => { |
| | | try { |
| | | clearAllPoints(); |
| | | isLoading.value = true; |
| | | // const res = await getDeviceInfoShg(); |
| | | // const allDevices = res.data.pageData; |
| | | deviceListAll.value = allDevices.value.filter((item) => |
| | | |
| | | deviceListAll.value = simStore.devices.filter((item) => |
| | | item.deviceName?.includes(areaName) |
| | | ); |
| | | |
| | | initializeDevicePoints(); |
| | | // getDeviceInfo().then((res) => { |
| | | // const list = res.data.pageData; |
| | | // deviceListAll.value = []; |
| | | |
| | | // let index = 0; |
| | | // const batchSize = 50; // 每次处理的数量 |
| | | // const delay = 100; // 每隔多少毫秒处理一次 |
| | | |
| | | // const intervalId = setInterval(() => { |
| | | // // 取出当前批次的数据 |
| | | // const batch = list.slice(index, index + batchSize); |
| | | |
| | | // if (batch.length === 0) { |
| | | // clearInterval(intervalId); // 数据处理完了,停止定时器 |
| | | // return; |
| | | // } |
| | | |
| | | // // 把当前批次的数据 push 到 deviceListAll |
| | | // deviceListAll.value = [...deviceListAll.value, ...batch]; |
| | | |
| | | // // 对当前批次执行初始化方法 |
| | | // initializeDevicePoints(batch); |
| | | |
| | | // index += batchSize; |
| | | // }, delay); |
| | | // }); |
| | | await initializeDevicePoints(); |
| | | } catch (error) { |
| | | console.error("加载设备信息失败", error); |
| | | } finally { |
| | | isLoading.value = false; |
| | | } |
| | | }; |
| | | |
| | | // 监听 simStore.devices 变化 |
| | | watch( |
| | | () => simStore.devices, |
| | | (newVal) => { |
| | | if (newVal && newVal.length > 0) { |
| | | loadDeviceList(selectValue.value); |
| | | } else { |
| | | clearAllPoints(); |
| | | deviceListAll.value = []; |
| | | } |
| | | } |
| | | ); |
| | | |
| | | // 处理区域变化事件 |
| | | const handleChange = (item) => { |
| | |
| | | } |
| | | // 根据新区域名重新加载设备列表 |
| | | loadDeviceList(item); |
| | | initializeDevicePoints(); |
| | | |
| | | // console.log(deviceListAll.value); |
| | | }; |
| | | |
| | |
| | | }); |
| | | |
| | | function handleTreeNodeClick(data) { |
| | | initializeDevicePoints(); |
| | | // 只有设备节点才处理点击事件 |
| | | if (!data.children) { |
| | | const entity = viewer.entities.getById(data.deviceId); |