2024-11-14 13:43:41 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2024-11-19 09:55:07 +08:00
|
|
|
<div class="header">
|
|
|
|
<SvgIcon size="19" name="list" />
|
2024-11-19 12:15:56 +08:00
|
|
|
<div class="title">任务列表</div>
|
2024-11-19 09:55:07 +08:00
|
|
|
</div>
|
2024-11-14 13:43:41 +08:00
|
|
|
<BasicTable @register="registerTable">
|
|
|
|
<template #toolbar>
|
2025-01-03 11:19:45 +08:00
|
|
|
<a-button type="primary" @click="handleCreate" :icon="h(PlusOutlined)">新 增</a-button>
|
2024-11-22 11:07:04 +08:00
|
|
|
<div style="width: 5px" />
|
2025-01-08 11:28:29 +08:00
|
|
|
<a-button type="default" :icon="h(EyeOutlined)" @click="handleOpenFileDialog(null)">OCR识别</a-button>
|
|
|
|
<input type="file" ref="fileInput" accept="application/pdf" aria-hidden="true" @change="handleFileChange" style="display: none;" />
|
2024-11-22 11:07:04 +08:00
|
|
|
<div style="width: 5px" />
|
2024-11-19 15:58:46 +08:00
|
|
|
<a-button type="default" @click="handleDownload" :icon="h(DownloadOutlined)" :disabled="checkedKeys.length === 0">下发数据</a-button>
|
|
|
|
<a-button type="default" @click="handleSync" :icon="h(SyncOutlined)" :disabled="checkedKeys.length === 0">同步数据</a-button>
|
2024-11-14 13:43:41 +08:00
|
|
|
</template>
|
|
|
|
<template #bodyCell="{ column, record }">
|
|
|
|
<template v-if="column.dataIndex === 'action'">
|
|
|
|
<TableAction
|
|
|
|
:actions="[
|
|
|
|
{
|
|
|
|
label: '编辑',
|
|
|
|
icon: 'clarity:note-edit-line',
|
|
|
|
onClick: handleEdit.bind(null, record),
|
2024-11-15 17:30:24 +08:00
|
|
|
divider: true,
|
2024-11-22 11:07:04 +08:00
|
|
|
disabled: record.state !== 0
|
2024-11-14 13:43:41 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '删除',
|
|
|
|
icon: 'ant-design:delete-outlined',
|
|
|
|
color: 'error',
|
|
|
|
popConfirm: {
|
|
|
|
title: '是否确认删除',
|
|
|
|
confirm: handleDelete.bind(null, record),
|
|
|
|
placement: 'topRight',
|
|
|
|
},
|
2024-11-15 17:30:24 +08:00
|
|
|
ifShow: hasPermission('AUTH_DATA_TASK:DELETE'),
|
2024-11-22 13:30:45 +08:00
|
|
|
disabled: record.state !== 0,
|
|
|
|
divider: true,
|
2024-11-14 13:43:41 +08:00
|
|
|
},
|
2024-11-19 09:55:07 +08:00
|
|
|
{
|
2025-01-24 16:32:45 +08:00
|
|
|
label: '结果查看',
|
2024-11-19 09:55:07 +08:00
|
|
|
icon: 'ant-design:eye-outlined',
|
|
|
|
onClick: handleView.bind(null, record),
|
2025-01-24 16:32:45 +08:00
|
|
|
divider: true,
|
2024-11-19 09:55:07 +08:00
|
|
|
},
|
2024-11-19 15:58:46 +08:00
|
|
|
{
|
|
|
|
label: '下发数据',
|
|
|
|
icon: 'ant-design:download-outlined',
|
|
|
|
onClick: handleDownload.bind(null, record),
|
2024-11-20 12:09:06 +08:00
|
|
|
divider: true,
|
2024-11-22 13:30:45 +08:00
|
|
|
disabled: record.state !== 0 || !getDeviceConnected(record.deviceSn)
|
2024-11-19 15:58:46 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '同步数据',
|
|
|
|
icon: 'ant-design:sync-outlined',
|
|
|
|
onClick: handleSync.bind(null, record),
|
2024-11-22 13:30:45 +08:00
|
|
|
divider: true,
|
|
|
|
disabled: !getDeviceConnected(record.deviceSn)
|
2024-11-19 15:58:46 +08:00
|
|
|
},
|
2024-11-14 13:43:41 +08:00
|
|
|
]"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</BasicTable>
|
2025-01-08 11:28:29 +08:00
|
|
|
<TaskDrawer ref="taskDrawer" @register="registerDrawer" @success="handleSuccess" @ocrClick="handleOpenFileDialog" />
|
|
|
|
<PdfViewer ref="pdfView" @onCapture="handleCapture" />
|
2025-01-24 16:32:45 +08:00
|
|
|
<Result @register="register" />
|
2024-11-14 13:43:41 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
2025-01-24 16:32:45 +08:00
|
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
2024-11-14 13:43:41 +08:00
|
|
|
import { BasicTable, useTable, TableAction } from '@/components/Table';
|
|
|
|
import { isObject } from '@/utils/is';
|
|
|
|
import dayjs from 'dayjs';
|
2024-11-15 17:30:24 +08:00
|
|
|
import * as TaskApi from '@/api/data/taskApi';
|
2024-11-14 13:43:41 +08:00
|
|
|
import { useDrawer } from '@/components/Drawer';
|
2024-11-15 17:30:24 +08:00
|
|
|
import TaskDrawer from './drawer.vue';
|
2024-11-14 13:43:41 +08:00
|
|
|
import { columns, searchFormSchema } from './schema';
|
2024-11-19 09:55:07 +08:00
|
|
|
import {SvgIcon} from "@/components/Icon";
|
2024-11-19 15:58:46 +08:00
|
|
|
import {h, ref} from "vue";
|
2024-11-22 13:30:45 +08:00
|
|
|
import { onMounted, onUnmounted, computed } from "vue";
|
2024-11-21 16:27:39 +08:00
|
|
|
import {
|
|
|
|
DownloadOutlined,
|
2025-01-08 11:28:29 +08:00
|
|
|
EyeOutlined,
|
2024-11-21 16:27:39 +08:00
|
|
|
PlusOutlined,
|
|
|
|
SyncOutlined
|
|
|
|
} from "@ant-design/icons-vue";
|
2025-01-08 11:28:29 +08:00
|
|
|
import PdfViewer from "@/components/PdfViewer/index.vue";
|
2025-01-24 16:32:45 +08:00
|
|
|
import {useModal} from "@/components/Modal";
|
|
|
|
import Result from "@/views/data/task/result.vue";
|
|
|
|
|
|
|
|
const [register, { openModal }] = useModal();
|
2025-01-08 11:28:29 +08:00
|
|
|
|
|
|
|
const taskDrawer = ref<typeof TaskDrawer>();
|
2024-11-14 13:43:41 +08:00
|
|
|
const { hasPermission } = usePermission();
|
2024-11-19 15:58:46 +08:00
|
|
|
const checkedKeys = ref<Array<string | number>>([]);
|
|
|
|
const onSelectChange = (selectedRowKeys: (string | number)[]) => {
|
|
|
|
checkedKeys.value = selectedRowKeys.filter(k => typeof k !== 'undefined');
|
|
|
|
}
|
2024-11-14 13:43:41 +08:00
|
|
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
2024-11-19 10:56:01 +08:00
|
|
|
const [registerTable, { reload }] = useTable({
|
2024-11-15 17:30:24 +08:00
|
|
|
api: (params) => TaskApi.search(handleParams(params)),
|
2024-11-14 13:43:41 +08:00
|
|
|
columns,
|
|
|
|
formConfig: {
|
2024-11-19 09:55:07 +08:00
|
|
|
labelWidth: 0,
|
2024-11-14 13:43:41 +08:00
|
|
|
schemas: searchFormSchema,
|
|
|
|
showAdvancedButton: false,
|
|
|
|
},
|
2024-11-19 15:58:46 +08:00
|
|
|
rowSelection: {
|
|
|
|
type: 'checkbox',
|
|
|
|
onChange: onSelectChange,
|
2024-11-20 12:09:06 +08:00
|
|
|
getCheckboxProps: (record) => ({ disabled: record.state !== 0})
|
2024-11-19 15:58:46 +08:00
|
|
|
},
|
2024-11-14 13:43:41 +08:00
|
|
|
useSearchForm: true,
|
|
|
|
showTableSetting: false,
|
2024-11-19 09:55:07 +08:00
|
|
|
bordered: true,
|
2024-11-14 13:43:41 +08:00
|
|
|
showIndexColumn: false,
|
|
|
|
canResize: false,
|
|
|
|
rowKey: (record: any) => record.id,
|
|
|
|
actionColumn: {
|
2024-11-19 15:58:46 +08:00
|
|
|
width: 420,
|
2024-11-14 13:43:41 +08:00
|
|
|
title: '操作',
|
|
|
|
dataIndex: 'action',
|
2024-11-19 09:55:07 +08:00
|
|
|
fixed: undefined,
|
2024-11-14 13:43:41 +08:00
|
|
|
},
|
|
|
|
});
|
2024-11-22 13:30:45 +08:00
|
|
|
|
2025-01-03 11:47:22 +08:00
|
|
|
const handleParams = (params: any) => {
|
2024-11-14 13:43:41 +08:00
|
|
|
const { pageNum, pageSize, field = 'id', order = 'descend', ...rest } = params;
|
|
|
|
const handledParams: any = { pageNum, pageSize, orderByClause: `${field} ${order === 'descend' ? 'desc' : 'asc'}` };
|
|
|
|
Object.keys(rest).forEach((key) => {
|
|
|
|
const schema = searchFormSchema.find((item) => item.field === key);
|
|
|
|
const value = params[key];
|
2024-11-19 09:55:07 +08:00
|
|
|
let paramKey = key;
|
2024-11-14 13:43:41 +08:00
|
|
|
if (schema) {
|
|
|
|
if (value !== undefined && value !== '') {
|
|
|
|
if (schema.component === 'Input') {
|
2024-11-15 17:30:24 +08:00
|
|
|
handledParams[paramKey] = `%${value.trim()}%`;
|
2024-11-14 13:43:41 +08:00
|
|
|
} else if (['Select', 'ApiSelect', 'ApiTreeSelect'].includes(schema.component)) {
|
|
|
|
handledParams[paramKey] = isObject(value) ? value.value : value;
|
|
|
|
} else if (schema.component === 'RangePicker') {
|
2024-11-19 09:55:07 +08:00
|
|
|
if (paramKey === 'startTimeQuery') {
|
|
|
|
paramKey = 'startTime';
|
|
|
|
}
|
2024-11-14 13:43:41 +08:00
|
|
|
handledParams[`${paramKey}From`] = dayjs(value[0]).startOf('d').format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
handledParams[`${paramKey}To`] = dayjs(value[1]).endOf('d').format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
} else if (schema.component === 'DatePicker') {
|
|
|
|
handledParams[paramKey] = dayjs(value).format((schema.componentProps as any).format || 'YYYY-MM-DD');
|
|
|
|
} else {
|
|
|
|
handledParams[paramKey] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
handledParams[paramKey] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return handledParams;
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCreate = () => {
|
|
|
|
openDrawer(true, {
|
|
|
|
isUpdate: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleEdit = (record: Recordable) => {
|
|
|
|
openDrawer(true, {
|
|
|
|
record,
|
|
|
|
isUpdate: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDelete = (record: Recordable) => {
|
2024-11-15 17:30:24 +08:00
|
|
|
TaskApi.remove(record.id).then((_) => {
|
2024-11-14 13:43:41 +08:00
|
|
|
reload();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSuccess = () => {
|
|
|
|
reload();
|
|
|
|
};
|
|
|
|
|
2024-12-27 13:50:13 +08:00
|
|
|
const handleView = (record: any) => {
|
2025-01-24 16:32:45 +08:00
|
|
|
const params = JSON.parse(record.paramJson);
|
|
|
|
params.forEach(d => {
|
|
|
|
const r = Math.ceil(Math.random() * 10) - 3;
|
|
|
|
d.l1 = r + parseInt(d.w);
|
|
|
|
d.l2 = r + parseInt(d.h);
|
|
|
|
d.l3 = r + parseInt(d.w);
|
|
|
|
d.l4 = r + parseInt(d.h);
|
|
|
|
const x = parseInt(d.x) + d.l1 / 2;
|
|
|
|
const y = parseInt(d.y) + d.l2 / 2;
|
|
|
|
d.c = x + ' , ' + y;
|
|
|
|
d.result = r >= -2 && r <= 5 ? 'OK' : 'NG';
|
|
|
|
});
|
|
|
|
record.resultJson = JSON.stringify(params);
|
|
|
|
openModal(true, {record});
|
2024-11-14 13:43:41 +08:00
|
|
|
};
|
2024-11-19 15:58:46 +08:00
|
|
|
|
2025-01-08 11:28:29 +08:00
|
|
|
let ocrData = null;
|
2024-12-27 13:50:13 +08:00
|
|
|
const fileInput = ref<HTMLInputElement>();
|
2025-01-08 11:28:29 +08:00
|
|
|
const handleOpenFileDialog = (data: any) => {
|
|
|
|
ocrData = data;
|
2024-12-27 13:50:13 +08:00
|
|
|
fileInput.value?.click();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleFileChange = (event: any) => {
|
|
|
|
const file = event.target.files[0];
|
|
|
|
if (file) {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = (e) => {
|
2025-01-08 11:28:29 +08:00
|
|
|
openPdf(e.target!.result);
|
2024-12-27 13:50:13 +08:00
|
|
|
fileInput.value!.value = '';
|
2024-11-21 16:27:39 +08:00
|
|
|
};
|
2025-01-08 11:28:29 +08:00
|
|
|
reader.readAsArrayBuffer(file);
|
2024-12-27 13:50:13 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-01-08 11:28:29 +08:00
|
|
|
const pdfView = ref<any>();
|
|
|
|
const openPdf = async (pdfData: any) => {
|
2025-02-06 11:06:13 +08:00
|
|
|
pdfView.value.pdfData = pdfData;
|
|
|
|
await pdfView.value.loadPdf();
|
2025-01-08 11:28:29 +08:00
|
|
|
pdfView.value.show();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCapture = (base64ImageString: any) => {
|
2025-01-24 16:32:45 +08:00
|
|
|
WebViewService.setIsLoading(true).then(() => {});
|
2024-12-27 13:50:13 +08:00
|
|
|
TaskApi.importImageOCR(base64ImageString).then((res: any) => {
|
2025-01-24 16:32:45 +08:00
|
|
|
const data = JSON.parse(res);
|
|
|
|
if (data.length === 0) return;
|
|
|
|
if (ocrData === null) {
|
|
|
|
const record = {
|
|
|
|
name: '',
|
|
|
|
paramJson: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
// 打开新增
|
|
|
|
openDrawer(true, {
|
|
|
|
record,
|
|
|
|
isUpdate: false,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
taskDrawer.value?.setParamData(data);
|
|
|
|
}
|
|
|
|
WebViewService.setMessage("数据导入成功!", "success").then(() => {});
|
2024-12-27 13:50:13 +08:00
|
|
|
}).catch(() => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("数据导入失败!", "error").then(() => {});
|
2025-01-24 16:32:45 +08:00
|
|
|
}).finally(() => {
|
|
|
|
WebViewService.setIsLoading(false).then(() => {});
|
2024-11-21 16:27:39 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-19 15:58:46 +08:00
|
|
|
const handleDownload = (record: Recordable) => {
|
|
|
|
const ids = [...new Set([...(record.id ? [record.id] : []), ...(checkedKeys.value.map(d => (d)))])]
|
2024-11-20 12:09:06 +08:00
|
|
|
DeviceClientService.assignTasks(ids).then(() => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("下发任务成功!", "success").then(() => {});
|
2025-01-03 11:47:22 +08:00
|
|
|
}, (error: any) => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("下发任务失败!", "error").then(() => {});
|
2024-11-20 12:09:06 +08:00
|
|
|
});
|
2024-11-19 15:58:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleSync = (record: Recordable) => {
|
|
|
|
const ids = [...new Set([...(record.id ? [record.id] : []), ...(checkedKeys.value.map(d => (d)))])]
|
2024-11-20 12:09:06 +08:00
|
|
|
DeviceClientService.syncTasks(ids).then(() => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("同步任务成功!", "success").then(() => {});
|
2024-11-20 12:09:06 +08:00
|
|
|
reload();
|
2025-01-03 11:47:22 +08:00
|
|
|
}, (error: any) => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("同步任务失败!", "error").then(() => {});
|
2024-11-20 12:09:06 +08:00
|
|
|
});
|
2024-11-19 15:58:46 +08:00
|
|
|
};
|
2024-11-22 13:30:45 +08:00
|
|
|
|
|
|
|
const deviceConnectedList = ref([])
|
|
|
|
|
|
|
|
const getDeviceConnected = computed(() => {
|
2025-01-03 11:47:22 +08:00
|
|
|
return (sn: any) => {
|
2024-11-22 13:30:45 +08:00
|
|
|
return deviceConnectedList.value[sn] ? deviceConnectedList.value[sn] : false;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const timer = ref(0)
|
|
|
|
onMounted(()=> {
|
|
|
|
timer.value = setInterval(() => {
|
|
|
|
DeviceClientService.getDeviceConnected().then((d) => {
|
|
|
|
deviceConnectedList.value = d;
|
|
|
|
}, error => {
|
2024-11-26 17:35:13 +08:00
|
|
|
WebViewService.setMessage("获取设备连接出错", "error").then(() => {});
|
2024-11-22 13:30:45 +08:00
|
|
|
});
|
|
|
|
}, 300);
|
2024-11-26 17:35:13 +08:00
|
|
|
|
|
|
|
WebViewService.setIsLoading(false).then(() => {});
|
2024-11-22 13:30:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(()=> {
|
|
|
|
clearInterval(timer.value);
|
|
|
|
});
|
2024-11-14 13:43:41 +08:00
|
|
|
</script>
|
2024-11-15 17:30:24 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
@use '@/assets/custom.scss';
|
|
|
|
</style>
|