refactor: 移除冗余代码并优化错误处理

- 删除了多处不必要的 console.log 语句
- 优化了错误处理,使用 Message 组件显示错误信息
- 简化了部分代码结构,提高了可读性- 移除了未使用的注释代码
This commit is contained in:
Kven 2025-03-11 17:26:36 +08:00
parent 3113bac668
commit c1c0be063d
7 changed files with 20 additions and 53 deletions

View File

@ -158,7 +158,6 @@
label: '今日新增', label: '今日新增',
value: props.alarmInfo.todayWarningCount, value: props.alarmInfo.todayWarningCount,
}]; }];
console.log(props.deviceInfo, props.alarmInfo, props.productInfo);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -241,7 +241,6 @@
qos, qos,
paras: rest, paras: rest,
}; };
console.log(params);
const res = await sendCommand(params); const res = await sendCommand(params);
if (res.status === 200) { if (res.status === 200) {
Message.success({ Message.success({

View File

@ -12,6 +12,7 @@
import { DeviceRecord, queryDeviceList } from '@/api/device'; import { DeviceRecord, queryDeviceList } from '@/api/device';
import "@amap/amap-jsapi-types"; import "@amap/amap-jsapi-types";
import router from '@/router'; import router from '@/router';
import { Message } from '@arco-design/web-vue';
let map: any = null; let map: any = null;
const porps = defineProps({ const porps = defineProps({
@ -88,12 +89,12 @@
infoWindow.open(map, lngLat); // infoWindow.open(map, lngLat); //
}); });
} else { } else {
console.warn('设备缺少经纬度信息', porps.renderData); Message.error('设备缺少经纬度信息');
} }
}) })
.catch((e) => { .catch(() => {
console.log(e); Message.error('获取设备信息失败');
}); });

View File

@ -2,7 +2,12 @@
<a-layout> <a-layout>
<a-layout-sider :resize-directions="['right']"> <a-layout-sider :resize-directions="['right']">
<a-row> <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 }} {{ device.name }}
</a-col> </a-col>
</a-row> </a-row>
@ -17,14 +22,15 @@
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import AMapLoader from '@amap/amap-jsapi-loader'; import AMapLoader from '@amap/amap-jsapi-loader';
import { DeviceRecord, queryDeviceList } from '@/api/device'; import { DeviceRecord, queryDeviceList } from '@/api/device';
import "@amap/amap-jsapi-types"; import '@amap/amap-jsapi-types';
import router from '@/router'; import router from '@/router';
import { Message } from '@arco-design/web-vue';
let map: any = null; let map: any = null;
const deviceList = ref<DeviceRecord[]>([]); const deviceList = ref<DeviceRecord[]>([]);
let selectDevice = (device: DeviceRecord) => { let selectDevice = (device: DeviceRecord) => {
console.log(device); console.log(device);
} };
AMapLoader.load({ AMapLoader.load({
key: 'a4e80eed798a56451b226dcfca81b846', // WebKey load key: 'a4e80eed798a56451b226dcfca81b846', // WebKey load
@ -58,29 +64,18 @@
map.setZoom(20); map.setZoom(20);
map.add(marker); 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 = [ const infoContent = [
`<br/><div style="width: 300px;margin-left: 20px;padding-bottom: 10px"><b>设备名称: ${device.name}</b>`, `<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.hardwareVersion}</span>`,
`<span style="font-size: 16px; color: #333;">固件版本: ${device.firmwareVersion}</span>`, `<span style="font-size: 16px; color: #333;">固件版本: ${device.firmwareVersion}</span>`,
`<span style="font-size: 16px; color: #333;">所属产品: ${device.productName}</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 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 } }); router.push({ name: 'deviceDetail', params: { id: deviceId } });
}; };
window.handleViewDetail = handleViewDetail;
// //
const infoWindow = new AMap.InfoWindow({ const infoWindow = new AMap.InfoWindow({
@ -93,12 +88,12 @@
infoWindow.open(map, lngLat); // infoWindow.open(map, lngLat); //
}); });
} else { } else {
console.warn('设备缺少经纬度信息', device); Message.error('设备缺少经纬度信息');
} }
}; };
}) })
.catch((e) => { .catch((e) => {
Message.error('加载地图失败');
console.log(e); console.log(e);
}); });
@ -112,15 +107,14 @@
.then((response) => { .then((response) => {
deviceList.value = response.data.records; deviceList.value = response.data.records;
}) })
.catch((error) => { .catch(() => {
console.error('获取设备列表失败', error); Message.error('获取设备列表失败');
}); });
}); });
// onUnmounted(() => { // onUnmounted(() => {
// map?.destroy(); // map?.destroy();
// }); // });
</script> </script>
<style scoped> <style scoped>
@ -128,33 +122,10 @@
width: 100%; width: 100%;
height: 800px; height: 800px;
} }
.custom-content-marker {
position: relative;
width: 25px;
height: 34px;
}
.custom-content-marker img { .custom-content-marker img {
width: 100%; width: 100%;
height: 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> </style>

View File

@ -348,7 +348,6 @@
if (res.status === 200) { if (res.status === 200) {
onSuccess(res.data); onSuccess(res.data);
formData.value.attachmentIds?.push(res.data.id); formData.value.attachmentIds?.push(res.data.id);
console.log(formData.value);
} else { } else {
onError(res.data); onError(res.data);
} }

View File

@ -692,7 +692,6 @@
}; };
// //
const handleAddParams = (data: string) => { const handleAddParams = (data: string) => {
console.log(data);
if (data === 'serveInputData') { if (data === 'serveInputData') {
serveInputData.value.push({ serveInputData.value.push({
name: '', name: '',

View File

@ -257,7 +257,6 @@
if (res.status === 200) { if (res.status === 200) {
onSuccess(res.data); onSuccess(res.data);
formData.value.attachmentIds?.push(res.data.id); formData.value.attachmentIds?.push(res.data.id);
console.log(formData.value);
} else { } else {
onError(res.data); onError(res.data);
} }