This commit is contained in:
njdaoyehu 2025-04-17 18:01:14 +08:00
parent fcb7b463da
commit 8795da1093
4 changed files with 142 additions and 45 deletions

View File

@ -80,6 +80,8 @@
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"dayjs": "^1.11.9", "dayjs": "^1.11.9",
"echarts": "^5.4.2", "echarts": "^5.4.2",
"exceljs": "^4.4.0",
"file-saver": "^2.0.5",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"lodash.get": "^4.4.2", "lodash.get": "^4.4.2",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
@ -109,6 +111,7 @@
"@purge-icons/generated": "^0.9.0", "@purge-icons/generated": "^0.9.0",
"@types/codemirror": "^5.60.8", "@types/codemirror": "^5.60.8",
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.1.1",
"@types/file-saver": "^2.0.7",
"@types/intro.js": "^5.1.1", "@types/intro.js": "^5.1.1",
"@types/lodash-es": "^4.17.7", "@types/lodash-es": "^4.17.7",
"@types/lodash.get": "^4.4.7", "@types/lodash.get": "^4.4.7",

View File

@ -217,38 +217,48 @@
reload(); reload();
}; };
const handleView = (record: any) => { const getCode = (code1: string, code2: string) => {
const hasPt = code1.indexOf("PT") !== -1;
if (hasPt) {
let code = code1.split("PT")[0] + "PT";
for (let i = 0; i < code1.split("PT")[1].length - code2.length; i++) {
code += "0";
}
code += code2;
return code
} else {
return code2
}
};
const getResults = (record: any) => {
const params = JSON.parse(record.paramJson); const params = JSON.parse(record.paramJson);
const result = JSON.parse(record.resultJson); if (record.results === undefined || record.results === null)
if (record.resultJson === undefined || record.resultJson === null) return undefined;
return; const results = JSON.parse(record.results);
result.forEach((items: any) => { params.forEach((param: any) => {
items.forEach((d: any) => { const l = results.filter((d: any) => param["code"] === getCode(param["code"], d["code"]+''));
params[d.code - 1].x1 = d.x1; if (l.length > 0) {
params[d.code - 1].x2 = d.x2; param["x1"] = l[0]["x1"];
params[d.code - 1].x3 = d.x3; param["y1"] = l[0]["y1"];
params[d.code - 1].x4 = d.x4; param["x2"] = l[0]["x2"];
params[d.code - 1].y1 = d.y1; param["y2"] = l[0]["y2"];
params[d.code - 1].y2 = d.y2; param["x3"] = l[0]["x3"];
params[d.code - 1].y3 = d.y3; param["y3"] = l[0]["y3"];
params[d.code - 1].y4 = d.y4; param["x4"] = l[0]["x4"];
params[d.code - 1].w = d.w; param["y4"] = l[0]["y4"];
params[d.code - 1].h = d.h; param["base"] = l[0]["base"];
params[d.code - 1].status = d.status; param["actual_value"] = l[0]["actual_value"];
}) param["status"] = l[0]["status"];
}
}); });
// params.forEach((d) => { return params;
// const r = Math.ceil(Math.random() * 10) - 3; }
// d.l1 = r + parseInt(d.w);
// d.l2 = r + parseInt(d.h); const handleView = (record: any) => {
// d.l3 = r + parseInt(d.w); const results = getResults(record);
// d.l4 = r + parseInt(d.h); if (!results) return;
// const x = parseInt(d.x) + d.l1 / 2; record.resultJson1 = JSON.stringify(results);
// const y = parseInt(d.y) + d.l2 / 2;
// d.c = x + ' , ' + y;
// d.result = r >= -2 && r <= 5 ? 'OK' : 'NG';
// });
record.resultJson1 = JSON.stringify(params);
openModal(true, { record }); openModal(true, { record });
}; };

View File

