feat: 支持查看摄像机告警画面截图
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getCameraSnapApi, type NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { detailDeviceAlarmSnapLogApi, type NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { tryGetDeviceType, DEVICE_TYPE_LITERALS } from '@/enums';
|
||||
import { parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
@@ -7,11 +7,9 @@ import { h, ref, watch, type Ref } from 'vue';
|
||||
|
||||
export const useCameraSnapColumn = (tableData: Ref<DataTableRowData[]>) => {
|
||||
const { mutateAsync: getSnapByDeviceId } = useMutation({
|
||||
mutationFn: async (params: { deviceAlarmLog: NdmDeviceAlarmLogResultVO }) => {
|
||||
const { deviceAlarmLog } = params;
|
||||
const { deviceId } = deviceAlarmLog;
|
||||
if (!deviceId) throw new Error('设备ID不能为空');
|
||||
const snap = await getCameraSnapApi(deviceId);
|
||||
mutationFn: async (params: { id: string }) => {
|
||||
const { id } = params;
|
||||
const snap = await detailDeviceAlarmSnapLogApi(id);
|
||||
return snap;
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -28,15 +26,15 @@ export const useCameraSnapColumn = (tableData: Ref<DataTableRowData[]>) => {
|
||||
});
|
||||
|
||||
const cameraSnapColumn: DataTableColumn<NdmDeviceAlarmLogResultVO & { snapUrl?: string }> = {
|
||||
title: '实时画面截图',
|
||||
title: '告警画面截图',
|
||||
key: 'snapUrl',
|
||||
align: 'center',
|
||||
render: (rowData) => {
|
||||
const { deviceType: deviceTypeCode, snapUrl } = rowData;
|
||||
const { id, deviceType: deviceTypeCode, snapUrl } = rowData;
|
||||
if (!id) return null;
|
||||
const deviceType = tryGetDeviceType(deviceTypeCode);
|
||||
if (deviceType !== DEVICE_TYPE_LITERALS.ndmCamera) return null;
|
||||
if (!snapUrl) {
|
||||
const id = rowData.id ?? '';
|
||||
return h(
|
||||
NButton,
|
||||
{
|
||||
@@ -46,8 +44,9 @@ export const useCameraSnapColumn = (tableData: Ref<DataTableRowData[]>) => {
|
||||
onClick: async () => {
|
||||
loadingMap.value[id] = true;
|
||||
try {
|
||||
const snap = await getSnapByDeviceId({ deviceAlarmLog: rowData });
|
||||
rowData.snapUrl = snap.data.url;
|
||||
const snap = await getSnapByDeviceId({ id });
|
||||
if (!snap.url) return;
|
||||
rowData.snapUrl = snap.url;
|
||||
} finally {
|
||||
loadingMap.value[id] = false;
|
||||
}
|
||||
@@ -60,6 +59,7 @@ export const useCameraSnapColumn = (tableData: Ref<DataTableRowData[]>) => {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
cameraSnapColumn,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user