Compare commits
12 Commits
6dca2a68c0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9771164cf5 | |||
| 7e13025e3b | |||
| ed25910679 | |||
| 9449c48327 | |||
| dddaaddd4d | |||
| 5182e81429 | |||
| 84ec762d09 | |||
| d3eb97eb8b | |||
| 8077d4204a | |||
| bf304e5dfd | |||
| d16c821783 | |||
| 7c9b51a6de |
@@ -109,6 +109,19 @@ const coreRoutes: RouteRecordRaw[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
// H5 工单详情页(企微内打开,无布局,无需登录)
|
||||
{
|
||||
name: 'WorkOrder',
|
||||
path: '/work-order',
|
||||
component: () => import('#/views/work-order/index.vue'),
|
||||
meta: {
|
||||
hideInMenu: true,
|
||||
hideInTab: true,
|
||||
hideInBreadcrumb: true,
|
||||
title: '工单详情',
|
||||
ignoreAccess: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export { coreRoutes, fallbackNotFoundRoute };
|
||||
|
||||
@@ -6,10 +6,14 @@ import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Button, Image, message, Modal, Tag } from 'ant-design-vue';
|
||||
import { Image, message, Modal, Tag } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getAlert, getAlertPage, handleAlert } from '#/api/aiot/alarm';
|
||||
import {
|
||||
getAlert,
|
||||
getAlertPage,
|
||||
handleAlert,
|
||||
} from '#/api/aiot/alarm';
|
||||
|
||||
import {
|
||||
ALERT_LEVEL_OPTIONS,
|
||||
@@ -117,37 +121,61 @@ async function handleView(row: AiotAlarmApi.Alert) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理告警 */
|
||||
async function handleProcess(row: AiotAlarmApi.Alert, status: string) {
|
||||
const statusText = status === 'handled' ? '处理' : '忽略';
|
||||
Modal.confirm({
|
||||
title: `${statusText}告警`,
|
||||
content: h('div', [
|
||||
h('p', `确定要${statusText}该告警吗?`),
|
||||
h('p', { class: 'text-gray-500 text-sm' }, `告警编号:${row.alertNo}`),
|
||||
h('textarea', {
|
||||
id: 'processRemark',
|
||||
class: 'ant-input mt-2',
|
||||
rows: 3,
|
||||
placeholder: '请输入处理备注(可选)',
|
||||
}),
|
||||
]),
|
||||
async onOk() {
|
||||
const textarea = document.querySelector(
|
||||
'#processRemark',
|
||||
) as HTMLTextAreaElement;
|
||||
const remark = textarea?.value || '';
|
||||
/** 处理告警 — "处理"弹窗(支持备注) */
|
||||
const handleModalVisible = ref(false);
|
||||
const handleModalRow = ref<AiotAlarmApi.Alert | null>(null);
|
||||
const handleRemark = ref('');
|
||||
const handleSubmitting = ref(false);
|
||||
|
||||
function openHandleModal(row: AiotAlarmApi.Alert) {
|
||||
handleModalRow.value = row;
|
||||
handleRemark.value = '';
|
||||
handleModalVisible.value = true;
|
||||
}
|
||||
|
||||
async function submitHandle() {
|
||||
const row = handleModalRow.value;
|
||||
if (!row) return;
|
||||
|
||||
handleSubmitting.value = true;
|
||||
try {
|
||||
await handleAlert(
|
||||
row.alarmId || row.id!,
|
||||
'handled',
|
||||
handleRemark.value || undefined,
|
||||
);
|
||||
message.success('处理成功');
|
||||
handleModalVisible.value = false;
|
||||
handleRefresh();
|
||||
} catch (error) {
|
||||
console.error('处理失败:', error);
|
||||
message.error('处理失败');
|
||||
} finally {
|
||||
handleSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理告警 — "误报"确认弹窗 */
|
||||
function handleFalseAlarm(row: AiotAlarmApi.Alert) {
|
||||
Modal.confirm({
|
||||
title: '标记误报',
|
||||
content: h('div', [
|
||||
h('p', '确定要将该告警标记为误报吗?'),
|
||||
h('p', { class: 'text-gray-500 text-sm' }, `告警编号:${row.alertNo}`),
|
||||
]),
|
||||
okText: '确定',
|
||||
cancelText: '取消',
|
||||
async onOk() {
|
||||
const hideLoading = message.loading({
|
||||
content: '正在处理...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await handleAlert(row.alarmId || row.id!, status, remark);
|
||||
message.success(`${statusText}成功`);
|
||||
await handleAlert(row.alarmId || row.id!, 'ignored');
|
||||
message.success('已标记为误报');
|
||||
handleRefresh();
|
||||
} catch (error) {
|
||||
console.error(`${statusText}失败:`, error);
|
||||
console.error('标记误报失败:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
hideLoading();
|
||||
@@ -272,14 +300,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
label: '处理',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
onClick: handleProcess.bind(null, row, 'handled'),
|
||||
onClick: openHandleModal.bind(null, row),
|
||||
ifShow: row.status === 'pending',
|
||||
},
|
||||
{
|
||||
label: '忽略',
|
||||
label: '误报',
|
||||
type: 'link',
|
||||
danger: true,
|
||||
onClick: handleProcess.bind(null, row, 'ignored'),
|
||||
onClick: handleFalseAlarm.bind(null, row),
|
||||
ifShow: row.status === 'pending',
|
||||
},
|
||||
]"
|
||||
@@ -409,5 +437,30 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<!-- 处理告警弹窗 -->
|
||||
<Modal
|
||||
v-model:open="handleModalVisible"
|
||||
title="处理告警"
|
||||
:confirm-loading="handleSubmitting"
|
||||
ok-text="确认处理"
|
||||
cancel-text="取消"
|
||||
@ok="submitHandle"
|
||||
>
|
||||
<div v-if="handleModalRow" class="space-y-4">
|
||||
<div class="text-gray-500 text-sm">
|
||||
告警编号:{{ handleModalRow.alertNo }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="mb-1 text-sm">处理备注</div>
|
||||
<textarea
|
||||
v-model="handleRemark"
|
||||
class="ant-input w-full"
|
||||
:rows="3"
|
||||
placeholder="请输入处理备注(可选)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
@@ -18,9 +18,10 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'draw-cancelled': [];
|
||||
'roi-deleted': [roiId: string];
|
||||
'roi-drawn': [data: { roi_type: string; coordinates: string }];
|
||||
'roi-selected': [roiId: string | null];
|
||||
'roi-deleted': [roiId: string];
|
||||
'snap-status': [ok: boolean];
|
||||
}>();
|
||||
|
||||
@@ -31,19 +32,20 @@ let ctx: CanvasRenderingContext2D | null = null;
|
||||
let canvasWidth = 0;
|
||||
let canvasHeight = 0;
|
||||
|
||||
const isDrawing = ref(false);
|
||||
let startPoint: { x: number; y: number } | null = null;
|
||||
let currentPoint: { x: number; y: number } | null = null;
|
||||
const polygonPoints = ref<{ x: number; y: number }[]>([]);
|
||||
let mouseMovePoint: { x: number; y: number } | null = null;
|
||||
const loading = ref(true);
|
||||
const errorMsg = ref('');
|
||||
|
||||
watch(() => props.rois, () => redraw(), { deep: true });
|
||||
watch(() => props.selectedRoiId, () => redraw());
|
||||
watch(() => props.drawMode, () => {
|
||||
watch(() => props.drawMode, (newVal) => {
|
||||
polygonPoints.value = [];
|
||||
isDrawing.value = false;
|
||||
mouseMovePoint = null;
|
||||
redraw();
|
||||
if (newVal && wrapper.value) {
|
||||
wrapper.value.focus();
|
||||
}
|
||||
});
|
||||
watch(() => props.snapUrl, () => {
|
||||
loading.value = true;
|
||||
@@ -86,7 +88,6 @@ function onImageError() {
|
||||
loading.value = false;
|
||||
errorMsg.value = '截图加载失败,请确认摄像头拉流地址是否有效';
|
||||
emit('snap-status', false);
|
||||
// 关键:截图失败也初始化 canvas,使 ROI 区域可见可操作
|
||||
nextTick(() => initCanvas());
|
||||
}
|
||||
|
||||
@@ -143,72 +144,88 @@ function getCanvasPoint(e: MouseEvent) {
|
||||
};
|
||||
}
|
||||
|
||||
// ---- 鼠标事件 ----
|
||||
|
||||
function onMouseDown(e: MouseEvent) {
|
||||
if (e.button !== 0) return;
|
||||
const pt = getCanvasPoint(e);
|
||||
|
||||
if (props.drawMode === 'rectangle') {
|
||||
isDrawing.value = true;
|
||||
startPoint = pt;
|
||||
currentPoint = pt;
|
||||
} else if (props.drawMode === 'polygon') {
|
||||
if (props.drawMode === 'polygon') {
|
||||
polygonPoints.value.push(pt);
|
||||
redraw();
|
||||
drawPolygonInProgress();
|
||||
} else {
|
||||
} else if (!props.drawMode) {
|
||||
const clickedRoi = findRoiAtPoint(pt);
|
||||
emit('roi-selected', clickedRoi?.roiId ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseMove(e: MouseEvent) {
|
||||
if (!isDrawing.value || props.drawMode !== 'rectangle') return;
|
||||
currentPoint = getCanvasPoint(e);
|
||||
redraw();
|
||||
drawRectInProgress();
|
||||
}
|
||||
|
||||
function onMouseUp(e: MouseEvent) {
|
||||
if (!isDrawing.value || props.drawMode !== 'rectangle') return;
|
||||
isDrawing.value = false;
|
||||
const endPoint = getCanvasPoint(e);
|
||||
const x = Math.min(startPoint!.x, endPoint.x);
|
||||
const y = Math.min(startPoint!.y, endPoint.y);
|
||||
const w = Math.abs(endPoint.x - startPoint!.x);
|
||||
const h = Math.abs(endPoint.y - startPoint!.y);
|
||||
if (w > 0.01 && h > 0.01) {
|
||||
emit('roi-drawn', {
|
||||
roi_type: 'rectangle',
|
||||
coordinates: JSON.stringify({ x, y, w, h }),
|
||||
});
|
||||
}
|
||||
startPoint = null;
|
||||
currentPoint = null;
|
||||
if (props.drawMode !== 'polygon' || polygonPoints.value.length === 0) return;
|
||||
mouseMovePoint = getCanvasPoint(e);
|
||||
redraw();
|
||||
drawPolygonInProgress();
|
||||
}
|
||||
|
||||
function onDoubleClick() {
|
||||
if (props.drawMode === 'polygon' && polygonPoints.value.length >= 3) {
|
||||
emit('roi-drawn', {
|
||||
roi_type: 'polygon',
|
||||
coordinates: JSON.stringify(
|
||||
polygonPoints.value.map((p) => ({ x: p.x, y: p.y })),
|
||||
),
|
||||
});
|
||||
polygonPoints.value = [];
|
||||
redraw();
|
||||
finishPolygon();
|
||||
}
|
||||
}
|
||||
|
||||
function onContextMenu(e: MouseEvent) {
|
||||
e.preventDefault();
|
||||
const pt = getCanvasPoint(e);
|
||||
const roi = findRoiAtPoint(pt);
|
||||
if (roi?.roiId) {
|
||||
emit('roi-deleted', roi.roiId);
|
||||
if (props.drawMode === 'polygon' && polygonPoints.value.length >= 3) {
|
||||
finishPolygon();
|
||||
return;
|
||||
}
|
||||
if (!props.drawMode) {
|
||||
const pt = getCanvasPoint(e);
|
||||
const roi = findRoiAtPoint(pt);
|
||||
if (roi?.roiId) {
|
||||
emit('roi-deleted', roi.roiId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 键盘事件 ----
|
||||
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
if (props.drawMode === 'polygon') {
|
||||
if (e.key === 'Escape') {
|
||||
polygonPoints.value = [];
|
||||
mouseMovePoint = null;
|
||||
emit('draw-cancelled');
|
||||
redraw();
|
||||
} else if ((e.ctrlKey && e.key === 'z') || e.key === 'Backspace') {
|
||||
e.preventDefault();
|
||||
if (polygonPoints.value.length > 0) {
|
||||
polygonPoints.value.pop();
|
||||
redraw();
|
||||
if (polygonPoints.value.length > 0) {
|
||||
drawPolygonInProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 多边形完成(公开方法,供父组件调用) ----
|
||||
|
||||
function finishPolygon() {
|
||||
if (polygonPoints.value.length < 3) return;
|
||||
const points = polygonPoints.value.map((p) => ({ x: p.x, y: p.y }));
|
||||
emit('roi-drawn', {
|
||||
roi_type: 'polygon',
|
||||
coordinates: JSON.stringify(points),
|
||||
});
|
||||
polygonPoints.value = [];
|
||||
mouseMovePoint = null;
|
||||
redraw();
|
||||
}
|
||||
|
||||
// ---- ROI 查找 ----
|
||||
|
||||
function findRoiAtPoint(pt: { x: number; y: number }) {
|
||||
for (let i = props.rois.length - 1; i >= 0; i--) {
|
||||
const roi = props.rois[i]!;
|
||||
@@ -217,7 +234,8 @@ function findRoiAtPoint(pt: { x: number; y: number }) {
|
||||
typeof roi.coordinates === 'string'
|
||||
? JSON.parse(roi.coordinates)
|
||||
: roi.coordinates;
|
||||
if (roi.roiType === 'rectangle') {
|
||||
const type = roi.roiType;
|
||||
if (type === 'rectangle' || type === 'fullscreen') {
|
||||
if (
|
||||
pt.x >= coords.x &&
|
||||
pt.x <= coords.x + coords.w &&
|
||||
@@ -226,7 +244,7 @@ function findRoiAtPoint(pt: { x: number; y: number }) {
|
||||
) {
|
||||
return roi;
|
||||
}
|
||||
} else if (roi.roiType === 'polygon') {
|
||||
} else if (type === 'polygon') {
|
||||
if (isPointInPolygon(pt, coords)) return roi;
|
||||
}
|
||||
} catch {
|
||||
@@ -254,6 +272,8 @@ function isPointInPolygon(
|
||||
return inside;
|
||||
}
|
||||
|
||||
// ---- 绘制 ----
|
||||
|
||||
function redraw() {
|
||||
if (!ctx) return;
|
||||
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
||||
@@ -266,12 +286,13 @@ function redraw() {
|
||||
: roi.coordinates;
|
||||
const color = roi.color || '#FF0000';
|
||||
const isSelected = roi.roiId === props.selectedRoiId;
|
||||
const type = roi.roiType;
|
||||
|
||||
ctx!.strokeStyle = color;
|
||||
ctx!.lineWidth = isSelected ? 3 : 2;
|
||||
ctx!.fillStyle = `${color}33`;
|
||||
|
||||
if (roi.roiType === 'rectangle') {
|
||||
if (type === 'rectangle' || type === 'fullscreen') {
|
||||
const rx = coords.x * canvasWidth;
|
||||
const ry = coords.y * canvasHeight;
|
||||
const rw = coords.w * canvasWidth;
|
||||
@@ -283,7 +304,7 @@ function redraw() {
|
||||
ctx!.font = '12px Arial';
|
||||
ctx!.fillText(roi.name, rx + 4, ry + 14);
|
||||
}
|
||||
} else if (roi.roiType === 'polygon') {
|
||||
} else if (type === 'polygon') {
|
||||
ctx!.beginPath();
|
||||
coords.forEach((p: { x: number; y: number }, idx: number) => {
|
||||
const px = p.x * canvasWidth;
|
||||
@@ -310,19 +331,6 @@ function redraw() {
|
||||
});
|
||||
}
|
||||
|
||||
function drawRectInProgress() {
|
||||
if (!startPoint || !currentPoint || !ctx) return;
|
||||
const x = Math.min(startPoint.x, currentPoint.x) * canvasWidth;
|
||||
const y = Math.min(startPoint.y, currentPoint.y) * canvasHeight;
|
||||
const w = Math.abs(currentPoint.x - startPoint.x) * canvasWidth;
|
||||
const h = Math.abs(currentPoint.y - startPoint.y) * canvasHeight;
|
||||
ctx.strokeStyle = '#00FF00';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.setLineDash([5, 5]);
|
||||
ctx.strokeRect(x, y, w, h);
|
||||
ctx.setLineDash([]);
|
||||
}
|
||||
|
||||
function drawPolygonInProgress() {
|
||||
if (polygonPoints.value.length < 1 || !ctx) return;
|
||||
ctx.strokeStyle = '#00FF00';
|
||||
@@ -335,15 +343,31 @@ function drawPolygonInProgress() {
|
||||
if (idx === 0) ctx!.moveTo(px, py);
|
||||
else ctx!.lineTo(px, py);
|
||||
ctx!.fillStyle = '#00FF00';
|
||||
ctx!.fillRect(px - 3, py - 3, 6, 6);
|
||||
ctx!.fillRect(px - 4, py - 4, 8, 8);
|
||||
});
|
||||
// 鼠标跟随线
|
||||
if (mouseMovePoint) {
|
||||
ctx.lineTo(
|
||||
mouseMovePoint.x * canvasWidth,
|
||||
mouseMovePoint.y * canvasHeight,
|
||||
);
|
||||
}
|
||||
// 首尾闭合预览线
|
||||
if (polygonPoints.value.length >= 3) {
|
||||
const first = polygonPoints.value[0]!;
|
||||
const last = mouseMovePoint || polygonPoints.value[polygonPoints.value.length - 1]!;
|
||||
ctx.moveTo(last.x * canvasWidth, last.y * canvasHeight);
|
||||
ctx.lineTo(first.x * canvasWidth, first.y * canvasHeight);
|
||||
}
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
}
|
||||
|
||||
defineExpose({ polygonPoints, finishPolygon, redraw, drawPolygonInProgress });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapper" class="roi-canvas-wrapper">
|
||||
<div ref="wrapper" class="roi-canvas-wrapper" tabindex="0" @keydown="onKeyDown">
|
||||
<img
|
||||
v-if="snapUrl"
|
||||
:src="snapUrl"
|
||||
@@ -358,12 +382,16 @@ function drawPolygonInProgress() {
|
||||
<canvas
|
||||
ref="canvas"
|
||||
class="roi-overlay"
|
||||
:class="{ drawing: drawMode === 'polygon' }"
|
||||
@mousedown="onMouseDown"
|
||||
@mousemove="onMouseMove"
|
||||
@mouseup="onMouseUp"
|
||||
@dblclick="onDoubleClick"
|
||||
@contextmenu="onContextMenu"
|
||||
/>
|
||||
<!-- 绘制中浮动提示条 -->
|
||||
<div v-if="drawMode === 'polygon'" class="draw-hint-bar">
|
||||
单击添加顶点 | 双击或右键完成选区 | Esc取消 | Ctrl+Z撤销
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -374,6 +402,7 @@ function drawPolygonInProgress() {
|
||||
height: 100%;
|
||||
min-height: 400px;
|
||||
background: #000;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.bg-image {
|
||||
@@ -396,6 +425,24 @@ function drawPolygonInProgress() {
|
||||
|
||||
.roi-overlay {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.roi-overlay.drawing {
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
.draw-hint-bar {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
color: #fff;
|
||||
padding: 6px 16px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
z-index: 10;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* ROI 区域配置页面
|
||||
*
|
||||
* 功能:摄像头截图展示、ROI 区域绘制(矩形/多边形)、ROI 属性编辑、
|
||||
* 功能:摄像头截图展示、ROI 区域绘制(全图/自定义多边形)、ROI 属性编辑、
|
||||
* 算法绑定管理、配置推送到边缘端
|
||||
* 后端:WVP 视频平台 AiRoi / AiConfig API
|
||||
*/
|
||||
@@ -65,31 +65,26 @@ const selectedRoiId = ref<null | string>(null);
|
||||
const selectedRoiBindings = ref<AiotDeviceApi.RoiAlgoBinding[]>([]);
|
||||
const snapUrl = ref('');
|
||||
const snapOk = ref(false);
|
||||
|
||||
const edgeDevices = ref<Array<{ deviceId: string }>>([]);
|
||||
|
||||
async function loadEdgeDevices() {
|
||||
try {
|
||||
const list = await wvpRequestClient.get<Array<{ deviceId: string }>>('/aiot/device/device/list');
|
||||
edgeDevices.value = (list as any) || [];
|
||||
} catch {
|
||||
edgeDevices.value = [{ deviceId: 'edge' }];
|
||||
}
|
||||
}
|
||||
const panelVisible = ref(false);
|
||||
const roiCanvasRef = ref<InstanceType<typeof RoiCanvas> | null>(null);
|
||||
|
||||
const selectedRoi = computed(() => {
|
||||
if (!selectedRoiId.value) return null;
|
||||
return roiList.value.find((r) => r.roiId === selectedRoiId.value) || null;
|
||||
});
|
||||
|
||||
const isDrawing = computed(() => drawMode.value === 'polygon');
|
||||
|
||||
const polygonPointCount = computed(() => {
|
||||
return roiCanvasRef.value?.polygonPoints?.length ?? 0;
|
||||
});
|
||||
|
||||
// ==================== 初始化 ====================
|
||||
|
||||
onMounted(async () => {
|
||||
loadEdgeDevices();
|
||||
const q = route.query;
|
||||
if (q.cameraCode) {
|
||||
cameraCode.value = String(q.cameraCode);
|
||||
// 加载摄像头信息以获取应用名
|
||||
await loadCurrentCamera();
|
||||
await buildSnapUrl();
|
||||
loadRois();
|
||||
@@ -121,7 +116,7 @@ async function loadCameraOptions() {
|
||||
const list = res.list || [];
|
||||
cameraOptions.value = list.map((cam: AiotDeviceApi.Camera) => ({
|
||||
value: cam.cameraCode || '',
|
||||
label: `${cam.app || cam.stream}${cam.srcUrl ? ` (${cam.srcUrl})` : ''}`,
|
||||
label: `${cam.cameraName || cam.app || cam.stream}${cam.srcUrl ? ` (${cam.srcUrl})` : ''}`,
|
||||
camera: cam,
|
||||
}));
|
||||
} catch {
|
||||
@@ -146,6 +141,20 @@ function goBack() {
|
||||
router.push('/aiot/device/camera');
|
||||
}
|
||||
|
||||
// ==================== ROI 类型标签 ====================
|
||||
|
||||
function getRoiTagColor(roi: AiotDeviceApi.Roi) {
|
||||
if (roi.roiType === 'fullscreen') return 'orange';
|
||||
if (roi.roiType === 'rectangle') return 'blue';
|
||||
return 'green';
|
||||
}
|
||||
|
||||
function getRoiTagLabel(roi: AiotDeviceApi.Roi) {
|
||||
if (roi.roiType === 'fullscreen') return '全图';
|
||||
if (roi.roiType === 'rectangle') return '矩形';
|
||||
return '自定义';
|
||||
}
|
||||
|
||||
// ==================== 截图 ====================
|
||||
|
||||
async function buildSnapUrl(force = false) {
|
||||
@@ -188,42 +197,98 @@ async function loadRoiDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== ROI 绘制 ====================
|
||||
// ==================== 全图 ====================
|
||||
|
||||
function addFullscreen() {
|
||||
const hasFullscreen = roiList.value.some((r) => r.roiType === 'fullscreen');
|
||||
if (hasFullscreen) {
|
||||
message.warning('已存在全图选区');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '新建全图选区',
|
||||
content: '将创建覆盖整张图片的选区',
|
||||
async onOk() {
|
||||
const newRoi: Partial<AiotDeviceApi.Roi> = {
|
||||
cameraId: cameraCode.value,
|
||||
name: `全图-${roiList.value.length + 1}`,
|
||||
roiType: 'fullscreen',
|
||||
coordinates: JSON.stringify({ x: 0, y: 0, w: 1, h: 1 }),
|
||||
color: '#FF0000',
|
||||
priority: 0,
|
||||
enabled: 1,
|
||||
description: '',
|
||||
deviceId: '',
|
||||
};
|
||||
try {
|
||||
await saveRoi(newRoi);
|
||||
message.success('全图选区已创建');
|
||||
loadRois();
|
||||
} catch {
|
||||
message.error('保存失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 自定义选区(多边形绘制) ====================
|
||||
|
||||
function startDraw(mode: string) {
|
||||
drawMode.value = mode;
|
||||
}
|
||||
|
||||
function finishDraw() {
|
||||
roiCanvasRef.value?.finishPolygon();
|
||||
}
|
||||
|
||||
function undoPoint() {
|
||||
if (roiCanvasRef.value && roiCanvasRef.value.polygonPoints.length > 0) {
|
||||
roiCanvasRef.value.polygonPoints.pop();
|
||||
roiCanvasRef.value.redraw();
|
||||
if (roiCanvasRef.value.polygonPoints.length > 0) {
|
||||
roiCanvasRef.value.drawPolygonInProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cancelDraw() {
|
||||
drawMode.value = null;
|
||||
}
|
||||
|
||||
function onDrawCancelled() {
|
||||
drawMode.value = null;
|
||||
}
|
||||
|
||||
async function onRoiDrawn(data: { coordinates: string; roi_type: string }) {
|
||||
drawMode.value = null;
|
||||
const roiName = `ROI-${roiList.value.length + 1}`;
|
||||
const newRoi: Partial<AiotDeviceApi.Roi> = {
|
||||
cameraId: cameraCode.value,
|
||||
name: `ROI-${roiList.value.length + 1}`,
|
||||
name: roiName,
|
||||
roiType: data.roi_type,
|
||||
coordinates: data.coordinates,
|
||||
color: '#FF0000',
|
||||
priority: 0,
|
||||
enabled: 1,
|
||||
description: '',
|
||||
deviceId: edgeDevices.value[0]?.deviceId || 'edge', // 默认关联边缘设备
|
||||
deviceId: '',
|
||||
};
|
||||
try {
|
||||
await saveRoi(newRoi);
|
||||
message.success('ROI已保存');
|
||||
message.success('选区已保存');
|
||||
loadRois();
|
||||
} catch {
|
||||
message.error('保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== ROI 选择 ====================
|
||||
// ==================== ROI 选择与面板 ====================
|
||||
|
||||
function onRoiSelected(roiId: null | string) {
|
||||
selectedRoiId.value = roiId;
|
||||
if (roiId) {
|
||||
panelVisible.value = true;
|
||||
loadRoiDetail();
|
||||
} else {
|
||||
selectedRoiBindings.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +297,12 @@ function selectRoi(roi: AiotDeviceApi.Roi) {
|
||||
loadRoiDetail();
|
||||
}
|
||||
|
||||
function closePanel() {
|
||||
panelVisible.value = false;
|
||||
selectedRoiId.value = null;
|
||||
selectedRoiBindings.value = [];
|
||||
}
|
||||
|
||||
// ==================== ROI 编辑 ====================
|
||||
|
||||
async function updateRoiData(roi: AiotDeviceApi.Roi) {
|
||||
@@ -246,7 +317,13 @@ async function updateRoiData(roi: AiotDeviceApi.Roi) {
|
||||
// ==================== ROI 删除 ====================
|
||||
|
||||
function onRoiDeleted(roiId: string) {
|
||||
doDeleteRoi(roiId);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
content: '确定删除该ROI?关联的算法绑定也将删除。',
|
||||
async onOk() {
|
||||
doDeleteRoi(roiId);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDeleteRoi(roi: AiotDeviceApi.Roi) {
|
||||
@@ -267,7 +344,10 @@ async function doDeleteRoi(roiId: string) {
|
||||
selectedRoiId.value = null;
|
||||
selectedRoiBindings.value = [];
|
||||
}
|
||||
loadRois();
|
||||
await loadRois();
|
||||
if (roiList.value.length === 0) {
|
||||
panelVisible.value = false;
|
||||
}
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
@@ -316,40 +396,43 @@ function handlePush() {
|
||||
<div class="page-header">
|
||||
<div class="header-left">
|
||||
<Button size="small" @click="goBack">返回</Button>
|
||||
<h3>{{ currentCamera?.app || cameraCode }} - ROI配置</h3>
|
||||
<h3>{{ currentCamera?.cameraName || currentCamera?.app || cameraCode }} - ROI配置</h3>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
:disabled="drawMode === 'rectangle'"
|
||||
@click="startDraw('rectangle')"
|
||||
>
|
||||
画矩形
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
:disabled="drawMode === 'polygon'"
|
||||
@click="startDraw('polygon')"
|
||||
>
|
||||
画多边形
|
||||
</Button>
|
||||
<Button size="small" :disabled="!drawMode" @click="drawMode = null">
|
||||
取消绘制
|
||||
</Button>
|
||||
<Button size="small" @click="refreshSnap">刷新截图</Button>
|
||||
<Button size="small" type="default" @click="handlePush">
|
||||
推送到边缘端
|
||||
</Button>
|
||||
<!-- 默认工具栏 -->
|
||||
<template v-if="!isDrawing">
|
||||
<Button size="small" type="primary" @click="addFullscreen">
|
||||
全图
|
||||
</Button>
|
||||
<Button size="small" type="primary" @click="startDraw('polygon')">
|
||||
自定义选区
|
||||
</Button>
|
||||
<Button size="small" @click="refreshSnap">刷新截图</Button>
|
||||
<Button size="small" type="default" @click="handlePush">
|
||||
推送到边缘端
|
||||
</Button>
|
||||
</template>
|
||||
<!-- 绘制中工具栏 -->
|
||||
<template v-else>
|
||||
<Button size="small" type="primary" :disabled="polygonPointCount < 3" @click="finishDraw">
|
||||
完成选区
|
||||
</Button>
|
||||
<Button size="small" :disabled="polygonPointCount === 0" @click="undoPoint">
|
||||
撤销上一点
|
||||
</Button>
|
||||
<Button size="small" danger @click="cancelDraw">
|
||||
取消绘制
|
||||
</Button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 主内容区:左侧画布 + 右侧面板 -->
|
||||
<div class="main-content">
|
||||
<!-- 画布区域 -->
|
||||
<div class="canvas-panel">
|
||||
<div :class="['canvas-panel', { 'panel-open': panelVisible }]">
|
||||
<RoiCanvas
|
||||
ref="roiCanvasRef"
|
||||
:rois="roiList"
|
||||
:draw-mode="drawMode"
|
||||
:selected-roi-id="selectedRoiId"
|
||||
@@ -357,134 +440,126 @@ function handlePush() {
|
||||
@roi-drawn="onRoiDrawn"
|
||||
@roi-selected="onRoiSelected"
|
||||
@roi-deleted="onRoiDeleted"
|
||||
@draw-cancelled="onDrawCancelled"
|
||||
@snap-status="onSnapStatus"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 右侧面板 -->
|
||||
<div class="side-panel">
|
||||
<!-- ROI 列表 -->
|
||||
<div class="section-header">
|
||||
<span>ROI列表 ({{ roiList.length }})</span>
|
||||
</div>
|
||||
<div v-if="roiList.length === 0" class="empty-tip">
|
||||
暂无ROI,请在左侧画面上绘制
|
||||
</div>
|
||||
<div
|
||||
v-for="roi in roiList"
|
||||
:key="roi.roiId"
|
||||
:class="['roi-item', { active: selectedRoiId === roi.roiId }]"
|
||||
@click="selectRoi(roi)"
|
||||
>
|
||||
<div class="roi-item-header">
|
||||
<span
|
||||
class="roi-color"
|
||||
:style="{ background: roi.color || '#FF0000' }"
|
||||
/>
|
||||
<span class="roi-name">{{ roi.name || '未命名' }}</span>
|
||||
<Tag
|
||||
:color="roi.roiType === 'rectangle' ? 'blue' : 'green'"
|
||||
style="margin-right: 0"
|
||||
>
|
||||
{{ roi.roiType === 'rectangle' ? '矩形' : '多边形' }}
|
||||
</Tag>
|
||||
<Switch
|
||||
:checked="roi.enabled === 1"
|
||||
size="small"
|
||||
style="margin-left: auto"
|
||||
@change="
|
||||
(val: string | number | boolean) => {
|
||||
roi.enabled = val ? 1 : 0;
|
||||
updateRoiData(roi);
|
||||
}
|
||||
"
|
||||
@click.stop
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
danger
|
||||
style="margin-left: 4px"
|
||||
@click.stop="handleDeleteRoi(roi)"
|
||||
>
|
||||
删除
|
||||
<transition name="slide-panel">
|
||||
<div v-if="panelVisible" class="side-panel">
|
||||
<div class="panel-close">
|
||||
<Button size="small" shape="circle" @click="closePanel">
|
||||
✕
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
<!-- ROI 属性编辑 -->
|
||||
<div v-if="selectedRoi" class="roi-detail-section">
|
||||
<h4>ROI属性</h4>
|
||||
<Form
|
||||
layout="horizontal"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
size="small"
|
||||
<!-- ROI 列表 -->
|
||||
<div class="section-header">
|
||||
<span>ROI列表 ({{ roiList.length }})</span>
|
||||
</div>
|
||||
<div v-if="roiList.length === 0" class="empty-tip">
|
||||
暂无ROI,请使用上方按钮添加
|
||||
</div>
|
||||
<div
|
||||
v-for="roi in roiList"
|
||||
:key="roi.roiId"
|
||||
:class="['roi-item', { active: selectedRoiId === roi.roiId }]"
|
||||
@click="selectRoi(roi)"
|
||||
>
|
||||
<Form.Item label="名称">
|
||||
<Input
|
||||
v-model:value="selectedRoi.name"
|
||||
@blur="updateRoiData(selectedRoi!)"
|
||||
<div class="roi-item-header">
|
||||
<span
|
||||
class="roi-color"
|
||||
:style="{ background: roi.color || '#FF0000' }"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="边缘设备">
|
||||
<Select
|
||||
v-model:value="selectedRoi.deviceId"
|
||||
placeholder="选择边缘设备"
|
||||
@change="updateRoiData(selectedRoi!)"
|
||||
<span class="roi-name">{{ roi.name || '未命名' }}</span>
|
||||
<Tag
|
||||
:color="getRoiTagColor(roi)"
|
||||
style="margin-right: 0"
|
||||
>
|
||||
<Select.Option v-for="dev in edgeDevices" :key="dev.deviceId" :value="dev.deviceId">
|
||||
{{ dev.deviceId }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
<div style="margin-top: 4px; font-size: 12px; color: #999">
|
||||
关联的边缘推理节点
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item label="颜色">
|
||||
<Input
|
||||
v-model:value="selectedRoi.color"
|
||||
type="color"
|
||||
style="width: 60px; padding: 2px"
|
||||
@change="updateRoiData(selectedRoi!)"
|
||||
{{ getRoiTagLabel(roi) }}
|
||||
</Tag>
|
||||
<Switch
|
||||
:checked="roi.enabled === 1"
|
||||
size="small"
|
||||
style="margin-left: auto"
|
||||
@change="
|
||||
(val: string | number | boolean) => {
|
||||
roi.enabled = val ? 1 : 0;
|
||||
updateRoiData(roi);
|
||||
}
|
||||
"
|
||||
@click.stop
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="优先级">
|
||||
<InputNumber
|
||||
v-model:value="selectedRoi.priority"
|
||||
:min="0"
|
||||
:max="100"
|
||||
@change="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
<div style="margin-top: 4px; font-size: 12px; color: #999">
|
||||
数值越大优先级越高(0-100),多个ROI重叠时优先处理高优先级区域
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item label="描述">
|
||||
<Input.TextArea
|
||||
v-model:value="selectedRoi.description"
|
||||
:rows="2"
|
||||
@blur="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<Button
|
||||
size="small"
|
||||
type="text"
|
||||
danger
|
||||
style="margin-left: 4px"
|
||||
@click.stop="handleDeleteRoi(roi)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
<!-- 算法绑定管理 -->
|
||||
<RoiAlgorithmBind
|
||||
:roi-id="selectedRoi.roiId || ''"
|
||||
:bindings="selectedRoiBindings"
|
||||
:snap-ok="snapOk"
|
||||
@changed="loadRoiDetail"
|
||||
/>
|
||||
<!-- ROI 属性编辑 -->
|
||||
<div v-if="selectedRoi" class="roi-detail-section">
|
||||
<h4>ROI属性</h4>
|
||||
<Form
|
||||
layout="horizontal"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
size="small"
|
||||
>
|
||||
<Form.Item label="名称">
|
||||
<Input
|
||||
v-model:value="selectedRoi.name"
|
||||
@blur="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="颜色">
|
||||
<Input
|
||||
v-model:value="selectedRoi.color"
|
||||
type="color"
|
||||
style="width: 60px; padding: 2px"
|
||||
@change="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="优先级">
|
||||
<InputNumber
|
||||
v-model:value="selectedRoi.priority"
|
||||
:min="0"
|
||||
:max="100"
|
||||
@change="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="描述">
|
||||
<Input.TextArea
|
||||
v-model:value="selectedRoi.description"
|
||||
:rows="2"
|
||||
@blur="updateRoiData(selectedRoi!)"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<Divider />
|
||||
|
||||
<!-- 算法绑定管理 -->
|
||||
<RoiAlgorithmBind
|
||||
:roi-id="selectedRoi.roiId || ''"
|
||||
:bindings="selectedRoiBindings"
|
||||
:snap-ok="snapOk"
|
||||
@changed="loadRoiDetail"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="empty-tip" style="margin-top: 20px">
|
||||
点击左侧ROI区域或列表项查看详情
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-tip" style="margin-top: 20px">
|
||||
点击左侧ROI区域或列表项查看详情
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
@@ -513,6 +588,7 @@ function handlePush() {
|
||||
|
||||
.header-left h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
@@ -523,15 +599,21 @@ function handlePush() {
|
||||
.main-content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 12px;
|
||||
gap: 0;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.canvas-panel {
|
||||
flex: 6;
|
||||
flex: 1;
|
||||
background: #000;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
transition: flex 0.3s ease;
|
||||
}
|
||||
|
||||
.canvas-panel.panel-open {
|
||||
flex: 6;
|
||||
}
|
||||
|
||||
.side-panel {
|
||||
@@ -539,8 +621,28 @@ function handlePush() {
|
||||
overflow-y: auto;
|
||||
background: #fff;
|
||||
border: 1px solid #f0f0f0;
|
||||
border-radius: 4px;
|
||||
border-radius: 0 4px 4px 0;
|
||||
padding: 12px;
|
||||
margin-left: 1px;
|
||||
}
|
||||
|
||||
.panel-close {
|
||||
text-align: right;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
/* 面板滑入动画 */
|
||||
.slide-panel-enter-active,
|
||||
.slide-panel-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.slide-panel-enter-from,
|
||||
.slide-panel-leave-to {
|
||||
flex: 0 !important;
|
||||
padding: 0 !important;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
|
||||
452
apps/web-antd/src/views/work-order/index.vue
Normal file
452
apps/web-antd/src/views/work-order/index.vue
Normal file
@@ -0,0 +1,452 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* H5 工单详情页
|
||||
*
|
||||
* 企微卡片点击跳转到此页面,保安可以:
|
||||
* - 查看告警截图和详情
|
||||
* - 填写处理描述
|
||||
* - 拍照上传处理后照片
|
||||
* - 提交完成工单
|
||||
*/
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Image,
|
||||
Input,
|
||||
message,
|
||||
Result,
|
||||
Spin,
|
||||
Tag,
|
||||
Upload,
|
||||
} from 'ant-design-vue';
|
||||
// 使用 Unicode 字符替代 @ant-design/icons-vue(该包未安装)
|
||||
// CameraOutlined → 📷, UploadOutlined → 用文字
|
||||
|
||||
defineOptions({ name: 'WorkOrderDetail' });
|
||||
|
||||
const route = useRoute();
|
||||
const alarmId = ref('');
|
||||
const loading = ref(true);
|
||||
const submitting = ref(false);
|
||||
const detail = ref<any>(null);
|
||||
const error = ref('');
|
||||
|
||||
// 处理表单
|
||||
const remark = ref('');
|
||||
const uploadedImages = ref<string[]>([]);
|
||||
const uploading = ref(false);
|
||||
|
||||
// API 基础地址(vsp-service)
|
||||
const API_BASE = import.meta.env.VITE_VSP_SERVICE_URL || 'http://124.221.55.225:8000';
|
||||
|
||||
// 企微 OAuth2 配置
|
||||
const CORP_ID = import.meta.env.VITE_WECHAT_CORP_ID || '';
|
||||
const AGENT_ID = import.meta.env.VITE_WECHAT_AGENT_ID || '';
|
||||
|
||||
// 当前认证用户
|
||||
const currentUserId = ref('');
|
||||
const authChecked = ref(false);
|
||||
|
||||
/** 企微 OAuth2 认证 */
|
||||
async function checkAuth() {
|
||||
// 检查 URL 中是否有 code 参数(OAuth2 回调带回)
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const code = urlParams.get('code');
|
||||
|
||||
if (code) {
|
||||
// 用 code 换 userid
|
||||
try {
|
||||
const resp = await fetch(`${API_BASE}/api/work-order/auth?code=${code}`);
|
||||
const data = await resp.json();
|
||||
if (data.code === 0 && data.data?.userId) {
|
||||
currentUserId.value = data.data.userId;
|
||||
authChecked.value = true;
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
// code 可能已过期
|
||||
}
|
||||
}
|
||||
|
||||
// 没有 code 或 code 无效:跳转企微 OAuth2 授权
|
||||
if (CORP_ID) {
|
||||
const redirectUri = encodeURIComponent(window.location.href.split('?')[0] + '?' + urlParams.toString());
|
||||
const oauthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${CORP_ID}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&agentid=${AGENT_ID}&state=workorder#wechat_redirect`;
|
||||
window.location.href = oauthUrl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 未配置企微参数,跳过认证(开发模式)
|
||||
authChecked.value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 加载工单详情 */
|
||||
async function loadDetail() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const resp = await fetch(
|
||||
`${API_BASE}/api/work-order/detail?alarmId=${alarmId.value}`,
|
||||
);
|
||||
const data = await resp.json();
|
||||
if (data.code === 0) {
|
||||
detail.value = data.data;
|
||||
} else {
|
||||
error.value = data.msg || '加载失败';
|
||||
}
|
||||
} catch (e: any) {
|
||||
error.value = e.message || '网络异常';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 上传图片 */
|
||||
async function handleUpload(file: File) {
|
||||
uploading.value = true;
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const resp = await fetch(`${API_BASE}/api/work-order/upload-image`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.code === 0 && data.data?.url) {
|
||||
uploadedImages.value.push(data.data.url);
|
||||
message.success('图片上传成功');
|
||||
} else {
|
||||
message.error(data.msg || '上传失败');
|
||||
}
|
||||
} catch {
|
||||
message.error('图片上传失败');
|
||||
} finally {
|
||||
uploading.value = false;
|
||||
}
|
||||
return false; // 阻止 antd 默认上传
|
||||
}
|
||||
|
||||
/** 提交处理结果 */
|
||||
async function handleSubmit() {
|
||||
if (!remark.value.trim()) {
|
||||
message.warning('请填写处理描述');
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
const resp = await fetch(`${API_BASE}/api/work-order/submit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
alarmId: alarmId.value,
|
||||
result: remark.value.trim(),
|
||||
resultImgUrls:
|
||||
uploadedImages.value.length > 0 ? uploadedImages.value : undefined,
|
||||
}),
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (data.code === 0) {
|
||||
message.success('提交成功');
|
||||
await loadDetail(); // 刷新状态
|
||||
} else {
|
||||
message.error(data.msg || '提交失败');
|
||||
}
|
||||
} catch {
|
||||
message.error('提交失败,请重试');
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除已上传图片 */
|
||||
function removeImage(index: number) {
|
||||
uploadedImages.value.splice(index, 1);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
alarmId.value = (route.query.alarmId as string) || '';
|
||||
if (!alarmId.value) {
|
||||
loading.value = false;
|
||||
error.value = '缺少告警ID参数';
|
||||
return;
|
||||
}
|
||||
|
||||
// 企微 OAuth2 认证
|
||||
const authed = await checkAuth();
|
||||
if (!authed) return; // 正在跳转授权页
|
||||
|
||||
loadDetail();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="work-order-page">
|
||||
<!-- 加载中 -->
|
||||
<div v-if="loading" class="center-box">
|
||||
<Spin size="large" tip="加载中..." />
|
||||
</div>
|
||||
|
||||
<!-- 错误 -->
|
||||
<Result v-else-if="error" status="error" :title="error" />
|
||||
|
||||
<!-- 工单详情 -->
|
||||
<div v-else-if="detail" class="detail-container">
|
||||
<!-- 头部状态 -->
|
||||
<div class="status-bar">
|
||||
<Tag
|
||||
:color="
|
||||
detail.status === 'completed'
|
||||
? 'green'
|
||||
: detail.status === 'false_alarm'
|
||||
? 'default'
|
||||
: detail.status === 'processing'
|
||||
? 'blue'
|
||||
: 'orange'
|
||||
"
|
||||
class="status-tag"
|
||||
>
|
||||
{{
|
||||
detail.status === 'pending'
|
||||
? '待处理'
|
||||
: detail.status === 'processing'
|
||||
? '处理中'
|
||||
: detail.status === 'completed'
|
||||
? '已完成'
|
||||
: '误报'
|
||||
}}
|
||||
</Tag>
|
||||
<span class="order-id" v-if="detail.orderId">
|
||||
工单 #{{ detail.orderId }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 告警信息 -->
|
||||
<Card size="small" class="info-card">
|
||||
<div class="info-row">
|
||||
<span class="label">告警类型</span>
|
||||
<span>{{ detail.alarmType }}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">告警级别</span>
|
||||
<Tag
|
||||
:color="
|
||||
detail.alarmLevel === '紧急'
|
||||
? 'red'
|
||||
: detail.alarmLevel === '重要'
|
||||
? 'orange'
|
||||
: 'blue'
|
||||
"
|
||||
>
|
||||
{{ detail.alarmLevel }}
|
||||
</Tag>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">摄像头</span>
|
||||
<span>{{ detail.cameraName }}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">告警时间</span>
|
||||
<span>{{ detail.eventTime }}</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<!-- 告警截图 -->
|
||||
<Card v-if="detail.snapshotUrl" size="small" title="告警截图" class="info-card">
|
||||
<Image :src="detail.snapshotUrl" :width="'100%'" />
|
||||
</Card>
|
||||
|
||||
<!-- 已完成/误报:显示处理结果 -->
|
||||
<Card
|
||||
v-if="detail.status === 'completed' || detail.status === 'false_alarm'"
|
||||
size="small"
|
||||
title="处理结果"
|
||||
class="info-card"
|
||||
>
|
||||
<div class="info-row">
|
||||
<span class="label">处理人</span>
|
||||
<span>{{ detail.handler || '-' }}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">处理时间</span>
|
||||
<span>{{ detail.handledAt || '-' }}</span>
|
||||
</div>
|
||||
<div v-if="detail.handleRemark" class="info-row">
|
||||
<span class="label">处理描述</span>
|
||||
<span>{{ detail.handleRemark }}</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<!-- 处理中:显示提交表单 -->
|
||||
<Card
|
||||
v-if="detail.status === 'processing' || detail.status === 'pending'"
|
||||
size="small"
|
||||
title="提交处理结果"
|
||||
class="info-card"
|
||||
>
|
||||
<div class="form-section">
|
||||
<div class="form-label">处理描述 *</div>
|
||||
<Input.TextArea
|
||||
v-model:value="remark"
|
||||
placeholder="请描述处理情况..."
|
||||
:rows="3"
|
||||
:maxlength="500"
|
||||
show-count
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<div class="form-label">上传现场照片(可选)</div>
|
||||
<div class="upload-area">
|
||||
<div
|
||||
v-for="(img, idx) in uploadedImages"
|
||||
:key="idx"
|
||||
class="uploaded-item"
|
||||
>
|
||||
<Image :src="img" :width="80" :height="80" />
|
||||
<span class="remove-btn" @click="removeImage(idx)">×</span>
|
||||
</div>
|
||||
<Upload
|
||||
:before-upload="handleUpload"
|
||||
:show-upload-list="false"
|
||||
accept="image/*"
|
||||
>
|
||||
<div class="upload-btn">
|
||||
<span style="font-size: 24px">📷</span>
|
||||
<span>拍照/选图</span>
|
||||
</div>
|
||||
</Upload>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="primary"
|
||||
block
|
||||
size="large"
|
||||
:loading="submitting"
|
||||
:disabled="!remark.trim()"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
提交处理结果
|
||||
</Button>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.work-order-page {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.center-box {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 60vh;
|
||||
}
|
||||
|
||||
.detail-container {
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-size: 14px;
|
||||
padding: 4px 12px;
|
||||
}
|
||||
|
||||
.order-id {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.uploaded-item {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
position: absolute;
|
||||
top: -6px;
|
||||
right: -6px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background: #ff4d4f;
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.upload-btn {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.upload-btn:hover {
|
||||
border-color: #1890ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user