Commit 3bde8331a26ca16dfe980138f14f46549a41a032

Authored by xp.Huang
2 parents d6503094 5d250b25

Merge branch 'fix/DEFECT-1890' into 'main_dev'

fix: DEFECT-1890 修复地图选择结构体时无法绘制路径

See merge request yunteng/thingskit-front!1188
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 import { StructJSON } from '/@/api/device/model/modelOfMatterModel'; 12 import { StructJSON } from '/@/api/device/model/modelOfMatterModel';
13 import { HistoryData } from '/@/api/alarm/position/model'; 13 import { HistoryData } from '/@/api/alarm/position/model';
14 import { useJsonParse } from '/@/hooks/business/useJsonParse'; 14 import { useJsonParse } from '/@/hooks/business/useJsonParse';
  15 + import { isObject, isString } from '/@/utils/is';
15 16
16 const emit = defineEmits(['register', 'ok']); 17 const emit = defineEmits(['register', 'ok']);
17 18
@@ -28,6 +29,14 @@ @@ -28,6 +29,14 @@
28 29
29 const getPositionRecord = computed<DataSource>(() => unref(dataSourceRef).at(0) as DataSource); 30 const getPositionRecord = computed<DataSource>(() => unref(dataSourceRef).at(0) as DataSource);
30 31
  32 + const getPositionIdentifier = computed(() => {
  33 + const { latitudeIdentifier, longitudeIdentifier } = unref(getPositionRecord);
  34 + return {
  35 + latitudeIdentifier,
  36 + longitudeIdentifier,
  37 + };
  38 + });
  39 +
