refactor(mes/wm/barcode): 清理 TODO @AI、简化 onBizChange、对齐勾选写法

- 删除 data.ts / config/data.ts / index.vue 里残留的 TODO @AI 注释
- applyBizSelected 改名 syncBizDetail(对齐 mes/qc/ipqc 的 syncUnqualified),
  函数内置 formApi 空判断,去掉中间变量 onBizChange,14 处 onChange 直接调用
- config/data.ts 的 dependencies 单行展开为多行
- index.vue 勾选写法对齐 system/user:records.map((item) => item.id!)
pull/350/head
YunaiV 2026-05-29 22:13:57 +08:00
parent b2ccdf80b2
commit a8d60580be
6 changed files with 87 additions and 83 deletions

View File

@ -5,14 +5,16 @@ import { getDictOptions } from '@vben/hooks';
import { z } from '#/adapter/form';
// TODO @AI这里的代码风格不对
/** 表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: { triggerFields: [''], show: () => false },
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'format',
@ -35,8 +37,7 @@ export function useFormSchema(): VbenFormSchema[] {
dependencies: {
triggerFields: ['id'],
componentProps: (values) => ({
// 编辑时业务类型不允许变更 TODO @AI这种简单的注释可以考虑放到 disabled 后面;写到 style 里;
disabled: !!values.id,
disabled: !!values.id, // 编辑时业务类型不允许变更
}),
},
rules: 'required',

View File

@ -28,7 +28,13 @@ import {
} from './../warehouse/components';
/** 业务对象选中后回填业务编码、业务名称、条码内容 */
async function applyBizSelected(formApi: VbenFormApi, item: any) {
async function syncBizDetail(
formApi: undefined | VbenFormApi,
item: any,
) {
if (!formApi) {
return;
}
const values = await formApi.getValues();
const bizType = values.bizType as number | undefined;
if (!item) {
@ -61,13 +67,6 @@ async function applyBizSelected(formApi: VbenFormApi, item: any) {
/** 新增/修改条码的表单 */
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
// TODO @AI是不是可以去掉 onBizChange直接搞个 handleBizTypeChange 函数?
const onBizChange = (item: any) => {
if (formApi) {
void applyBizSelected(formApi, item);
}
};
return [
{
fieldName: 'bizType',
@ -96,7 +95,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '仓库',
component: markRaw(WmWarehouseSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -133,7 +132,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
componentProps: (values) => ({
placeholder: '请选择库区',
warehouseId: values.locationWarehouseId,
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
}),
},
rules: 'required',
@ -188,7 +187,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
componentProps: (values) => ({
placeholder: '请选择库位',
locationId: values.areaLocationId,
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
}),
},
rules: 'required',
@ -198,7 +197,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工单',
component: markRaw(ProWorkOrderSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -211,7 +210,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '设备',
component: markRaw(DvMachinerySelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -224,7 +223,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '产品物料',
component: markRaw(MdItemSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -237,7 +236,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '供应商',
component: markRaw(MdVendorSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -250,7 +249,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工作站',
component: markRaw(MdWorkstationSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -263,7 +262,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '车间',
component: markRaw(MdWorkshopSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -276,7 +275,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '客户',
component: markRaw(MdClientSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -289,7 +288,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工具',
component: markRaw(TmToolSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -302,7 +301,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '库存',
component: markRaw(WmMaterialStockSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],

View File

@ -31,18 +31,14 @@ const [FormModal, formModalApi] = useVbenModal({
const barcodeDetailRef = ref<InstanceType<typeof BarcodeDetail>>();
// TODO @AI checkedIds handleRowCheckboxChange
// TODO @AI system user index
/** 已选条码 ID */
const checkedIds = ref<number[]>([]);
/** 处理勾选变化 */
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: MesWmBarcodeApi.Barcode[];
}) {
checkedIds.value = records.map((row) => row.id!).filter(Boolean);
checkedIds.value = records.map((item) => item.id!);
}
/** 刷新表格 */

View File

@ -1,5 +1,4 @@
<script lang="ts" setup>
// TODO @AI system user index.vue
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmMaterialStockApi } from '#/api/mes/wm/materialstock';
@ -8,7 +7,7 @@ import { ref } from 'vue';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message } from 'ant-design-vue';
import { Button, Card, message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@ -27,25 +26,55 @@ const [AreaModal, areaModalApi] = useVbenModal({
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function handleExport() {
const data = await exportMaterialStock({
...(await gridApi.formApi.getValues()),
itemTypeId: searchItemTypeId.value,
});
downloadFileFromBlobPart({ fileName: '库存台账.xls', source: data });
}
/** 选择物料分类 */
const searchItemTypeId = ref<number | undefined>(undefined);
function handleTypeNodeClick(row: undefined | { id?: number }) {
searchItemTypeId.value = row?.id;
handleRefresh();
}
/** 打开库位详情弹窗 */
function handleOpenAreaDetail(row: MesWmMaterialStockApi.MaterialStock) {
if (!row.areaId) {
return;
}
areaModalApi.setData({ formType: 'detail', id: row.areaId }).open();
}
/** 处理冻结状态切换 */
async function handleFrozenChange(row: MesWmMaterialStockApi.MaterialStock) {
async function handleFrozenChange(
row: MesWmMaterialStockApi.MaterialStock,
): Promise<boolean | undefined> {
const text = row.frozen ? '冻结' : '解冻';
try {
await confirm(`确认要"${text}"该库存记录吗?`);
} catch {
return false;
}
//
await updateMaterialStockFrozen({
id: row.id!,
frozen: row.frozen!,
});
//
message.success(`${text}成功`);
return true;
}
/** 已选物料分类 */
const searchItemTypeId = ref<number>();
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@ -60,8 +89,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
return await getMaterialStockPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
itemTypeId: searchItemTypeId.value,
...formValues,
itemTypeId: searchItemTypeId.value,
});
},
},
@ -76,29 +105,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
} as VxeTableGridOptions<MesWmMaterialStockApi.MaterialStock>,
});
/** 物料分类树节点点击 */
function handleTypeNodeClick(row: undefined | { id?: number }) {
searchItemTypeId.value = row?.id;
gridApi.query();
}
/** 打开库位详情弹窗 */
function handleOpenAreaDetail(row: MesWmMaterialStockApi.MaterialStock) {
if (!row.areaId) {
return;
}
areaModalApi.setData({ formType: 'detail', id: row.areaId }).open();
}
/** 导出表格 */
async function handleExport() {
const data = await exportMaterialStock({
...(await gridApi.formApi.getValues()),
itemTypeId: searchItemTypeId.value,
});
downloadFileFromBlobPart({ fileName: '库存台账.xls', source: data });
}
</script>
<template>
@ -112,10 +118,12 @@ async function handleExport() {
<AreaModal />
<div class="flex h-full gap-3">
<div class="bg-card w-1/6 rounded p-3">
<div class="flex h-full w-full">
<!-- 左侧物料分类树 -->
<Card class="mr-4 h-full w-1/6">
<MdItemTypeTree @node-click="handleTypeNodeClick" />
</div>
</Card>
<!-- 右侧库存台账列表 -->
<div class="w-5/6">
<Grid table-title="">
<template #toolbar-tools>

View File

@ -28,7 +28,13 @@ import {
} from './../warehouse/components';
/** 业务对象选中后回填业务编码、业务名称、条码内容 */
async function applyBizSelected(formApi: VbenFormApi, item: any) {
async function syncBizDetail(
formApi: undefined | VbenFormApi,
item: any,
) {
if (!formApi) {
return;
}
const values = await formApi.getValues();
const bizType = values.bizType as number | undefined;
if (!item) {
@ -61,12 +67,6 @@ async function applyBizSelected(formApi: VbenFormApi, item: any) {
/** 新增/修改条码的表单 */
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
const onBizChange = (item: any) => {
if (formApi) {
void applyBizSelected(formApi, item);
}
};
return [
{
fieldName: 'bizType',
@ -95,7 +95,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '仓库',
component: markRaw(WmWarehouseSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -130,7 +130,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
triggerFields: ['bizType', 'locationWarehouseId'],
show: (values) => values.bizType === BarcodeBizTypeEnum.LOCATION,
componentProps: (values) => ({
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
placeholder: '请选择库区',
warehouseId: values.locationWarehouseId,
}),
@ -186,7 +186,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
show: (values) => values.bizType === BarcodeBizTypeEnum.AREA,
componentProps: (values) => ({
locationId: values.areaLocationId,
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
placeholder: '请选择库位',
}),
},
@ -197,7 +197,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工单',
component: markRaw(ProWorkOrderSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -210,7 +210,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '设备',
component: markRaw(DvMachinerySelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -223,7 +223,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '产品物料',
component: markRaw(MdItemSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -236,7 +236,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '供应商',
component: markRaw(MdVendorSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -249,7 +249,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工作站',
component: markRaw(MdWorkstationSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -262,7 +262,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '车间',
component: markRaw(MdWorkshopSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -275,7 +275,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '客户',
component: markRaw(MdClientSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -288,7 +288,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '工具',
component: markRaw(TmToolSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],
@ -301,7 +301,7 @@ export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
label: '库存',
component: markRaw(WmMaterialStockSelect),
componentProps: {
onChange: onBizChange,
onChange: (item: any) => syncBizDetail(formApi, item),
},
dependencies: {
triggerFields: ['bizType'],

View File

@ -40,7 +40,7 @@ function handleRowCheckboxChange({
}: {
records: MesWmBarcodeApi.Barcode[];
}) {
checkedIds.value = records.map((row) => row.id!).filter(Boolean);
checkedIds.value = records.map((item) => item.id!);
}
/** 刷新表格 */