@jswork/antd-components 1.0.116 → 1.0.118
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 +24 -7
- package/dist/main.d.ts +24 -7
- package/dist/main.esm.js +1 -1
- package/dist/main.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/table.tsx +53 -25
- package/src/lib/use-table-command.ts +5 -4
package/package.json
CHANGED
package/src/lib/table.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: aric 1290657123@qq.com
|
|
3
3
|
* @Date: 2025-10-03 07:11:26
|
|
4
4
|
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
-
* @LastEditTime: 2025-10-
|
|
5
|
+
* @LastEditTime: 2025-10-23 15:34:25
|
|
6
6
|
*/
|
|
7
7
|
import type { EventMittNamespace } from '@jswork/event-mitt';
|
|
8
8
|
import { ReactHarmonyEvents } from '@jswork/harmony-events';
|
|
@@ -10,7 +10,7 @@ import '@jswork/next-create-fetcher';
|
|
|
10
10
|
import UrlSyncFlat from '@jswork/url-sync-flat';
|
|
11
11
|
import { Table, TableProps, message } from 'antd';
|
|
12
12
|
import cx from 'classnames';
|
|
13
|
-
import React
|
|
13
|
+
import React from 'react';
|
|
14
14
|
|
|
15
15
|
const CLASS_NAME = 'ac-table';
|
|
16
16
|
|
|
@@ -41,7 +41,16 @@ export type AcTableProps = TableProps & {
|
|
|
41
41
|
total?: number; // 如果 fetcher 不返回 total,可在此固定(不推荐)
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
type AcTableState = {
|
|
45
|
+
currentRowId: any;
|
|
46
|
+
dataSource: TableProps['dataSource'];
|
|
47
|
+
isLoading: boolean;
|
|
48
|
+
current: any;
|
|
49
|
+
pageSize: any;
|
|
50
|
+
total: any;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class AcTable extends React.Component<AcTableProps, AcTableState> {
|
|
45
54
|
static displayName = CLASS_NAME;
|
|
46
55
|
static formSchema = CLASS_NAME;
|
|
47
56
|
private harmonyEvents: ReactHarmonyEvents | null = null;
|
|
@@ -65,6 +74,7 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
65
74
|
const init = this.sync.readInitialState({ defaults });
|
|
66
75
|
|
|
67
76
|
this.state = {
|
|
77
|
+
currentRowId: null,
|
|
68
78
|
dataSource: [],
|
|
69
79
|
isLoading: false,
|
|
70
80
|
current: init.page,
|
|
@@ -129,12 +139,24 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
129
139
|
},
|
|
130
140
|
() => {
|
|
131
141
|
void this.fetchData(defaultCurrent!, defaultPageSize!);
|
|
132
|
-
}
|
|
142
|
+
},
|
|
133
143
|
);
|
|
134
144
|
};
|
|
135
145
|
|
|
136
146
|
/* ----- public eventBus methods end ----- */
|
|
137
147
|
|
|
148
|
+
handleOnRow = (record) => {
|
|
149
|
+
const { rowKey } = this.props;
|
|
150
|
+
return {
|
|
151
|
+
onMouseEnter: () => {
|
|
152
|
+
this.setState({ currentRowId: record[rowKey as any] });
|
|
153
|
+
},
|
|
154
|
+
onMouseLeave: () => {
|
|
155
|
+
this.setState({ currentRowId: null });
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
138
160
|
render() {
|
|
139
161
|
const { className, pagination, onPageChange, params, ...rest } = this.props;
|
|
140
162
|
const { dataSource, isLoading, current, pageSize, total } = this.state;
|
|
@@ -143,6 +165,7 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
143
165
|
className={cx(className, CLASS_NAME)}
|
|
144
166
|
loading={isLoading}
|
|
145
167
|
dataSource={dataSource}
|
|
168
|
+
onRow={this.handleOnRow}
|
|
146
169
|
pagination={{
|
|
147
170
|
total,
|
|
148
171
|
current,
|
|
@@ -167,24 +190,29 @@ export type AcTableMainProps = Omit<AcTableProps, 'fetcher'> & {
|
|
|
167
190
|
totalPath?: string;
|
|
168
191
|
};
|
|
169
192
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
...
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
193
|
+
// const ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaProps>(
|
|
194
|
+
// (props, ref) => {
|
|
195
|
+
export const AcTableMain = React.forwardRef<any, AcTableMainProps>(
|
|
196
|
+
(props, ref) => {
|
|
197
|
+
const { name, dataPath, totalPath, ...rest } = {
|
|
198
|
+
dataPath: 'rows',
|
|
199
|
+
totalPath: 'total',
|
|
200
|
+
...props,
|
|
201
|
+
};
|
|
202
|
+
const resourceId = `${name}_index`;
|
|
203
|
+
const fetcher = nx.createFetcher(resourceId, { dataPath, totalPath });
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<AcTable
|
|
207
|
+
ref={ref}
|
|
208
|
+
size="middle"
|
|
209
|
+
rowKey="id"
|
|
210
|
+
bordered
|
|
211
|
+
name={name}
|
|
212
|
+
fetcher={fetcher}
|
|
213
|
+
pagination={{ showSizeChanger: true }}
|
|
214
|
+
{...rest}
|
|
215
|
+
/>
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AcTable } from './table';
|
|
2
2
|
|
|
3
|
+
type ExecuteFn = (command: string, ...args: any[]) => void;
|
|
4
|
+
type ListenFn = (command: string, callback: any) => void;
|
|
5
|
+
|
|
3
6
|
const useCommand = (inName?: string) => {
|
|
4
7
|
const name = inName || '@';
|
|
5
|
-
const execute = (command
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const listen = (cmd: string, callback: any) => AcTable.event?.on(`${name}:${cmd}`, callback);
|
|
8
|
+
const execute: ExecuteFn = (command, ...args) => AcTable.event?.emit(`${name}:${command}`, ...args);
|
|
9
|
+
const listen: ListenFn = (cmd, callback) => AcTable.event?.on(`${name}:${cmd}`, callback);
|
|
9
10
|
|
|
10
11
|
// the command repository:
|
|
11
12
|
const refetch = () => execute('refetch');
|