refactor: 移除冗余代码并优化错误处理
- 删除了多处不必要的 console.log 语句 - 优化了错误处理,使用 Message 组件显示错误信息 - 简化了部分代码结构,提高了可读性- 移除了未使用的注释代码
This commit is contained in:
parent
3113bac668
commit
c1c0be063d
@ -158,7 +158,6 @@
|
||||
label: '今日新增',
|
||||
value: props.alarmInfo.todayWarningCount,
|
||||
}];
|
||||
console.log(props.deviceInfo, props.alarmInfo, props.productInfo);
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
@ -241,7 +241,6 @@
|
||||
qos,
|
||||
paras: rest,
|
||||
};
|
||||
console.log(params);
|
||||
const res = await sendCommand(params);
|
||||
if (res.status === 200) {
|
||||
Message.success({
|
||||
|
@ -12,6 +12,7 @@
|
||||
import { DeviceRecord, queryDeviceList } from '@/api/device';
|
||||
import "@amap/amap-jsapi-types";
|
||||
import router from '@/router';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
|
||||
let map: any = null;
|
||||
const porps = defineProps({
|
||||
@ -88,12 +89,12 @@
|
||||
infoWindow.open(map, lngLat); // 打开信息窗体
|
||||
});
|
||||
} else {
|
||||
console.warn('设备缺少经纬度信息', porps.renderData);
|
||||
Message.error('设备缺少经纬度信息');
|
||||
}
|
||||
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
.catch(() => {
|
||||
Message.error('获取设备信息失败');
|
||||
});
|
||||
|
||||
|
||||
|
@ -2,7 +2,12 @@
|
||||
<a-layout>
|
||||
<a-layout-sider :resize-directions="['right']">
|
||||
<a-row>
|
||||
<a-col :span="24" v-for="device in deviceList" :key="device.id" @click="selectDevice(device)">
|
||||
<a-col
|
||||
:span="24"
|
||||
v-for="device in deviceList"
|
||||
:key="device.id"
|
||||
@click="selectDevice(device)"
|
||||
>
|
||||
{{ device.name }}
|
||||
</a-col>
|
||||
</a-row>
|
||||
@ -17,14 +22,15 @@
|
||||
import { onMounted, ref } from 'vue';
|
||||
import AMapLoader from '@amap/amap-jsapi-loader';
|
||||
import { DeviceRecord, queryDeviceList } from '@/api/device';
|
||||
import "@amap/amap-jsapi-types";
|
||||
import '@amap/amap-jsapi-types';
|
||||
import router from '@/router';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
|
||||
let map: any = null;
|
||||
const deviceList = ref<DeviceRecord[]>([]);
|
||||
let selectDevice = (device: DeviceRecord) => {
|
||||
console.log(device);
|
||||
}
|
||||
};
|
||||
|
||||
AMapLoader.load({
|
||||
key: 'a4e80eed798a56451b226dcfca81b846', // 申请好的Web端开发者Key,首次调用 load 时必填
|
||||
@ -58,29 +64,18 @@
|
||||
map.setZoom(20);
|
||||
map.add(marker);
|
||||
|
||||
// const infoContent = `
|
||||
// <div style="width: 220px; padding: 10px; background: #fff; border-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);">
|
||||
// <h4 style="margin: 0 0 10px; font-size: 16px; color: #333;">设备信息</h4>
|
||||
// <p style="margin: 0; font-size: 14px; color: #555;"><strong>设备名称:</strong> ${device.name}</p>
|
||||
// <p style="margin: 0; font-size: 14px; color: #555;"><strong>硬件版本:</strong> ${device.hardwareVersion}</p>
|
||||
// <p style="margin: 0; font-size: 14px; color: #555;"><strong>固件版本:</strong> ${device.firmwareVersion}</p>
|
||||
// <p style="margin: 0; font-size: 14px; color: #555;"><strong>所属产品:</strong> ${device.productId}</p>
|
||||
// </div>
|
||||
// `;
|
||||
const infoContent = [
|
||||
`<br/><div style="width: 300px;margin-left: 20px;padding-bottom: 10px"><b>设备名称: ${device.name}</b>`,
|
||||
`<span style="font-size: 16px; color: #333;">硬件版本: ${device.hardwareVersion}</span>`,
|
||||
`<span style="font-size: 16px; color: #333;">固件版本: ${device.firmwareVersion}</span>`,
|
||||
`<span style="font-size: 16px; color: #333;">所属产品: ${device.productName}</span>`,
|
||||
`<a-button style="margin-left: 200px;color: #0960bd" onclick="handleViewDetail('${device.id}')">查看详情
|
||||
</a-button></div>`
|
||||
]
|
||||
</a-button></div>`,
|
||||
];
|
||||
|
||||
const handleViewDetail = (deviceId: number) => {
|
||||
window.handleViewDetail = (deviceId: number) => {
|
||||
router.push({ name: 'deviceDetail', params: { id: deviceId } });
|
||||
};
|
||||
window.handleViewDetail = handleViewDetail;
|
||||
|
||||
|
||||
// 初始化信息窗体
|
||||
const infoWindow = new AMap.InfoWindow({
|
||||
@ -93,12 +88,12 @@
|
||||
infoWindow.open(map, lngLat); // 打开信息窗体
|
||||
});
|
||||
} else {
|
||||
console.warn('设备缺少经纬度信息', device);
|
||||
Message.error('设备缺少经纬度信息');
|
||||
}
|
||||
};
|
||||
|
||||
})
|
||||
.catch((e) => {
|
||||
Message.error('加载地图失败');
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
@ -112,15 +107,14 @@
|
||||
.then((response) => {
|
||||
deviceList.value = response.data.records;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('获取设备列表失败', error);
|
||||
.catch(() => {
|
||||
Message.error('获取设备列表失败');
|
||||
});
|
||||
});
|
||||
|
||||
// onUnmounted(() => {
|
||||
// map?.destroy();
|
||||
// });
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@ -128,33 +122,10 @@
|
||||
width: 100%;
|
||||
height: 800px;
|
||||
}
|
||||
.custom-content-marker {
|
||||
position: relative;
|
||||
width: 25px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.custom-content-marker img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.custom-content-marker .close-btn {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -8px;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
font-size: 12px;
|
||||
background: #ccc;
|
||||
border-radius: 50%;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
line-height: 15px;
|
||||
box-shadow: -1px 1px 1px rgba(10, 10, 10, .2);
|
||||
}
|
||||
|
||||
.custom-content-marker .close-btn:hover{
|
||||
background: #666;
|
||||
}
|
||||
</style>
|
@ -348,7 +348,6 @@
|
||||
if (res.status === 200) {
|
||||
onSuccess(res.data);
|
||||
formData.value.attachmentIds?.push(res.data.id);
|
||||
console.log(formData.value);
|
||||
} else {
|
||||
onError(res.data);
|
||||
}
|
||||
|
@ -692,7 +692,6 @@
|
||||
};
|
||||
// 点击添加参数
|
||||
const handleAddParams = (data: string) => {
|
||||
console.log(data);
|
||||
if (data === 'serveInputData') {
|
||||
serveInputData.value.push({
|
||||
name: '',
|
||||
|
@ -257,7 +257,6 @@
|
||||
if (res.status === 200) {
|
||||
onSuccess(res.data);
|
||||
formData.value.attachmentIds?.push(res.data.id);
|
||||
console.log(formData.value);
|
||||
} else {
|
||||
onError(res.data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user