listpro 传操作宽度 opWidth

This commit is contained in:
wangwenchen 2024-05-17 14:39:01 +08:00
parent 97cae3d9ac
commit 8cebbe36b3
7 changed files with 36 additions and 28 deletions

View File

@ -21,6 +21,7 @@ export default function Render(props: WebComponentProps<ED, keyof ED, false, {
size?: 'large' | 'middle' | 'small';
scroll?: TableProps<RowWithActions<ED, keyof ED>>['scroll'];
locale?: TableProps<RowWithActions<ED, keyof ED>>['locale'];
opWidth?: number;
}, {
getColor: (attr: string, value: any) => `#${string}` | undefined;
}>): React.JSX.Element;

View File

@ -9,7 +9,7 @@ import { TableContext } from '../listPro';
export default function Render(props) {
const { methods, data: oakData } = props;
const { t, getColor } = methods;
const { loading, entity, schema, extraActions, data, disabledOp = false, tablePagination, onAction, rowSelection, attributes, i18n, hideHeader, disableSerialNumber, judgeAttributes, size = 'large', scroll, locale, } = oakData;
const { loading, entity, schema, extraActions, data, disabledOp = false, tablePagination, onAction, rowSelection, attributes, i18n, hideHeader, disableSerialNumber, judgeAttributes, size = 'large', scroll, locale,opWidth } = oakData;
const [tableColumns, setTableColumns] = useState([]);
const { tableAttributes, setSchema } = useContext(TableContext);
// 为了i18更新时能够重新渲染
@ -97,7 +97,7 @@ export default function Render(props) {
align: 'left',
title: '操作',
key: 'operation',
width: 140,
width: opWidth || 140,
render: (value, row) => {
const oakActions = row?.['#oakLegalActions'];
let extraActions2;

View File

@ -22,6 +22,7 @@ type Props<ED2 extends ED, T extends keyof ED2> = {
size?: 'large' | 'middle' | 'small';
scroll?: TableProps<RowWithActions<ED2, T>>['scroll'];
locale?: TableProps<RowWithActions<ED2, T>>['locale'];
opWidth?: number;
};
export type TableAttributeType = {
attribute: OakAbsAttrJudgeDef;

View File

@ -14,7 +14,7 @@ export const TableContext = createContext({
onReset: undefined,
});
const ProList = (props) => {
const { buttonGroup, entity, extraActions, onAction, disabledOp, attributes, data, loading, tablePagination, rowSelection, onReload, disableSerialNumber, title, hideDefaultButtons = false, extraContent, size = 'large', scroll, locale, } = props;
const { buttonGroup, entity, extraActions, onAction, disabledOp, attributes, data, loading, tablePagination, rowSelection, onReload, disableSerialNumber, title, hideDefaultButtons = false, extraContent, size = 'large', scroll, locale,opWidth } = props;
const [tableAttributes, setTableAttributes] = useState([]);
const [schema, setSchema] = useState(undefined);
const width = useWidth();
@ -45,7 +45,7 @@ const ProList = (props) => {
<div className={Style.container}>
{!isMobile && !hideDefaultButtons && (<ToolBar title={title} extraContent={extraContent} buttonGroup={buttonGroup} reload={onReload}/>)}
{isMobile && <ButtonGroup items={buttonGroup}/>}
<List entity={entity} extraActions={extraActions} onAction={onAction} disabledOp={disabledOp} attributes={attributes} scroll={scroll} locale={locale} data={data} loading={loading} size={size} tablePagination={tablePagination} rowSelection={rowSelection} disableSerialNumber={disableSerialNumber}/>
<List entity={entity} extraActions={extraActions} onAction={onAction} disabledOp={disabledOp} attributes={attributes} scroll={scroll} locale={locale} data={data} loading={loading} size={size} tablePagination={tablePagination} rowSelection={rowSelection} disableSerialNumber={disableSerialNumber} opWidth={opWidth} />
</div>
</TableContext.Provider>);
};

View File

@ -11,7 +11,7 @@ export default OakComponent({
extraActions: [] as
| OakExtraActionProps[]
| ((row: RowWithActions<ED, keyof ED>) => OakExtraActionProps[]),
onAction: (() => {}) as Function,
onAction: (() => { }) as Function,
disabledOp: false,
attributes: [] as OakAbsAttrDef[],
data: [] as RowWithActions<ED, keyof ED>[],
@ -31,6 +31,7 @@ export default OakComponent({
locale: undefined as
| TableProps<RowWithActions<ED, keyof ED>>['locale']
| undefined,
opWidth: undefined as number | undefined,
},
formData({ props }) {
const { converter } = this.state;
@ -106,8 +107,8 @@ export default OakComponent({
{
entity: T2;
extraActions:
| OakExtraActionProps[]
| ((row: RowWithActions<ED2, T2>) => OakExtraActionProps[]);
| OakExtraActionProps[]
| ((row: RowWithActions<ED2, T2>) => OakExtraActionProps[]);
onAction: onActionFnDef;
disabledOp: boolean;
attributes: OakAbsAttrDef[];

View File

@ -22,8 +22,8 @@ export default function Render(
{
loading: boolean;
extraActions:
| OakExtraActionProps[]
| ((row: RowWithActions<ED, keyof ED>) => OakExtraActionProps[]);
| OakExtraActionProps[]
| ((row: RowWithActions<ED, keyof ED>) => OakExtraActionProps[]);
entity: string;
schema: StorageSchema<ED>;
attributes: OakAbsAttrDef[];
@ -43,6 +43,7 @@ export default function Render(
size?: 'large' | 'middle' | 'small';
scroll?: TableProps<RowWithActions<ED, keyof ED>>['scroll'];
locale?: TableProps<RowWithActions<ED, keyof ED>>['locale'];
opWidth?: number;
},
{
getColor: (attr: string, value: any) => `#${string}` | undefined;
@ -69,6 +70,7 @@ export default function Render(
size = 'large',
scroll,
locale,
opWidth,
} = oakData;
const [tableColumns, setTableColumns] = useState([] as ColumnsType<any>);
const { tableAttributes, setSchema } = useContext(TableContext);
@ -193,7 +195,7 @@ export default function Render(
align: 'left',
title: '操作',
key: 'operation',
width: 140,
width: opWidth || 140,
render: (value: any, row: any) => {
const oakActions = row?.[
'#oakLegalActions'
@ -246,15 +248,15 @@ export default function Render(
dataSource={
!disableSerialNumber
? data?.map((ele, index) => {
if (tablePagination) {
const total = tablePagination.total || 0;
const pageSize = tablePagination.pageSize || 20; //条数
const current = tablePagination.current || 1; //当前页
(ele as any)['#'] =
pageSize * (current - 1) + (index + 1);
}
return ele;
})
if (tablePagination) {
const total = tablePagination.total || 0;
const pageSize = tablePagination.pageSize || 20; //条数
const current = tablePagination.current || 1; //当前页
(ele as any)['#'] =
pageSize * (current - 1) + (index + 1);
}
return ele;
})
: data
}
columns={tableColumns}
@ -263,13 +265,13 @@ export default function Render(
scroll={
data?.length > 0
? Object.assign(
{},
showScroll && {
scrollToFirstRowOnChange: true,
x: 1200,
},
scroll
)
{},
showScroll && {
scrollToFirstRowOnChange: true,
x: 1200,
},
scroll
)
: undefined
}
onRow={(record) => {

View File

@ -25,8 +25,8 @@ type Props<ED2 extends ED, T extends keyof ED2> = {
onReload?: () => void;
entity: T;
extraActions?:
| OakExtraActionProps[]
| ((row: RowWithActions<ED2, T>) => OakExtraActionProps[]);
| OakExtraActionProps[]
| ((row: RowWithActions<ED2, T>) => OakExtraActionProps[]);
onAction?: onActionFnDef;
disabledOp?: boolean;
attributes: OakAbsAttrDef[];
@ -38,6 +38,7 @@ type Props<ED2 extends ED, T extends keyof ED2> = {
size?: 'large' | 'middle' | 'small';
scroll?: TableProps<RowWithActions<ED2, T>>['scroll'];
locale?: TableProps<RowWithActions<ED2, T>>['locale'];
opWidth?: number;
};
export type TableAttributeType = {
@ -85,6 +86,7 @@ const ProList = <ED2 extends ED, T extends keyof ED2>(props: Props<ED2, T>) => {
size = 'large',
scroll,
locale,
opWidth,
} = props;
const [tableAttributes, setTableAttributes] = useState<
@ -151,6 +153,7 @@ const ProList = <ED2 extends ED, T extends keyof ED2>(props: Props<ED2, T>) => {
tablePagination={tablePagination}
rowSelection={rowSelection}
disableSerialNumber={disableSerialNumber}
opWidth={opWidth}
/>
</div>
</TableContext.Provider>