@jswork/antd-components 1.0.157 → 1.0.158
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.cjs.js +1 -1
- package/dist/main.d.mts +33 -1
- package/dist/main.d.ts +33 -1
- package/dist/main.esm.js +1 -1
- package/dist/main.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/table-links.tsx +23 -2
- package/src/lib/table.tsx +44 -4
package/package.json
CHANGED
package/src/lib/table-links.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @Author: aric 1290657123@qq.com
|
|
3
3
|
* @Date: 2025-10-03 07:11:26
|
|
4
|
-
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
-
* @LastEditTime: 2025-10-
|
|
4
|
+
* @LastEditors: aric.zheng 1290657123@qq.com
|
|
5
|
+
* @LastEditTime: 2025-10-29 07:47:55
|
|
6
6
|
*/
|
|
7
7
|
import nx from '@jswork/next';
|
|
8
8
|
import { Space } from 'antd';
|
|
@@ -19,10 +19,12 @@ const locales = {
|
|
|
19
19
|
'zh-CN': {
|
|
20
20
|
edit: '编辑',
|
|
21
21
|
destroy: '删除',
|
|
22
|
+
action: '操作',
|
|
22
23
|
},
|
|
23
24
|
'en-US': {
|
|
24
25
|
edit: 'Edit',
|
|
25
26
|
destroy: 'Destroy',
|
|
27
|
+
action: 'Action',
|
|
26
28
|
},
|
|
27
29
|
};
|
|
28
30
|
|
|
@@ -36,6 +38,12 @@ export type AcTableLinksProps = {
|
|
|
36
38
|
actions?: string[];
|
|
37
39
|
};
|
|
38
40
|
|
|
41
|
+
export type TableActionArgs = {
|
|
42
|
+
name: string;
|
|
43
|
+
lang?: string;
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
const defaultProps = {
|
|
40
48
|
lang: 'zh-CN',
|
|
41
49
|
actions: ['edit', 'destroy'],
|
|
@@ -66,3 +74,16 @@ export const AcTableLinks: FC<AcTableLinksProps> = (props) => {
|
|
|
66
74
|
</AsComponent>
|
|
67
75
|
);
|
|
68
76
|
};
|
|
77
|
+
|
|
78
|
+
export const tableAction = (args: TableActionArgs) => {
|
|
79
|
+
const { name, lang, ...rest } = args;
|
|
80
|
+
const t = (key: string) => locales[lang!][key];
|
|
81
|
+
return {
|
|
82
|
+
title: t('action'),
|
|
83
|
+
dataIndex: 'action',
|
|
84
|
+
key: 'action',
|
|
85
|
+
width: 120,
|
|
86
|
+
render: (_, record) => <AcTableLinks name={name} model={record} />,
|
|
87
|
+
...rest,
|
|
88
|
+
};
|
|
89
|
+
};
|
package/src/lib/table.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @Author: aric 1290657123@qq.com
|
|
3
3
|
* @Date: 2025-10-03 07:11:26
|
|
4
|
-
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
-
* @LastEditTime: 2025-10-
|
|
4
|
+
* @LastEditors: aric.zheng 1290657123@qq.com
|
|
5
|
+
* @LastEditTime: 2025-10-29 07:51:33
|
|
6
6
|
*
|
|
7
7
|
*
|
|
8
8
|
* 路由风格: /{module}/{name} eg: /admin/staff-roles
|
|
@@ -16,6 +16,7 @@ import cx from 'classnames';
|
|
|
16
16
|
import React from 'react';
|
|
17
17
|
import nx from '@jswork/next';
|
|
18
18
|
import '@jswork/next-create-fetcher';
|
|
19
|
+
import { tableAction } from './table-links';
|
|
19
20
|
|
|
20
21
|
type NavigateFunction = import('react-router-dom').NavigateFunction;
|
|
21
22
|
|
|
@@ -34,7 +35,12 @@ export type AcTableProps = TableProps & {
|
|
|
34
35
|
* The identity name.
|
|
35
36
|
* @default '@'
|
|
36
37
|
*/
|
|
37
|
-
name
|
|
38
|
+
name: string;
|
|
39
|
+
/**
|
|
40
|
+
* The language.
|
|
41
|
+
* @default 'zh-CN'
|
|
42
|
+
*/
|
|
43
|
+
lang?: string;
|
|
38
44
|
/**
|
|
39
45
|
* The platform module name.
|
|
40
46
|
* @default admin
|
|
@@ -100,6 +106,23 @@ export type AcTableProps = TableProps & {
|
|
|
100
106
|
* The response total key.
|
|
101
107
|
*/
|
|
102
108
|
totalPath?: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Column fields for table.
|
|
112
|
+
*/
|
|
113
|
+
columnsFields?: TableProps['columns'];
|
|
114
|
+
/**
|
|
115
|
+
* Column fields for table action.
|
|
116
|
+
*/
|
|
117
|
+
columnsAction?: TableProps['columns'];
|
|
118
|
+
/**
|
|
119
|
+
* The table action params.
|
|
120
|
+
*/
|
|
121
|
+
columnsActionParams?: Record<string, any>;
|
|
122
|
+
/**
|
|
123
|
+
* The table columns.
|
|
124
|
+
*/
|
|
125
|
+
columns?: TableProps['columns'];
|
|
103
126
|
};
|
|
104
127
|
|
|
105
128
|
type AcTableState = {
|
|
@@ -125,6 +148,7 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
|
|
|
125
148
|
defaultPageSize: 10,
|
|
126
149
|
dataPath: 'rows',
|
|
127
150
|
totalPath: 'total',
|
|
151
|
+
columnsFields: [],
|
|
128
152
|
};
|
|
129
153
|
|
|
130
154
|
public eventBus: EventMittNamespace.EventMitt = AcTable.event;
|
|
@@ -133,7 +157,19 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
|
|
|
133
157
|
|
|
134
158
|
get routerKey() {
|
|
135
159
|
const { name } = this.props;
|
|
136
|
-
return name
|
|
160
|
+
return name.replace(/_/g, '-');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get calculateColumnsAction() {
|
|
164
|
+
const { name, columnsAction, columnsActionParams, lang } = this.props;
|
|
165
|
+
if (typeof columnsAction !== 'undefined') return columnsAction;
|
|
166
|
+
return tableAction({ name, lang, ...columnsActionParams });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get calculateColumns() {
|
|
170
|
+
const { columnsFields, columns } = this.props;
|
|
171
|
+
if (columns && columns.length > 0) return columns;
|
|
172
|
+
return [...columnsFields!, this.calculateColumnsAction] as TableProps['columns'];
|
|
137
173
|
}
|
|
138
174
|
|
|
139
175
|
constructor(props: AcTableProps) {
|
|
@@ -303,6 +339,9 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
|
|
|
303
339
|
fetcher,
|
|
304
340
|
dataPath,
|
|
305
341
|
totalPath,
|
|
342
|
+
columnsFields,
|
|
343
|
+
columnsAction,
|
|
344
|
+
columns,
|
|
306
345
|
...rest
|
|
307
346
|
} = this.props;
|
|
308
347
|
const { dataSource, isLoading, current, pageSize, total } = this.state;
|
|
@@ -313,6 +352,7 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
|
|
|
313
352
|
loading={isLoading}
|
|
314
353
|
dataSource={dataSource}
|
|
315
354
|
onRow={this.handleOnRow}
|
|
355
|
+
columns={this.calculateColumns}
|
|
316
356
|
pagination={{
|
|
317
357
|
total,
|
|
318
358
|
current,
|