@jswork/antd-components 1.0.157 → 1.0.159

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jswork/antd-components",
3
- "version": "1.0.157",
3
+ "version": "1.0.159",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.esm.js",
6
6
  "types": "dist/main.d.ts",
@@ -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-25 21:52:35
4
+ * @LastEditors: aric.zheng 1290657123@qq.com
5
+ * @LastEditTime: 2025-10-29 08:14:20
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-26 19:43:01
4
+ * @LastEditors: aric.zheng 1290657123@qq.com
5
+ * @LastEditTime: 2025-10-29 08:14:01
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?: string;
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 = {
@@ -119,12 +142,14 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
119
142
  static events = ['refetch', 'reset', 'add', 'edit', 'destroy', 'draft'];
120
143
  static defaultProps = {
121
144
  name: '@',
145
+ lang: 'zh-CN',
122
146
  module: 'admin',
123
147
  rowKey: 'id',
124
148
  defaultCurrent: 1,
125
149
  defaultPageSize: 10,
126
150
  dataPath: 'rows',
127
151
  totalPath: 'total',
152
+ columnsFields: [],
128
153
  };
129
154
 
130
155
  public eventBus: EventMittNamespace.EventMitt = AcTable.event;
@@ -133,7 +158,19 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
133
158
 
134
159
  get routerKey() {
135
160
  const { name } = this.props;
136
- return name!.replace(/_/g, '-');
161
+ return name.replace(/_/g, '-');
162
+ }
163
+
164
+ get calculateColumnsAction() {
165
+ const { name, columnsAction, columnsActionParams, lang } = this.props;
166
+ if (typeof columnsAction !== 'undefined') return columnsAction;
167
+ return tableAction({ name, lang, ...columnsActionParams });
168
+ }
169
+
170
+ get calculateColumns() {
171
+ const { columnsFields, columns } = this.props;
172
+ if (columns && columns.length > 0) return columns;
173
+ return [...columnsFields!, this.calculateColumnsAction] as TableProps['columns'];
137
174
  }
138
175
 
139
176
  constructor(props: AcTableProps) {
@@ -303,6 +340,9 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
303
340
  fetcher,
304
341
  dataPath,
305
342
  totalPath,
343
+ columnsFields,
344
+ columnsAction,
345
+ columns,
306
346
  ...rest
307
347
  } = this.props;
308
348
  const { dataSource, isLoading, current, pageSize, total } = this.state;
@@ -313,6 +353,7 @@ export class AcTable extends React.Component<AcTableProps, AcTableState> {
313
353
  loading={isLoading}
314
354
  dataSource={dataSource}
315
355
  onRow={this.handleOnRow}
356
+ columns={this.calculateColumns}
316
357
  pagination={{
317
358
  total,
318
359
  current,