Commit 31a31840bb1a080431fc517261682e06d79c794a
Merge branch 'local_dev_branch_by_ft' into 'main_dev'
fix: DEFECT-1741 修改报表导出点击报表查看趋势图里属性映射成物模型的标识符名 See merge request yunteng/thingskit-front!991
Showing
1 changed file
with
59 additions
and
6 deletions
@@ -34,7 +34,12 @@ | @@ -34,7 +34,12 @@ | ||
34 | @change="(value) => handleChangeChars(value, item.device, item)" | 34 | @change="(value) => handleChangeChars(value, item.device, item)" |
35 | v-bind="createPickerSearch()" | 35 | v-bind="createPickerSearch()" |
36 | placeholder="请选择设备属性" | 36 | placeholder="请选择设备属性" |
37 | - :options="item?.attributes?.map((item1) => ({ label: item1, value: item1 }))" | 37 | + :options=" |
38 | + item?.attributes?.map((attrItem: any) => ({ | ||
39 | + label: attrItem.label, | ||
40 | + value: attrItem.value, | ||
41 | + })) | ||
42 | + " | ||
38 | /> | 43 | /> |
39 | </div> | 44 | </div> |
40 | <div class="w-full h-full flex justify-center items-center"> | 45 | <div class="w-full h-full flex justify-center items-center"> |
@@ -64,6 +69,8 @@ | @@ -64,6 +69,8 @@ | ||
64 | import { ExecuteReportRecord } from '/@/api/export/model/exportModel'; | 69 | import { ExecuteReportRecord } from '/@/api/export/model/exportModel'; |
65 | import { Select, Spin, Empty } from 'ant-design-vue'; | 70 | import { Select, Spin, Empty } from 'ant-design-vue'; |
66 | import { createPickerSearch } from '/@/utils/pickerSearch'; | 71 | import { createPickerSearch } from '/@/utils/pickerSearch'; |
72 | + import { getDeviceDetail } from '/@/api/device/deviceManager'; | ||
73 | + import { getAttribute } from '/@/api/ruleengine/ruleengineApi'; | ||
67 | 74 | ||
68 | interface ResponsData { | 75 | interface ResponsData { |
69 | attr: string; | 76 | attr: string; |
@@ -141,20 +148,66 @@ | @@ -141,20 +148,66 @@ | ||
141 | return chartOption; | 148 | return chartOption; |
142 | }; | 149 | }; |
143 | 150 | ||
151 | + const handleDeviceProfileAttributes = async (entityId: string) => { | ||
152 | + const deviceDetailRes = await getDeviceDetail(entityId); | ||
153 | + const { deviceProfileId } = deviceDetailRes; | ||
154 | + if (!deviceProfileId) return; | ||
155 | + const attributeRes = await getAttribute(deviceProfileId); | ||
156 | + return handleDataFormat(deviceDetailRes, attributeRes); | ||
157 | + }; | ||
158 | + | ||
159 | + const handleDataFormat = (deviceDetail: any, attributes: any) => { | ||
160 | + const { name, tbDeviceId } = deviceDetail; | ||
161 | + const attribute = attributes.map((item: any) => ({ | ||
162 | + identifier: item.identifier, | ||
163 | + name: item.name, | ||
164 | + detail: item.detail, | ||
165 | + })); | ||
166 | + return { | ||
167 | + name, | ||
168 | + tbDeviceId, | ||
169 | + attribute, | ||
170 | + }; | ||
171 | + }; | ||
172 | + | ||
144 | const [register, { setModalProps }] = useModalInner( | 173 | const [register, { setModalProps }] = useModalInner( |
145 | async (data: { record: ExecuteReportRecord }) => { | 174 | async (data: { record: ExecuteReportRecord }) => { |
146 | setModalProps({ loading: true }); | 175 | setModalProps({ loading: true }); |
147 | try { | 176 | try { |
148 | currentRecord = data.record; | 177 | currentRecord = data.record; |
149 | const deviceInfo = data.record.executeCondition.executeAttributes || []; | 178 | const deviceInfo = data.record.executeCondition.executeAttributes || []; |
150 | - chartInstance.value = deviceInfo.map((item) => ({ | ||
151 | - ...item, | ||
152 | - active: item.attributes.at(0), | ||
153 | - })); | 179 | + let attributesList: Recordable[] = []; |
180 | + // 处理为物模型里的标识符名 | ||
181 | + const reflectDeviceList = deviceInfo.map(async (item) => { | ||
182 | + const { device, attributes } = item as Recordable; | ||
183 | + if (!device) return; | ||
184 | + const thingsModel = (await handleDeviceProfileAttributes(item.device)) as Recordable; | ||
185 | + const { tbDeviceId, attribute } = thingsModel as Recordable; | ||
186 | + if (!tbDeviceId) return; | ||
187 | + if (device === tbDeviceId) { | ||
188 | + attributesList = attributes.reduce((acc, curr) => { | ||
189 | + attribute.forEach((item: Recordable) => { | ||
190 | + if (item.identifier === curr) { | ||
191 | + acc.push({ | ||
192 | + label: item.name, | ||
193 | + value: item.identifier, | ||
194 | + }); | ||
195 | + } | ||
196 | + }); | ||
197 | + return [...acc]; | ||
198 | + }, []); | ||
199 | + } | ||
200 | + return { | ||
201 | + ...item, | ||
202 | + active: attributes.at(0), | ||
203 | + attributes: attributesList, | ||
204 | + }; | ||
205 | + }); | ||
206 | + chartInstance.value = (await Promise.all(reflectDeviceList)) as any as ChartInstance[]; | ||
154 | for (const item of unref(chartInstance)) { | 207 | for (const item of unref(chartInstance)) { |
155 | const { attributes, device } = item; | 208 | const { attributes, device } = item; |
156 | 209 | ||
157 | - const keys = attributes.length ? attributes.at(0) : ''; | 210 | + const keys = attributes.length ? (attributes as any[]).at(0)?.value : ''; |
158 | 211 | ||
159 | const sendParams = { | 212 | const sendParams = { |
160 | ...data.record.executeCondition.executeCondition, | 213 | ...data.record.executeCondition.executeCondition, |