| | |
| | | let unitListPromise: Promise<any[]> | null = null; |
| | | |
| | | /** 将扁平分类列表转为 TreeSelect 所需的树形结构 */ |
| | | function buildCategoryTree(list: any[]): any[] { |
| | | export function buildCategoryTree(list: any[]): any[] { |
| | | const map = new Map<number, any>(); |
| | | const roots: any[] = []; |
| | | for (const item of list) { |
| | |
| | | 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: "ApiTreeSelect", |
| | | component: "TreeSelect", |
| | | fieldName: "categoryId", |
| | | label: "物料分类", |
| | | rules: "selectRequired", |
| | |
| | | placeholder: "请选择物料分类", |
| | | allowClear: true, |
| | | treeDefaultExpandAll: true, |
| | | api: async () => { |
| | | const res = await getItemTypeSimpleList(); |
| | | return buildCategoryTree(res || []); |
| | | }, |
| | | treeData: categoryTreeData, |
| | | fieldNames: { label: 'label', value: 'value', children: 'children' }, |
| | | }, |
| | | }, |
| | | { |