|
|
@ -1,3 +1,4 @@ |
|
|
|
import { useTranslation } from '@/i18n.ts' |
|
|
|
import { EditableFormInstance, EditableProTable } from '@ant-design/pro-components' |
|
|
|
import { useMemo, useRef, useState } from 'react' |
|
|
|
import { IDataProps } from '@/types' |
|
|
@ -10,13 +11,14 @@ type DataSourceType = { |
|
|
|
} |
|
|
|
|
|
|
|
const fixRowKey = (data: DataSourceType[]) => { |
|
|
|
return data.map((item, index) => ({ ...item, id: item.id ?? index+1 })) |
|
|
|
return data.map((item, index) => ({ ...item, id: item.id ?? index + 1 })) |
|
|
|
} |
|
|
|
|
|
|
|
const ButtonTable = (props: IDataProps & { |
|
|
|
form: FormInstance |
|
|
|
}) => { |
|
|
|
|
|
|
|
const { t } = useTranslation() |
|
|
|
const { value, onChange } = props |
|
|
|
const editorFormRef = useRef<EditableFormInstance<DataSourceType>>() |
|
|
|
const [ editableKeys, setEditableRowKeys ] = useState<any[]>(() => { |
|
|
@ -34,26 +36,26 @@ const ButtonTable = (props: IDataProps & { |
|
|
|
hideInTable: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '名称', |
|
|
|
title: t('system.menus.form.table.columns.name', '名称'), |
|
|
|
dataIndex: 'label', |
|
|
|
formItemProps: () => { |
|
|
|
return { |
|
|
|
rules: [ { required: true, message: '此项为必填项' } ], |
|
|
|
rules: [ { required: true, message: t('message.required') } ], |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '标识', |
|
|
|
title: t('system.menus.form.table.columns.code', '标识'), |
|
|
|
dataIndex: 'code', |
|
|
|
formItemProps: () => { |
|
|
|
return { |
|
|
|
rules: [ { required: true, message: '此项为必填项' } ], |
|
|
|
rules: [ { required: true, message: t('message.required') } ], |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
title: '操作', |
|
|
|
title: t('system.menus.form.table.columns.option', '操作'), |
|
|
|
valueType: 'option', |
|
|
|
width: 80, |
|
|
|
|
|
|
@ -67,14 +69,14 @@ const ButtonTable = (props: IDataProps & { |
|
|
|
|
|
|
|
<EditableProTable<DataSourceType> |
|
|
|
rowKey="id" |
|
|
|
value={values } |
|
|
|
value={values} |
|
|
|
onChange={onChange} |
|
|
|
editableFormRef={editorFormRef} |
|
|
|
recordCreatorProps={ |
|
|
|
{ |
|
|
|
newRecordType: 'dataSource', |
|
|
|
record: () => { |
|
|
|
return { id: ((value?? []).length + 1) } as DataSourceType |
|
|
|
return { id: ((value ?? []).length + 1) } as DataSourceType |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|