| | |
| | | const { service } = useCool(); |
| | | |
| | | const deviceList = ref<any[]>([]); |
| | | const ysToken = ref<string>(''); |
| | | let ysToken = ref(''); |
| | | |
| | | /** 拿萤石 token */ |
| | | async function fetchYsToken() { |
| | | if (ysToken.value) return; // 已有就不再重复拿 |
| | | if (ysToken.value) return; |
| | | try { |
| | | const res = await service.monitor.ys7.getToken(); |
| | | ysToken.value = res.accessToken; |
| | | } catch (e) { |
| | | console.error('萤石 Token 获取失败', e); |
| | | //const res = await service.monitor.ys7.getToken(); |
| | | const res = await service.base.sys.param.stringbykey({key:"ys7.accessToken"}); |
| | | ysToken = res; |
| | | } catch (e: any) { |
| | | console.error('萤石 Token 获取失败', e?.response?.data?.message || e.message); |
| | | } |
| | | } |
| | | |
| | | onMounted(() => { |
| | | fetchYsToken(); |
| | | }); |
| | | onMounted(fetchYsToken); |
| | | |
| | | /** 树节点点击 */ |
| | | async function handleTreeSelect(businessId: string | number | null) { |
| | | if (!businessId) { |
| | | deviceList.value = []; |
| | | return; |
| | | } |
| | | |
| | | // 保险:token 万一慢于树点击 |
| | | if (!ysToken.value) { |
| | | await fetchYsToken(); |
| | | } |
| | | |
| | | if (!ysToken.value) await fetchYsToken(); |
| | | try { |
| | | const res = await service.basicdata.iot.getYsDevices({ businessId }); |
| | | deviceList.value = res || []; |
| | | } catch (err) { |
| | | console.error('获取萤石设备列表失败', err); |
| | | } catch { |
| | | deviceList.value = []; |
| | | } |
| | | } |