diff --git a/src/components/TableForm/index.ts b/src/components/TableForm/index.ts new file mode 100644 index 000000000..d0456f911 --- /dev/null +++ b/src/components/TableForm/index.ts @@ -0,0 +1,3 @@ +import Annex from './src/Annex.vue' + +export { Annex } diff --git a/src/components/TableForm/src/TableForm.vue b/src/components/TableForm/src/TableForm.vue new file mode 100644 index 000000000..c3584b243 --- /dev/null +++ b/src/components/TableForm/src/TableForm.vue @@ -0,0 +1,120 @@ + + + + + + + diff --git a/src/hooks/web/useCrudSchemas.ts b/src/hooks/web/useCrudSchemas.ts index 458b57ec6..b39d0453f 100644 --- a/src/hooks/web/useCrudSchemas.ts +++ b/src/hooks/web/useCrudSchemas.ts @@ -7,6 +7,7 @@ import { getBoolDictOptions, getDictOptions, getIntDictOptions } from '@/utils/d import { FormSchema } from '@/types/form' import { TableColumn } from '@/types/table' import { DescriptionsSchema } from '@/types/descriptions' +import { TableFormColumn } from '@/types/tableForm' import { ComponentOptions, ComponentProps } from '@/types/components' import { DictTag } from '@/components/DictTag' import { cloneDeep, merge } from 'lodash-es' @@ -20,6 +21,8 @@ export type CrudSchema = Omit & { form?: CrudFormParams // 表单的详细配置 isDetail?: boolean // 是否在详情显示 detail?: CrudDescriptionsParams // 详情的详细配置 + isTableForm?: boolean // 是否在表格嵌套表单显示 + tableForm?: CrudTableFormParams // 表格嵌套表单的详细配置 children?: CrudSchema[] dictType?: string // 字典类型 dictClass?: 'string' | 'number' | 'boolean' // 字典数据类型 string | number | boolean @@ -54,11 +57,16 @@ type CrudDescriptionsParams = { show?: boolean } & Omit +type CrudTableFormParams = { + // 是否显示表单项 + show?: boolean +} & Omit interface AllSchemas { searchSchema: FormSchema[] tableColumns: TableColumn[] formSchema: FormSchema[] detailSchema: DescriptionsSchema[] + tableFormColumns: TableFormColumn[] } const { t } = useI18n() @@ -74,7 +82,8 @@ export const useCrudSchemas = ( searchSchema: [], tableColumns: [], formSchema: [], - detailSchema: [] + detailSchema: [], + tableFormColumns:[] }) const searchSchema = filterSearchSchema(crudSchema, allSchemas) @@ -89,6 +98,8 @@ export const useCrudSchemas = ( const detailSchema = filterDescriptionsSchema(crudSchema) allSchemas.detailSchema = detailSchema + const tableFormColumns= filterTableFormSchema(crudSchema) + allSchemas.tableFormColumns =tableFormColumns || [] return { allSchemas } @@ -187,7 +198,36 @@ const filterTableSchema = (crudSchema: CrudSchema[]): TableColumn[] => { return !!data.field }) } +// 过滤 tableForm 结构 +const filterTableFormSchema = (crudSchema: CrudSchema[]): TableFormColumn[] => { + const tableFormColumns = treeMap(crudSchema, { + conversion: (schema: CrudSchema) => { + if (schema?.isTableForm !== false && schema?.tableForm?.show !== false) { + // add by 芋艿:增加对 dict 字典数据的支持 + if (!schema.formatter && schema.dictType) { + schema.formatter = (_: Recordable, __: TableFormColumn, cellValue: any) => { + return h(DictTag, { + type: schema.dictType!, // ! 表示一定不为空 + value: cellValue + }) + } + } + return { + ...schema.tableForm, + ...schema + } + } + } + }) + // 第一次过滤会有 undefined 所以需要二次过滤 + return filter(tableFormColumns as TableFormColumn[], (data) => { + if (data.children === void 0) { + delete data.children + } + return !!data.field + }) +} // 过滤 form 结构 const filterFormSchema = (crudSchema: CrudSchema[], allSchemas: AllSchemas): FormSchema[] => { const formSchema: FormSchema[] = [] @@ -324,3 +364,11 @@ export const sortTableColumns = (tableColumns: TableColumn[], field: string) => // 添加到开头 tableColumns.unshift(fieldColumn) } +// 将 tableColumns 指定 fields 放到最前面 +export const sortTableFormColumns = (tableFormColumns: TableFormColumn[], field: string) => { + const fieldIndex = tableFormColumns.findIndex((item) => item.field === field) + const fieldColumn = cloneDeep(tableFormColumns[fieldIndex]) + tableFormColumns.splice(fieldIndex, 1) + // 添加到开头 + tableFormColumns.unshift(fieldColumn) +} diff --git a/src/types/tableForm.d.ts b/src/types/tableForm.d.ts new file mode 100644 index 000000000..598deb831 --- /dev/null +++ b/src/types/tableForm.d.ts @@ -0,0 +1,44 @@ +import type { CSSProperties } from 'vue' +import { ColProps, ComponentProps, ComponentName } from '@/types/components' +import type { AxiosPromise } from 'axios' + +export type TableFormSetPropsType = { + field: string + path: string + value: any +} + +export type TableFormValueType = string | number | string[] | number[] | boolean | undefined | null + +export type TableFormItemProps = { + labelWidth?: string | number + required?: boolean + rules?: Recordable + error?: string + showMessage?: boolean + inlineMessage?: boolean + style?: CSSProperties +} + +export type TableFormSchema = { + // 唯一值 + field: string + // 标题 + label?: string + // 提示 + labelMessage?: string + // col组件属性 + colProps?: ColProps + // 表单组件属性,slots对应的是表单组件的插槽,规则:${field}-xxx,具体可以查看element-plus文档 + componentProps?: { slots?: Recordable } & ComponentProps + // formItem组件属性 + formItemProps?: FormItemProps + // 渲染的组件 + component?: ComponentName + // 初始值 + value?: FormValueType + // 是否隐藏 + hidden?: boolean + // 远程加载下拉项 + api?: () => AxiosPromise +} diff --git a/src/utils/disposition/tableColumns.ts b/src/utils/disposition/tableColumns.ts index 8d606d650..76135a18b 100644 --- a/src/utils/disposition/tableColumns.ts +++ b/src/utils/disposition/tableColumns.ts @@ -9,8 +9,12 @@ export const ItemBasic = useCrudSchemas(reactive([ field: 'code', sort: 'custom', table: { - width: 150 - } + width:700 + }, + tableForm:{ + width: 300, + sortable:false + } }, { label: '名称', @@ -18,6 +22,10 @@ export const ItemBasic = useCrudSchemas(reactive([ sort: 'custom', table: { width: 150 + }, + tableForm:{ + width: 300, + sortable:false } }, { @@ -26,7 +34,8 @@ export const ItemBasic = useCrudSchemas(reactive([ sort: 'custom', table: { width: 150 - } + } , + isTableForm:false }, { label: '描述2', @@ -34,7 +43,8 @@ export const ItemBasic = useCrudSchemas(reactive([ sort: 'custom', table: { width: 150 - } + } , + isTableForm:false }, { label: '状态', @@ -49,7 +59,7 @@ export const ItemBasic = useCrudSchemas(reactive([ width: 100 } , form: { - component: 'Select', + component: 'Switch', } }, { @@ -74,7 +84,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 150 - } + } , + isTableForm:false }, { label: '是否标包', @@ -104,7 +115,8 @@ export const ItemBasic = useCrudSchemas(reactive([ }, form: { component: 'Radio', - } + }, + isTableForm:false }, { label: '可制造', @@ -134,7 +146,8 @@ export const ItemBasic = useCrudSchemas(reactive([ } , form: { component: 'Radio', - } + }, + isTableForm:false }, { label: '回收件', @@ -149,7 +162,8 @@ export const ItemBasic = useCrudSchemas(reactive([ }, form: { component: 'Radio', - } + }, + isTableForm:false }, { label: '虚零件', @@ -164,7 +178,8 @@ export const ItemBasic = useCrudSchemas(reactive([ } , form: { component: 'Radio', - } + }, + isTableForm:false }, { label: 'ABC类', @@ -176,7 +191,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '类型', @@ -188,7 +204,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '种类', @@ -200,7 +217,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '分组', @@ -212,7 +230,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '颜色', @@ -224,7 +243,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '配置', @@ -236,7 +256,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 100 - } + } , + isTableForm:false }, { label: '项目', @@ -244,7 +265,8 @@ export const ItemBasic = useCrudSchemas(reactive([ sort: 'custom', table: { width: 100 - } + } , + isTableForm:false }, { label: '质量等级', @@ -256,7 +278,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isTable: true, table: { width: 120 - } + } , + isTableForm:false }, { label: '有效天数', @@ -267,7 +290,8 @@ export const ItemBasic = useCrudSchemas(reactive([ }, form: { component: 'InputNumber', - } + }, + isTableForm:false }, { label: '是否可用', @@ -282,7 +306,8 @@ export const ItemBasic = useCrudSchemas(reactive([ }, form: { component: 'Radio', - } + }, + isTableForm:false }, { label: '生效时间', @@ -320,7 +345,8 @@ export const ItemBasic = useCrudSchemas(reactive([ componentProps: { type: 'datetimerange', } - } + }, + isTableForm:false }, { label: '创建时间', @@ -334,10 +360,11 @@ export const ItemBasic = useCrudSchemas(reactive([ }, table: { width: 120 - } + } , + isTableForm:false }, - { label: '备注', field: 'remark', sort: 'custom', isTable: false }, - { label: '创建者ID', field: 'creator', sort: 'custom', isTable: false, isForm: false }, + { label: '备注', field: 'remark', sort: 'custom', isTable: false,isTableForm:false}, + { label: '创建者ID', field: 'creator', sort: 'custom', isTable: false, isForm: false,isTableForm:false }, { label: '操作', field: 'action', @@ -345,7 +372,8 @@ export const ItemBasic = useCrudSchemas(reactive([ isForm: false , table: { width: 150 - } + }, + isTableForm:false } ])) diff --git a/src/views/wms/itembasic/ItembasicForm.vue b/src/views/wms/itembasic/ItembasicForm.vue index db6c6e656..720ce4568 100644 --- a/src/views/wms/itembasic/ItembasicForm.vue +++ b/src/views/wms/itembasic/ItembasicForm.vue @@ -4,21 +4,21 @@
- + - -