| | |
| | | let unitListCache: any[] | null = null; |
| | | let unitListPromise: Promise<any[]> | null = null; |
| | | |
| | | /** 将扁平分类列表转为 TreeSelect 所需的树形结构 */ |
| | | export function buildCategoryTree(list: any[]): any[] { |
| | | const map = new Map<number, any>(); |
| | | const roots: any[] = []; |
| | | for (const item of list) { |
| | | map.set(item.id, { label: item.name, value: item.id, children: [] }); |
| | | } |
| | | for (const item of list) { |
| | | const node = map.get(item.id)!; |
| | | if (item.parentId && map.has(item.parentId)) { |
| | | map.get(item.parentId)!.children.push(node); |
| | | } else { |
| | | roots.push(node); |
| | | } |
| | | } |
| | | return roots; |
| | | } |
| | | |
| | | /** 获取单位列表(带缓存) */ |
| | | async function getUnitListCached() { |
| | | if (unitListCache) { |
| | |
| | | return unitListPromise; |
| | | } |
| | | |
| | | /** 清除单位列表缓存 */ |
| | | export function clearUnitListCache() { |
| | | unitListCache = null; |
| | | } |
| | | |
| | | /** 新增/修改的表单 */ |
| | | export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] { |
| | | export function useFormSchema(formApi?: VbenFormApi, categoryTreeData: any[] = []): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | component: "Input", |
| | |
| | | rules: "required", |
| | | }, |
| | | { |
| | | component: "ApiSelect", |
| | | component: "TreeSelect", |
| | | fieldName: "categoryId", |
| | | label: "物料分类", |
| | | rules: "selectRequired", |
| | | componentProps: { |
| | | placeholder: "请选择物料分类", |
| | | allowClear: true, |
| | | api: async () => { |
| | | const res = await getItemTypeSimpleList(); |
| | | return res || []; |
| | | }, |
| | | labelField: "name", |
| | | valueField: "id", |
| | | treeDefaultExpandAll: true, |
| | | treeData: categoryTreeData, |
| | | fieldNames: { label: 'label', value: 'value', children: 'children' }, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | fieldName: 'isBatchManaged', |
| | | label: '批次管理', |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | rules: z.boolean().default(false), |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "syncMes", |
| | | label: "同步到 MES", |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | |
| | | }, |
| | | }, |
| | | { |
| | | field: "isBatchManaged", |
| | | title: "批次管理", |
| | | minWidth: 80, |
| | | slots: { default: "isBatchManaged" }, |
| | | }, |
| | | { |
| | | field: "status", |
| | | title: "状态", |
| | | minWidth: 80, |
| | | cellRender: { |
| | | name: "CellDict", |
| | | props: { type: DICT_TYPE.COMMON_STATUS }, |
| | | }, |
| | | }, |
| | | { |
| | | field: "createTime", |
| | | title: "创建时间", |
| | | minWidth: 180, |
| | | formatter: "formatDateTime", |
| | | }, |
| | | { |
| | | field: "isBatchManaged", |
| | | title: "批次管理", |
| | | width: 80, |
| | | fixed: "right", |
| | | slots: { default: "isBatchManaged" }, |
| | | }, |
| | | { |
| | | field: "syncedMes", |
| | | title: "同步状态", |
| | | width: 90, |
| | | fixed: "right", |
| | | slots: { default: "syncedMes" }, |
| | | }, |
| | | { |
| | | field: "status", |
| | | title: "状态", |
| | | width: 80, |
| | | fixed: "right", |
| | | cellRender: { |
| | | name: "CellDict", |
| | | props: { type: DICT_TYPE.COMMON_STATUS }, |
| | | }, |
| | | }, |
| | | { |
| | | title: "操作", |
| | | width: 180, |
| | | fixed: "right", |