31 const { getDeviceProfileTslByIdWithIdentifier } = useDeviceProfileQueryContext(); 40 const { getDeviceProfileTslByIdWithIdentifier } = useDeviceProfileQueryContext();
32 41
33 const handleSetForm = async () => { 42 const handleSetForm = async () => {
@@ -55,7 +64,7 @@ @@ -55,7 +64,7 @@
55 ); 64 );
56 return { 65 return {
57 label: `${detail.functionName} / ${structIdentifierDetail?.functionName}`, 66 label: `${detail.functionName} / ${structIdentifierDetail?.functionName}`,
58 - value: identifier, 67 + value: `${identifier} / ${structIdentifierDetail?.identifier}`,
59 }; 68 };
60 } 69 }
61 70
@@ -101,17 +110,15 @@ @@ -101,17 +110,15 @@
101 }); 110 });
102 111
103 const getPositionDataSource = async (res: HistoryData) => { 112 const getPositionDataSource = async (res: HistoryData) => {
104 - const keys = Object.keys(res);  
105 const track: Record<'lng' | 'lat', number>[] = []; 113 const track: Record<'lng' | 'lat', number>[] = [];
106 -  
107 const { 114 const {
108 latitudeIdentifier = [], 115 latitudeIdentifier = [],
109 longitudeIdentifier = [], 116 longitudeIdentifier = [],
110 deviceProfileId, 117 deviceProfileId,
111 } = unref(getPositionRecord); 118 } = unref(getPositionRecord);
112 119
113 - const [latIdentifier] = latitudeIdentifier || [];  
114 - const [lngIdentifier] = longitudeIdentifier || []; 120 + const [latIdentifier, structLatIdentifier] = latitudeIdentifier || [];
  121 + const [lngIdentifier, structLngIdentifier] = longitudeIdentifier || [];
115 122
116 if (!latIdentifier || !lngIdentifier) return track; 123 if (!latIdentifier || !lngIdentifier) return track;
117 124
@@ -133,27 +140,34 @@ @@ -133,27 +140,34 @@
133 const { identifier } = detail || {}; 140 const { identifier } = detail || {};
134 141
135 if (detail?.specs?.dataType.type === DataTypeEnum.STRUCT) { 142 if (detail?.specs?.dataType.type === DataTypeEnum.STRUCT) {
136 - const [, structIdentifier] = position;  
137 res[identifier].forEach((temp) => { 143 res[identifier].forEach((temp) => {
138 - const structJSON = useJsonParse(temp.value).value;  
139 - temp.value = structJSON?.[structIdentifier]; 144 + if (isString(temp.value)) {
  145 + temp.value = useJsonParse(temp.value).value;
  146 + }
140 }); 147 });
141 } 148 }
142 } 149 }
143 150
144 for (const ts of timespanList) { 151 for (const ts of timespanList) {
145 - const list: { ts: number; value: number }[] = [];  
146 - for (const key of keys) {  
147 - const record = res[key].find((item) => ts === item.ts);  
148 - list.push(record as any);  
149 - } 152 + const latRecord = res[latIdentifier].find((item) => ts === item.ts);
  153 + const lngRecord = res[lngIdentifier].find((item) => ts === item.ts);
  154 +
  155 + if (!latRecord || !lngRecord) continue;
  156 +
  157 + const positionRecord = { lat: 0, lng: 0 };
  158 +
  159 + positionRecord.lat =
  160 + structLatIdentifier && isObject(latRecord.value)
  161 + ? Reflect.get(latRecord.value as unknown as object, structLatIdentifier)
  162 + : latRecord.value;
  163 +
  164 + positionRecord.lng =
  165 + structLngIdentifier && isObject(lngRecord.value)
  166 + ? Reflect.get(latRecord.value as unknown as object, structLngIdentifier)
  167 + : lngRecord.value;
150 168
151 - if (list.length === 2 && list.every(Boolean)) {  
152 - let lng = list.at(0)?.value;  
153 - let lat = list.at(1)?.value;  
154 - if (lng && lat) {  
155 - track.push({ lng: Number(lng), lat: Number(lat) });  
156 - } 169 + if (positionRecord.lat && positionRecord.lng) {
  170 + track.push({ lng: Number(positionRecord.lng), lat: Number(positionRecord.lat) });
157 } 171 }
158 } 172 }
159 173
@@ -171,7 +185,9 @@ @@ -171,7 +185,9 @@
171 185
172 const res = await getDeviceHistoryInfo({ 186 const res = await getDeviceHistoryInfo({
173 ...value, 187 ...value,
174 - [SchemaFiled.KEYS]: value[SchemaFiled.KEYS].join(','), 188 + [SchemaFiled.KEYS]: `${unref(getPositionIdentifier).latitudeIdentifier?.at(0)},${unref(
  189 + getPositionIdentifier
  190 + ).longitudeIdentifier?.at(0)}`,
175 }); 191 });
176 192
177 const track = await getPositionDataSource(res); 193 const track = await getPositionDataSource(res);
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 import { useMultipleDataFetch } from '../../../hook/socket/useSocket'; 10 import { useMultipleDataFetch } from '../../../hook/socket/useSocket';
11 import { MultipleDataFetchUpdateFn } from '../../../hook/socket/useSocket.type'; 11 import { MultipleDataFetchUpdateFn } from '../../../hook/socket/useSocket.type';
12 import get from 'lodash-es/get'; 12 import get from 'lodash-es/get';
  13 + import { useJsonParse } from '/@/hooks/business/useJsonParse';
