From 9c7986d230f83434ead9d4936d93b846870f3cca Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 25 May 2026 23:29:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(mes)=EF=BC=9A=E5=AE=8C=E6=88=90=E2=80=9C?= =?UTF-8?q?=E5=AE=89=E7=81=AF=EF=BC=88pro=5Fandon=EF=BC=89=E2=80=9D?= =?UTF-8?q?=E7=9A=84=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/mes/pro/andon/config/index.ts | 1 - .../src/views/mes/pro/andon/config/data.ts | 111 +++++++ .../modules/{config-form.vue => form.vue} | 22 +- .../modules/{config-modal.vue => list.vue} | 66 ++-- .../src/views/mes/pro/andon/record/data.ts | 301 ++++++------------ .../src/views/mes/pro/andon/record/index.vue | 6 +- .../mes/pro/andon/record/modules/form.vue | 149 ++++----- .../src/api/mes/pro/andon/config/index.ts | 15 +- .../src/views/mes/pro/andon/config/data.ts | 111 +++++++ .../modules/{config-form.vue => form.vue} | 22 +- .../modules/{config-modal.vue => list.vue} | 44 +-- .../src/views/mes/pro/andon/record/data.ts | 298 ++++++----------- .../src/views/mes/pro/andon/record/index.vue | 6 +- .../mes/pro/andon/record/modules/form.vue | 159 +++++---- 14 files changed, 652 insertions(+), 659 deletions(-) create mode 100644 apps/web-antd/src/views/mes/pro/andon/config/data.ts rename apps/web-antd/src/views/mes/pro/andon/config/modules/{config-form.vue => form.vue} (85%) rename apps/web-antd/src/views/mes/pro/andon/config/modules/{config-modal.vue => list.vue} (59%) create mode 100644 apps/web-ele/src/views/mes/pro/andon/config/data.ts rename apps/web-ele/src/views/mes/pro/andon/config/modules/{config-form.vue => form.vue} (85%) rename apps/web-ele/src/views/mes/pro/andon/config/modules/{config-modal.vue => list.vue} (77%) diff --git a/apps/web-antd/src/api/mes/pro/andon/config/index.ts b/apps/web-antd/src/api/mes/pro/andon/config/index.ts index 7a2ac2ad1..d21621877 100644 --- a/apps/web-antd/src/api/mes/pro/andon/config/index.ts +++ b/apps/web-antd/src/api/mes/pro/andon/config/index.ts @@ -9,7 +9,6 @@ export namespace MesProAndonConfigApi { reason?: string; // 呼叫原因 level?: number; // 级别 handlerRoleId?: number; // 处置角色编号 - handlerRoleName?: string; // 处置角色名称(前端通过角色精简列表回显) handlerUserId?: number; // 处置人编号 handlerUserNickname?: string; // 处置人昵称 remark?: string; // 备注 diff --git a/apps/web-antd/src/views/mes/pro/andon/config/data.ts b/apps/web-antd/src/views/mes/pro/andon/config/data.ts new file mode 100644 index 000000000..f8ff65c18 --- /dev/null +++ b/apps/web-antd/src/views/mes/pro/andon/config/data.ts @@ -0,0 +1,111 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; +import type { MesProAndonConfigApi } from '#/api/mes/pro/andon/config'; +import type { SystemRoleApi } from '#/api/system/role'; + +import { DICT_TYPE } from '@vben/constants'; +import { getDictOptions } from '@vben/hooks'; + +import { z } from '#/adapter/form'; +import { getSimpleRoleList } from '#/api/system/role'; +import { getSimpleUserList } from '#/api/system/user'; + +/** 关联数据 */ +let roleList: SystemRoleApi.Role[] = []; +getSimpleRoleList().then((data) => (roleList = data)); + +/** 安灯配置列表的字段 */ +export function useGridColumns(): VxeTableGridOptions['columns'] { + return [ + { field: 'reason', title: '呼叫原因', minWidth: 200 }, + { + field: 'level', + title: '级别', + width: 100, + cellRender: { + name: 'CellDict', + props: { type: DICT_TYPE.MES_PRO_ANDON_LEVEL }, + }, + }, + { + field: 'handlerRoleId', + title: '处置角色', + width: 140, + formatter: ({ cellValue }) => + roleList.find((role) => role.id === cellValue)?.name ?? '', + }, + { field: 'handlerUserNickname', title: '处置人', width: 140 }, + { field: 'remark', title: '备注', minWidth: 160 }, + { + title: '操作', + width: 160, + fixed: 'right', + slots: { default: 'actions' }, + }, + ]; +} + +/** 新增/修改安灯配置的表单 */ +export function useFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'id', + component: 'Input', + dependencies: { triggerFields: [''], show: () => false }, + }, + { + fieldName: 'reason', + label: '呼叫原因', + component: 'Textarea', + componentProps: { + autoSize: { maxRows: 3, minRows: 1 }, + maxLength: 200, + placeholder: '请输入呼叫原因', + }, + rules: z.string().min(1, '呼叫原因不能为空').max(200), + }, + { + fieldName: 'level', + label: '级别', + component: 'Select', + componentProps: { + options: getDictOptions(DICT_TYPE.MES_PRO_ANDON_LEVEL, 'number'), + placeholder: '请选择级别', + }, + rules: 'selectRequired', + }, + { + fieldName: 'handlerRoleId', + label: '处置角色', + component: 'ApiSelect', + componentProps: { + allowClear: true, + api: getSimpleRoleList, + labelField: 'name', + placeholder: '请选择角色(与处置人至少填一个)', + valueField: 'id', + }, + }, + { + fieldName: 'handlerUserId', + label: '处置人', + component: 'ApiSelect', + componentProps: { + allowClear: true, + api: getSimpleUserList, + labelField: 'nickname', + placeholder: '请选择处置人(与角色至少填一个)', + valueField: 'id', + }, + }, + { + fieldName: 'remark', + label: '备注', + component: 'Input', + componentProps: { + maxLength: 100, + placeholder: '请输入备注', + }, + }, + ]; +} diff --git a/apps/web-antd/src/views/mes/pro/andon/config/modules/config-form.vue b/apps/web-antd/src/views/mes/pro/andon/config/modules/form.vue similarity index 85% rename from apps/web-antd/src/views/mes/pro/andon/config/modules/config-form.vue rename to apps/web-antd/src/views/mes/pro/andon/config/modules/form.vue index 46a6a5ed2..e421a4d31 100644 --- a/apps/web-antd/src/views/mes/pro/andon/config/modules/config-form.vue +++ b/apps/web-antd/src/views/mes/pro/andon/config/modules/form.vue @@ -15,25 +15,26 @@ import { } from '#/api/mes/pro/andon/config'; import { $t } from '#/locales'; -import { useConfigFormSchema } from '../../record/data'; +import { useFormSchema } from '../data'; const emit = defineEmits(['success']); const formData = ref(); - -const getTitle = computed(() => - formData.value?.id +const getTitle = computed(() => { + return formData.value?.id ? $t('ui.actionTitle.edit', ['安灯配置']) - : $t('ui.actionTitle.create', ['安灯配置']), -); + : $t('ui.actionTitle.create', ['安灯配置']); +}); const [Form, formApi] = useVbenForm({ commonConfig: { - componentProps: { class: 'w-full' }, + componentProps: { + class: 'w-full', + }, formItemClass: 'col-span-2', labelWidth: 100, }, layout: 'horizontal', - schema: useConfigFormSchema(), + schema: useFormSchema(), showDefaultActions: false, }); @@ -44,6 +45,7 @@ const [Modal, modalApi] = useVbenModal({ return; } modalApi.lock(); + // 提交表单 const data = (await formApi.getValues()) as MesProAndonConfigApi.AndonConfig; if (!data.handlerRoleId && !data.handlerUserId) { @@ -55,6 +57,7 @@ const [Modal, modalApi] = useVbenModal({ await (formData.value?.id ? updateAndonConfig(data) : createAndonConfig(data)); + // 关闭并提示 await modalApi.close(); emit('success'); message.success($t('ui.actionMessage.operationSuccess')); @@ -67,7 +70,7 @@ const [Modal, modalApi] = useVbenModal({ formData.value = undefined; return; } - await formApi.resetForm(); + // 加载数据 const data = modalApi.getData(); if (!data || !data.id) { return; @@ -75,6 +78,7 @@ const [Modal, modalApi] = useVbenModal({ modalApi.lock(); try { formData.value = await getAndonConfig(data.id); + // 设置到 values await formApi.setValues(formData.value); } finally { modalApi.unlock(); diff --git a/apps/web-antd/src/views/mes/pro/andon/config/modules/config-modal.vue b/apps/web-antd/src/views/mes/pro/andon/config/modules/list.vue similarity index 59% rename from apps/web-antd/src/views/mes/pro/andon/config/modules/config-modal.vue rename to apps/web-antd/src/views/mes/pro/andon/config/modules/list.vue index 5b01674b6..0b992e320 100644 --- a/apps/web-antd/src/views/mes/pro/andon/config/modules/config-modal.vue +++ b/apps/web-antd/src/views/mes/pro/andon/config/modules/list.vue @@ -2,8 +2,6 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { MesProAndonConfigApi } from '#/api/mes/pro/andon/config'; -import { ref } from 'vue'; - import { useVbenModal } from '@vben/common-ui'; import { message } from 'ant-design-vue'; @@ -13,67 +11,58 @@ import { deleteAndonConfig, getAndonConfigList, } from '#/api/mes/pro/andon/config'; -import { getSimpleRoleList } from '#/api/system/role'; import { $t } from '#/locales'; -import { useConfigGridColumns } from '../../record/data'; -import ConfigForm from './config-form.vue'; +import { useGridColumns } from '../data'; +import Form from './form.vue'; -const list = ref([]); // 安灯配置列表(已回填处置角色名称) - -const [ConfigFormModal, configFormModalApi] = useVbenModal({ - connectedComponent: ConfigForm, +const [FormModal, formModalApi] = useVbenModal({ + connectedComponent: Form, destroyOnClose: true, }); -// TODO @AI:这个格式,是不是有问题?应该要换行?看看别的模块也是; const [Grid, gridApi] = useVbenVxeGrid({ gridOptions: { autoResize: true, border: true, - columns: useConfigGridColumns(), - data: list.value, + columns: useGridColumns(), minHeight: 320, - pagerConfig: { enabled: false }, - rowConfig: { isHover: true, keyField: 'id' }, + pagerConfig: { + enabled: false, + }, + rowConfig: { + isHover: true, + keyField: 'id', + }, showOverflow: true, - toolbarConfig: { enabled: false }, + toolbarConfig: { + enabled: false, + }, } as VxeTableGridOptions, }); -/** 加载安灯配置列表,并通过角色精简列表回填处置角色名称 */ -// TODO @AI:这里需要 getAndonConfigList、getSimpleRoleList 么?通过 data.ts 里处理,是不是更主流??? +/** 加载安灯配置列表 */ async function getList() { gridApi.setLoading(true); try { - const [configList, roleList] = await Promise.all([ - getAndonConfigList(), - getSimpleRoleList(), - ]); - const roleMap = new Map(roleList.map((role) => [role.id!, role.name!])); - list.value = (configList || []).map((item) => ({ - ...item, - handlerRoleName: item.handlerRoleId - ? roleMap.get(item.handlerRoleId) - : undefined, - })); - gridApi.setGridOptions({ data: list.value }); + const data = (await getAndonConfigList()) || []; + gridApi.setGridOptions({ data }); } finally { gridApi.setLoading(false); } } -/** 新增配置 */ +/** 创建安灯配置 */ function handleCreate() { - configFormModalApi.setData({}).open(); + formModalApi.setData({}).open(); } -/** 编辑配置 */ +/** 编辑安灯配置 */ function handleEdit(row: MesProAndonConfigApi.AndonConfig) { - configFormModalApi.setData({ id: row.id }).open(); + formModalApi.setData({ id: row.id }).open(); } -/** 删除配置 */ +/** 删除安灯配置 */ async function handleDelete(row: MesProAndonConfigApi.AndonConfig) { await deleteAndonConfig(row.id!); message.success($t('ui.actionMessage.deleteSuccess', ['安灯配置'])); @@ -93,8 +82,13 @@ defineExpose({ open: () => modalApi.open() });