@ -1,6 +1,15 @@
<template> <template>
<BasicModal v-bind="$attrs" @register="register" :closable="false" :showCancelBtn="false" okText="关闭" showFooter title="任务结果详情" width="1450px" @ok="closeModal"> <BasicModal v-bind="$attrs" @register="register" width="1570px" :closable="false">
<template #title>
<div style="color: #ffffff; font-size: 16px; font-weight: normal;"><FileTextOutlined /> {{title}}</div>
</template>
<template #footer>
<div style="padding-right: 30px;">
<a-button :icon="h(FileExcelOutlined)" @click="handleExport">导出结果(Excel)</a-button>
<a-button :icon="h(CloseOutlined)" @click="closeModal">关闭</a-button>
</div>
</template>
<BasicTable @register="registerTable"> <BasicTable @register="registerTable">
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'status'"> <template v-if="column.dataIndex === 'status'">
@ -14,9 +23,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { BasicModal, useModalInner } from "@/components/Modal"; import { BasicModal, useModalInner } from "@/components/Modal";
import {defineEmits, ref} from "vue"; import {defineEmits, ref, h} from "vue";
import {BasicTable, useTable,} from "@/components/Table"; import {BasicTable, useTable,} from "@/components/Table";
import { CheckOutlined, CloseOutlined } from "@ant-design/icons-vue"; import { CheckOutlined, CloseOutlined, FileExcelOutlined, FileTextOutlined } from "@ant-design/icons-vue";
import ExcelJS from 'exceljs';
import { saveAs } from 'file-saver';
const columns = [ const columns = [
{ {
@ -54,75 +65,89 @@ const columns = [
width: '80px', width: '80px',
}, },
{ {
title: '检测中心(mm)', title: '中心(m)',
dataIndex: 'c', dataIndex: 'center',
key: 'c', key: 'center',
width: '110px', width: '110px',
}, },
{ {
title: 'X1', title: 'X1',
dataIndex: 'x1', dataIndex: 'x1',
key: 'x1', key: 'x1',
width: '40px', width: '70px',
}, },
{ {
title: 'Y1', title: 'Y1',
dataIndex: 'y1', dataIndex: 'y1',
key: 'y1', key: 'y1',
width: '40px', width: '70px',
}, },
{ {
title: 'X2', title: 'X2',
dataIndex: 'x2', dataIndex: 'x2',
key: 'x2', key: 'x2',
width: '40px', width: '70px',
}, },
{ {
title: 'Y2', title: 'Y2',
dataIndex: 'y2', dataIndex: 'y2',
key: 'y2', key: 'y2',
width: '40px', width: '70px',
}, },
{ {
title: 'X3', title: 'X3',
dataIndex: 'x3', dataIndex: 'x3',
key: 'x3', key: 'x3',
width: '40px', width: '70px',
}, },
{ {
title: 'Y3', title: 'Y3',
dataIndex: 'y3', dataIndex: 'y3',
key: 'y3', key: 'y3',
width: '40px', width: '70px',
}, },
{ {
title: 'X4', title: 'X4',
dataIndex: 'x4', dataIndex: 'x4',
key: 'x4', key: 'x4',
width: '40px', width: '70px',
}, },
{ {
title: 'Y4', title: 'Y4',
dataIndex: 'y4', dataIndex: 'y4',
key: 'y4', key: 'y4',
width: '40px', width: '70px',
},
{
title: '标准值',
dataIndex: 'base',
key: 'base',
width: '60px',
},
{
title: '实际值',
dataIndex: 'actual_value',
key: 'actual_value',
width: '70px',
}, },
{ {
title: '结果', title: '结果',
dataIndex: 'status', dataIndex: 'status',
key: 'status', key: 'status',
width: '80px', width: '50px',
}, },
]; ];
const paramData = ref<any>([]); const paramData = ref<any>([]);
const entity = ref(); const entity = ref();
const title = ref("");
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => { const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false }); setModalProps({ confirmLoading: false });
entity.value = data?.record; entity.value = data?.record;
title.value = data?.record.name + " - 任务结果详情";
paramData.value = []; paramData.value = [];
const items = entity.value && entity.value.resultJson ? JSON.parse(entity.value.resultJson1) : []; const items = entity.value && entity.value.resultJson ? JSON.parse(entity.value.resultJson1) : [];
items.forEach((d: any, index: number) => { items.forEach((d: any, index: number) => {
@ -143,6 +168,56 @@ const [registerTable] = useTable({
rowKey: (record: any) => record.code, rowKey: (record: any) => record.code,
}); });
const handleExport = async () => {
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');
//
worksheet.addRow(columns.map((d: any) => (d["title"] || d["key"])));
//
const headerRow = worksheet.getRow(1);
setCellStyle(headerRow, true);
//
paramData.value.forEach((param: any, index: number) => {
let data: any = [];
columns.forEach((d: any) => {
let v = !param[d["key"]] ? "" : param[d["key"]];
if (!!v && v === "good") {
v = "✔"
}
if (!!v && v === "error") {
v = "×"
}
data.push(v);
});
worksheet.addRow(data);
setCellStyle(worksheet.getRow(index + 2));
});
worksheet.getColumn(1).width = 22;
worksheet.getColumn(2).width = 22;
//
const buffer = await workbook.xlsx.writeBuffer();
const blob = new Blob([buffer], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
saveAs(blob, title.value.replaceAll(" ", "") + '.xlsx');
};
const setCellStyle = (row: any, isHeader: boolean = false) => {
row.eachCell((cell: any) => {
cell.fill = {
type: 'pattern',
pattern: 'solid',
fgColor: isHeader ? {argb: 'FFD3D3D3'} : {argb: 'FFFFFFFF'}
};
cell.font = {
bold: isHeader,
color: isHeader ? {argb: 'FF000000'} : {argb: 'ff333333'}
};
cell.alignment = {vertical: 'middle', horizontal: 'center'};
cell.border = {
bottom: {style: 'thin', color: {argb: 'ff000000'}},
right: {style: 'thin', color: {argb: 'ff000000'}},
};
});
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '@/assets/custom.scss'; @use '@/assets/custom.scss';

View File

@ -106,6 +106,15 @@ export const schema = {
table: { table: {
}, },
}, },
{
field: 'results',
label: '结果',
defaultValue: undefined,
form: {
},
table: {
},
},
{ {
field: 'startTimeQuery', field: 'startTimeQuery',
label: '开始时间', label: '开始时间',