13 14
14 const props = defineProps<{ 15 const props = defineProps<{
15 config: ComponentPropsConfigType<typeof option>; 16 config: ComponentPropsConfigType<typeof option>;
@@ -50,13 +51,25 @@ @@ -50,13 +51,25 @@
50 51
51 const bindMessage = data[deviceId]; 52 const bindMessage = data[deviceId];
52 53
53 - const lngData = get(bindMessage, unref(getLngKey)) || []; 54 + const [lngIdentifier, structLngIdentifier] = unref(getLngKey);
  55 + const lngData = get(bindMessage, lngIdentifier) || [];
54 const [lngLatest] = lngData; 56 const [lngLatest] = lngData;
55 - const [, lng] = lngLatest || []; 57 + let [, lng] = lngLatest || [];
56 58
57 - const latData = get(bindMessage, unref(getLatKey)) || []; 59 + if (structLngIdentifier) {
  60 + const structValue = useJsonParse(lng).value;
  61 + lng = get(structValue, structLngIdentifier);
  62 + }
  63 +
  64 + const [latIdentifier, structLatIdentifier] = unref(getLatKey);
  65 + const latData = get(bindMessage, latIdentifier) || [];
58 const [latLatest] = latData; 66 const [latLatest] = latData;
59 - const [, lat] = latLatest || []; 67 + let [, lat] = latLatest || [];
  68 +
  69 + if (structLatIdentifier) {
  70 + const structValue = useJsonParse(lat).value;
  71 + lat = get(structValue, structLatIdentifier);
  72 + }
60 73
61 if (validEffective(lng) && validEffective(lat)) { 74 if (validEffective(lng) && validEffective(lat)) {
62 drawLine({ lng: Number(lng), lat: Number(lat) }); 75 drawLine({ lng: Number(lng), lat: Number(lat) });
@@ -80,8 +80,14 @@ class Subscriber { @@ -80,8 +80,14 @@ class Subscriber {
80 this.componentGroupUpdateFnMap.clear(); 80 this.componentGroupUpdateFnMap.clear();
81 } 81 }
82 82
83 - addSubscriber = (info: Record<'deviceId' | 'slaveDeviceId' | 'attribute' | 'uuid', string>) => {  
84 - const { deviceId, attribute, uuid } = info; 83 + addSubscriber = (
  84 + info: Record<'deviceId' | 'slaveDeviceId' | 'attribute' | 'uuid' | 'frontId', string> & {
  85 + latitudeIdentifier?: string[];
  86 + longitudeIdentifier?: string[];
  87 + }
  88 + ) => {
  89 + const { deviceId, attribute, uuid, latitudeIdentifier = [], longitudeIdentifier = [] } = info;
  90 +
85 if (!this.deviceGroupMap.has(deviceId)) { 91 if (!this.deviceGroupMap.has(deviceId)) {
86 this.deviceGroupMap.set(deviceId, { 92 this.deviceGroupMap.set(deviceId, {
87 subscriptionId: this.getNextSubscribeId(), 93 subscriptionId: this.getNextSubscribeId(),
@@ -92,6 +98,15 @@ class Subscriber { @@ -92,6 +98,15 @@ class Subscriber {
92 98
93 const groupInfo = this.deviceGroupMap.get(deviceId); 99 const groupInfo = this.deviceGroupMap.get(deviceId);
94 groupInfo?.attributes.add(attribute); 100 groupInfo?.attributes.add(attribute);
  101 +
  102 + if (latitudeIdentifier?.[0]) {
  103 + groupInfo?.attributes.add(latitudeIdentifier?.[0]);
  104 + }
  105 +
  106 + if (longitudeIdentifier?.[0]) {
  107 + groupInfo?.attributes.add(longitudeIdentifier?.[0]);
  108 + }
  109 +
95 groupInfo?.subscriptionGroup.push({ uuid, attribute }); 110 groupInfo?.subscriptionGroup.push({ uuid, attribute });
96 111
97 this.subscriptionMap.set(groupInfo!.subscriptionId, deviceId); 112 this.subscriptionMap.set(groupInfo!.subscriptionId, deviceId);
@@ -296,8 +311,24 @@ export const useSocket = (dataSourceRef: Ref<WidgetDataType[]>) => { @@ -296,8 +311,24 @@ export const useSocket = (dataSourceRef: Ref<WidgetDataType[]>) => {
296 for (const item of unref(dataSourceRef)) { 311 for (const item of unref(dataSourceRef)) {
297 if (CUSTOM_SUBSCRIBE_MESSAGE_COMPONENT_KEY_LIST.includes(item.frontId)) continue; 312 if (CUSTOM_SUBSCRIBE_MESSAGE_COMPONENT_KEY_LIST.includes(item.frontId)) continue;
298 for (const temp of item.dataSource) { 313 for (const temp of item.dataSource) {
299 - const { deviceId, slaveDeviceId, attribute, uuid } = temp;  
300 - subscriber.addSubscriber({ deviceId, slaveDeviceId, attribute, uuid }); 314 + const {
  315 + deviceId,
  316 + slaveDeviceId,
  317 + attribute,
  318 + uuid,
  319 + longitudeIdentifier,
  320 + latitudeIdentifier,
  321 + } = temp;
  322 +
  323 + subscriber.addSubscriber({
  324 + deviceId,
  325 + slaveDeviceId,
  326 + attribute,
  327 + uuid,
  328 + frontId: item.frontId,
  329 + longitudeIdentifier,
  330 + latitudeIdentifier,
  331 + });
301 } 332 }
302 } 333 }
303 }; 334 };