detect-embeded/src/views/data/task/drawer.vue

282 lines
7.5 KiB
Vue
Raw Normal View History

2024-11-14 13:43:41 +08:00
<template>
2025-04-21 13:02:10 +08:00
<BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="960px" @ok="handleSubmit">
2025-01-08 11:28:29 +08:00
<BasicForm @register="registerForm" />
2024-12-27 13:50:13 +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-12-27 13:50:13 +08:00
<div style="width: 5px" />
<a-button type="primary" :icon="h(EyeOutlined)" @click="handleOpenFileDialog">OCR识别</a-button>
<div style="width: 5px" />
2025-04-23 17:00:27 +08:00
<Popconfirm
title="确定要清空预埋件列表吗?"
ok-text="确定"
cancel-text="取消"
@confirm="handleDeleteAll"
>
<a-button type="primary" :icon="h(MinusOutlined)">清空列表</a-button>
</Popconfirm>
<div style="width: 5px" />
2024-12-27 13:50:13 +08:00
</template>
<template #bodyCell="{ column, record }">
2025-04-23 17:00:27 +08:00
<template v-if="column.dataIndex === 'x'">
<span v-if="(getHasManyMinus('x') && Number(record.x) >= 0) || !(getHasManyMinus('x') && Number(record.x) < 0)" style="color: red">{{ record.x }}</span>
<span v-else style="color: white">{{ record.x }}</span>
</template>
<template v-if="column.dataIndex === 'center'">
<span v-if="(getHasManyMinus('center') && Number(record.center) >= 0) || !(getHasManyMinus('center') && Number(record.center) < 0)" style="color: red">{{ record.center }}</span>
<span v-else style="color: white">{{ record.center }}</span>
</template>
<template v-if="column.dataIndex === 'w'">
<span v-if="record.w !== record.h" style="color: red">{{ record.w }}</span>
<span v-else style="color: white">{{ record.w }}</span>
</template>
<template v-if="column.dataIndex === 'h'">
<span v-if="record.w !== record.h" style="color: red">{{ record.h }}</span>
<span v-else style="color: white">{{ record.h }}</span>
</template>
2024-12-27 13:50:13 +08:00
<template v-if="column.dataIndex === 'action'">
<TableAction
:actions="[
{
label: '编辑',
icon: 'clarity:note-edit-line',
onClick: handleEdit.bind(null, record),
divider: true,
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
placement: 'topRight',
},
divider: true,
},
]"
/>
</template>
</template>
</BasicTable>
2025-01-03 11:19:45 +08:00
<Modal @register="register" @success="updateParamData" />
2024-11-14 13:43:41 +08:00
</BasicDrawer>
</template>
<script lang="ts" setup>
2024-12-27 13:50:13 +08:00
import {defineEmits, ref, computed, unref, h} from 'vue';
import { BasicForm, useForm } from '@/components/Form/index';
import { formSchema } from './schema';
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import * as TaskApi from '@/api/data/taskApi';
import { BasicTable, useTable, TableAction } from '@/components/Table';
2025-04-23 17:00:27 +08:00
import { EyeOutlined, PlusOutlined, MinusOutlined } from "@ant-design/icons-vue";
import { Popconfirm } from 'ant-design-vue';
2024-12-27 13:50:13 +08:00
import Modal from "@/views/data/task/modal.vue";
import { useModal } from '/@/components/Modal';
const [register, { openModal }] = useModal();
const columns = [
2025-04-21 13:02:10 +08:00
{
title: '序号',
2025-04-23 14:49:49 +08:00
dataIndex: 'sn',
key: 'sn',
2025-04-21 13:02:10 +08:00
width: '50px',
2025-04-23 14:49:49 +08:00
// customRender: ({ index }) => `${index + 1}`,
2025-04-21 13:02:10 +08:00
},
2024-12-27 13:50:13 +08:00
{
title: '预埋件编号',
dataIndex: 'code',
key: 'code',
},
{
title: '类型',
dataIndex: 'type',
key: 'type',
},
{
title: 'X(mm)',
dataIndex: 'x',
key: 'x',
2025-04-21 13:02:10 +08:00
width: '72px',
2024-12-27 13:50:13 +08:00
},
{
title: 'Y(mm)',
dataIndex: 'y',
key: 'y',
2025-04-21 13:02:10 +08:00
width: '72px',
2024-12-27 13:50:13 +08:00
},
{
title: 'w(mm)',
dataIndex: 'w',
key: 'w',
2025-04-21 13:02:10 +08:00
width: '72px',
2024-12-27 13:50:13 +08:00
},
{
title: 'h(mm)',
dataIndex: 'h',
key: 'h',
2025-04-21 13:02:10 +08:00
width: '72px',
2024-12-27 13:50:13 +08:00
},
2025-02-14 11:08:21 +08:00
{
title: '中心点(m)',
dataIndex: 'center',
key: 'center',
width: '80px',
},
2024-12-27 13:50:13 +08:00
];
2025-01-03 11:19:45 +08:00
const paramData = ref<any>([]);
2024-11-14 13:43:41 +08:00
2025-01-08 11:28:29 +08:00
const emit = defineEmits(['success', 'register', 'ocrClick']);
2024-12-27 13:50:13 +08:00
const isUpdate = ref(true);
const entity = ref();
2024-11-14 13:43:41 +08:00
2025-01-08 11:28:29 +08:00
const [registerForm, { resetFields, setFieldsValue, validate, getFieldsValue }] = useForm({
2024-12-27 13:50:13 +08:00
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
});
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
await resetFields();
setDrawerProps({ confirmLoading: false });
isUpdate.value = !!data?.isUpdate;
entity.value = data?.record;
2025-01-03 11:19:45 +08:00
paramData.value = [];
const items = entity.value && entity.value.paramJson ? JSON.parse(entity.value.paramJson) : [];
2025-04-23 15:24:05 +08:00
items.forEach((d: any, index: number) => {
if (Object.keys(d).includes('sn')) {
paramData.value.push({...d});
} else {
paramData.value.push({ sn: (index + 1) + '', ...d});
}
2025-01-03 11:19:45 +08:00
});
2024-12-27 13:50:13 +08:00
await setFieldsValue({
...data.record,
2024-11-14 13:43:41 +08:00
});
2024-12-27 13:50:13 +08:00
});
2025-01-08 11:28:29 +08:00
const setParamData = (items: any) => {
2025-04-21 13:02:10 +08:00
if (!paramData.value)
paramData.value = [];
2025-04-23 14:49:49 +08:00
items.forEach((d: any) => {
2025-04-21 13:02:10 +08:00
const items = paramData.value.filter((p: any) => p.code === d.code);
if (items.length === 0) {
2025-04-23 14:49:49 +08:00
paramData.value.push({...d});
}
else {
items[0] = {...d};
2025-04-21 13:02:10 +08:00
}
2025-01-08 11:28:29 +08:00
});
};
2024-12-27 13:50:13 +08:00
const [registerTable] = useTable({
title: '预埋件列表',
columns,
dataSource: paramData,
useSearchForm: false,
showTableSetting: false,
bordered: true,
showIndexColumn: false,
canResize: false,
pagination: false,
rowKey: (record: any) => record.code,
actionColumn: {
2025-02-18 17:18:44 +08:00
width: 140,
2024-12-27 13:50:13 +08:00
title: '操作',
dataIndex: 'action',
fixed: undefined,
},
});
const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
2024-11-14 13:43:41 +08:00
2024-12-27 13:50:13 +08:00
async function handleSubmit() {
2025-01-08 11:28:29 +08:00
const values = await validate();
setDrawerProps({confirmLoading: true});
const {
...rest
} = values;
const action = !unref(isUpdate) ? TaskApi.add : TaskApi.update;
const data = !unref(isUpdate)
? {
...rest,
}
: Object.assign({},
{
...unref(entity),
...rest,
},
);
let p: any = [];
paramData.value.forEach((d: any) => {
delete d.index;
p.push(d);
});
data.paramJson = JSON.stringify(p);
await action(data);
closeDrawer();
emit('success');
setDrawerProps({confirmLoading: false});
2025-01-03 11:19:45 +08:00
}
2024-11-14 13:43:41 +08:00
2024-12-27 13:50:13 +08:00
const handleCreate = () => {
openModal(true, { isUpdate: false });
};
2025-01-03 11:19:45 +08:00
const handleEdit = (record: Recordable, index: number) => {
openModal(true, { record, isUpdate: true });
2024-12-27 13:50:13 +08:00
};
2024-11-14 13:43:41 +08:00
2024-12-27 13:50:13 +08:00
const handleDelete = (record: Recordable) => {
2025-04-23 14:49:49 +08:00
paramData.value = paramData.value.filter((d: any) => d.code !== record.code);
2024-12-27 13:50:13 +08:00
};
2024-11-14 13:43:41 +08:00
2024-12-27 13:50:13 +08:00
const handleOpenFileDialog = () => {
2025-01-08 11:28:29 +08:00
const rest = getFieldsValue();
const data = !unref(isUpdate)
? {
...rest,
}
: Object.assign({},
{
...unref(entity),
...rest,
},
);
emit("ocrClick", data);
2024-12-27 13:50:13 +08:00
};
2025-04-23 17:00:27 +08:00
const handleDeleteAll = (e: MouseEvent) => {
paramData.value = [];
};
2025-01-08 11:28:29 +08:00
const updateParamData = async (data: any) => {
2025-04-23 14:49:49 +08:00
paramData.value.forEach((d: any, index: number) => {
if (d["code"] === data["code"]) {
paramData.value[index] = { ...data };
}
});
2025-01-03 11:19:45 +08:00
}
2025-01-08 11:28:29 +08:00
2025-04-23 17:00:27 +08:00
const getHasManyMinus = computed(() => {
return (field: any) => {
let c = 0
paramData.value.forEach((d: any) => {
if (Number(d[field]) < 0) {
c += 1;
}
});
return paramData.value.length - c < c;
};
});
2025-01-08 11:28:29 +08:00
defineExpose({
setParamData
});
2024-11-14 13:43:41 +08:00
</script>
2024-11-19 09:55:07 +08:00
<style lang="scss" scoped>
@use '@/assets/custom.scss';
</style>