Commit c1d77499b011e73e2386077b0ec1e8b884f1731e
Merge branch 'fix/device-location-map' into 'main_dev'
fix: 修改设备位置第一次需要点击地图才显示位置问题 See merge request yunteng/thingskit-front!821
Showing
2 changed files
with
28 additions
and
5 deletions
@@ -145,6 +145,8 @@ | @@ -145,6 +145,8 @@ | ||
145 | // !!!此处需要删除地图的属性,否则会报堆栈溢出的错误 Uncaught RangeError: Maximum call stack size exceeded | 145 | // !!!此处需要删除地图的属性,否则会报堆栈溢出的错误 Uncaught RangeError: Maximum call stack size exceeded |
146 | Reflect.deleteProperty(DeviceStep1Ref.value.positionState, 'map'); | 146 | Reflect.deleteProperty(DeviceStep1Ref.value.positionState, 'map'); |
147 | Reflect.deleteProperty(DeviceStep1Ref.value.positionState, 'marker'); | 147 | Reflect.deleteProperty(DeviceStep1Ref.value.positionState, 'marker'); |
148 | + Reflect.deleteProperty(DeviceStep1Ref.value.devicePositionState, 'map'); | ||
149 | + Reflect.deleteProperty(DeviceStep1Ref.value.devicePositionState, 'marker'); | ||
148 | setModalProps({ | 150 | setModalProps({ |
149 | confirmLoading: true, | 151 | confirmLoading: true, |
150 | }); | 152 | }); |
@@ -156,7 +158,7 @@ | @@ -156,7 +158,7 @@ | ||
156 | customerId: currentDeviceData.customerId, | 158 | customerId: currentDeviceData.customerId, |
157 | deviceInfo: { | 159 | deviceInfo: { |
158 | avatar: DeviceStep1Ref.value?.devicePic, | 160 | avatar: DeviceStep1Ref.value?.devicePic, |
159 | - ...DeviceStep1Ref.value?.positionState, | 161 | + ...DeviceStep1Ref.value?.devicePositionState, |
160 | }, | 162 | }, |
161 | }; | 163 | }; |
162 | validateNameLength(stepRecord.name); | 164 | validateNameLength(stepRecord.name); |
@@ -168,7 +170,7 @@ | @@ -168,7 +170,7 @@ | ||
168 | sn: stepRecord.name, | 170 | sn: stepRecord.name, |
169 | deviceInfo: { | 171 | deviceInfo: { |
170 | avatar: DeviceStep1Ref.value?.devicePic, | 172 | avatar: DeviceStep1Ref.value?.devicePic, |
171 | - ...DeviceStep1Ref.value?.positionState, | 173 | + ...DeviceStep1Ref.value?.devicePositionState, |
172 | }, | 174 | }, |
173 | deviceToken: | 175 | deviceToken: |
174 | unref(current) === 0 || !unref(stepState).addAgree | 176 | unref(current) === 0 || !unref(stepState).addAgree |
@@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
46 | </div> | 46 | </div> |
47 | </template> | 47 | </template> |
48 | <template #deviceAddress> | 48 | <template #deviceAddress> |
49 | - <Input disabled v-model:value="positionState.address"> | 49 | + <Input disabled v-model:value="devicePositionState.address"> |
50 | <template #addonAfter> | 50 | <template #addonAfter> |
51 | <EnvironmentTwoTone @click="selectPosition" /> | 51 | <EnvironmentTwoTone @click="selectPosition" /> |
52 | </template> | 52 | </template> |
@@ -128,6 +128,7 @@ | @@ -128,6 +128,7 @@ | ||
128 | import { useDrawer } from '/@/components/Drawer'; | 128 | import { useDrawer } from '/@/components/Drawer'; |
129 | import DeptDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; | 129 | import DeptDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; |
130 | import { TaskTypeEnum } from '/@/views/task/center/config'; | 130 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
131 | + import { toRaw } from 'vue'; | ||
131 | 132 | ||
132 | export default defineComponent({ | 133 | export default defineComponent({ |
133 | components: { | 134 | components: { |
@@ -239,8 +240,14 @@ | @@ -239,8 +240,14 @@ | ||
239 | const selectPosition = () => { | 240 | const selectPosition = () => { |
240 | visible.value = true; | 241 | visible.value = true; |
241 | if (!positionState.longitude) { | 242 | if (!positionState.longitude) { |
242 | - positionState.longitude = '104.04666605565338'; | ||
243 | - positionState.latitude = '30.543516387560476'; | 243 | + positionState.longitude = '104.05326410962411'; |
244 | + positionState.latitude = '30.54855093076791'; | ||
245 | + | ||
246 | + // 根据经纬度获取详细位置 | ||
247 | + if (positionState.longitude && positionState.latitude) { | ||
248 | + var pt = new BMap.Point(positionState.longitude, positionState.latitude); | ||
249 | + getAddrByPoint(pt); | ||
250 | + } | ||
244 | initMap(positionState.longitude, positionState.latitude); | 251 | initMap(positionState.longitude, positionState.latitude); |
245 | } else { | 252 | } else { |
246 | initMap(positionState.longitude, positionState.latitude); | 253 | initMap(positionState.longitude, positionState.latitude); |
@@ -261,6 +268,15 @@ | @@ -261,6 +268,15 @@ | ||
261 | map: null, | 268 | map: null, |
262 | marker: null, | 269 | marker: null, |
263 | }); | 270 | }); |
271 | + | ||
272 | + const devicePositionState = ref({ | ||
273 | + longitude: '', | ||
274 | + latitude: '', | ||
275 | + address: '', | ||
276 | + map: null, | ||
277 | + marker: null, | ||
278 | + }); | ||
279 | + | ||
264 | /** | 280 | /** |
265 | * 逆地址解析函数(根据坐标点获取详细地址) | 281 | * 逆地址解析函数(根据坐标点获取详细地址) |
266 | * @param {Object} point 百度地图坐标点,必传 | 282 | * @param {Object} point 百度地图坐标点,必传 |
@@ -371,6 +387,7 @@ | @@ -371,6 +387,7 @@ | ||
371 | // 确定选择的位置 | 387 | // 确定选择的位置 |
372 | const handleOk = () => { | 388 | const handleOk = () => { |
373 | visible.value = false; | 389 | visible.value = false; |
390 | + devicePositionState.value = { ...toRaw(positionState) }; | ||
374 | }; | 391 | }; |
375 | // 取消选择位置 | 392 | // 取消选择位置 |
376 | const handleCancel = () => { | 393 | const handleCancel = () => { |
@@ -385,6 +402,7 @@ | @@ -385,6 +402,7 @@ | ||
385 | positionState.longitude = deviceInfo.longitude; | 402 | positionState.longitude = deviceInfo.longitude; |
386 | positionState.latitude = deviceInfo.latitude; | 403 | positionState.latitude = deviceInfo.latitude; |
387 | positionState.address = deviceInfo.address; | 404 | positionState.address = deviceInfo.address; |
405 | + devicePositionState.value = { ...toRaw(positionState) }; | ||
388 | devicePic.value = deviceInfo.avatar; | 406 | devicePic.value = deviceInfo.avatar; |
389 | setFieldsValue({ | 407 | setFieldsValue({ |
390 | ...data, | 408 | ...data, |
@@ -418,11 +436,13 @@ | @@ -418,11 +436,13 @@ | ||
418 | function parentResetDevicePic(deviceInfo) { | 436 | function parentResetDevicePic(deviceInfo) { |
419 | devicePic.value = deviceInfo.avatar; | 437 | devicePic.value = deviceInfo.avatar; |
420 | } | 438 | } |
439 | + | ||
421 | // 父组件重置位置 | 440 | // 父组件重置位置 |
422 | function parentResetPositionState() { | 441 | function parentResetPositionState() { |
423 | for (let key in positionState) { | 442 | for (let key in positionState) { |
424 | positionState[key] = ''; | 443 | positionState[key] = ''; |
425 | } | 444 | } |
445 | + devicePositionState.value = { ...toRaw(positionState) }; | ||
426 | } | 446 | } |
427 | // 禁用设备类型 | 447 | // 禁用设备类型 |
428 | function disabledDeviceType(disabled: boolean) { | 448 | function disabledDeviceType(disabled: boolean) { |
@@ -474,6 +494,7 @@ | @@ -474,6 +494,7 @@ | ||
474 | handleOpenOrgDrawer, | 494 | handleOpenOrgDrawer, |
475 | handleSuccess, | 495 | handleSuccess, |
476 | handleTreeOrg, | 496 | handleTreeOrg, |
497 | + devicePositionState, | ||
477 | }; | 498 | }; |
478 | }, | 499 | }, |
479 | }); | 500 | }); |