@jswork/antd-components 1.0.108 → 1.0.110
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.cjs.js.map +1 -1
- package/dist/main.d.mts +34 -5
- package/dist/main.d.ts +34 -5
- package/dist/main.esm.js +1 -1
- package/dist/main.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/lib/alert.tsx +14 -1
- package/src/lib/breadcrumb.tsx +7 -3
- package/src/lib/button.tsx +122 -0
- package/src/lib/table.tsx +37 -25
- package/src/main.ts +1 -0
- package/src/tpls/breadcrumb/index.tsx +2 -1
- package/src/tpls/kv/index.tsx +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jswork/antd-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.110",
|
|
4
4
|
"main": "dist/main.cjs.js",
|
|
5
5
|
"module": "dist/main.esm.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@jswork/harmony-events": "^1.2.11",
|
|
21
|
-
"@jswork/next": "^1.2
|
|
21
|
+
"@jswork/next": "^1.4.2",
|
|
22
22
|
"@swc/core": "^1.3.93",
|
|
23
23
|
"@types/react": "^18.2.28",
|
|
24
24
|
"@types/react-dom": "^18.2.13",
|
|
25
|
-
"antd": "^5.27.
|
|
25
|
+
"antd": "^5.27.5",
|
|
26
26
|
"autoprefixer": "^10.4.16",
|
|
27
27
|
"classnames": "^2.5.1",
|
|
28
28
|
"cssnano": "^6.0.1",
|
package/src/lib/alert.tsx
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Input, InputProps, Modal } from 'antd';
|
|
2
|
+
import { Input, InputProps, message, Modal } from 'antd';
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
interface NxStatic {
|
|
6
|
+
err: (inMessage: string) => any;
|
|
7
|
+
msg: (inMessage: string) => any;
|
|
6
8
|
alert: (inMessage: string, inTitle?: String) => any;
|
|
7
9
|
confirm: (inMessage: string, inTitle?: String) => any;
|
|
8
10
|
prompt: (inMessage: string, inOptions?: InputProps) => any;
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
export const msg = (inMessage: string) => {
|
|
15
|
+
return message.success(inMessage);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const err = (inMessage: string) => {
|
|
19
|
+
return message.error(inMessage);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
|
|
12
23
|
export const alert = (inMessage: string, inTitle?: String) => {
|
|
13
24
|
return Modal.info({
|
|
14
25
|
title: inTitle || 'Tips',
|
|
@@ -47,6 +58,8 @@ export const prompt = (inMessage: string, inOptions?: InputProps) => {
|
|
|
47
58
|
});
|
|
48
59
|
};
|
|
49
60
|
|
|
61
|
+
nx.msg = msg;
|
|
62
|
+
nx.err = err;
|
|
50
63
|
nx.alert = alert;
|
|
51
64
|
nx.confirm = confirm;
|
|
52
65
|
nx.prompt = prompt;
|
package/src/lib/breadcrumb.tsx
CHANGED
|
@@ -32,9 +32,13 @@ export class AcBreadcrumb extends React.Component<AcBreadcrumbProps> {
|
|
|
32
32
|
render() {
|
|
33
33
|
const { className, value, items, template, onChange, ...props } = this.props;
|
|
34
34
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
<ReactList
|
|
36
|
+
items={items || []}
|
|
37
|
+
template={template}
|
|
38
|
+
as={Breadcrumb}
|
|
39
|
+
className={cx(className, CLASS_NAME)}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
38
42
|
);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: aric 1290657123@qq.com
|
|
3
|
+
* @Date: 2025-10-18 07:09:31
|
|
4
|
+
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
+
* @LastEditTime: 2025-10-18 07:29:35
|
|
6
|
+
*/
|
|
7
|
+
import React, { FC } from 'react';
|
|
8
|
+
import { Button, ButtonProps } from 'antd';
|
|
9
|
+
|
|
10
|
+
const locals = {
|
|
11
|
+
'zh-CN': {
|
|
12
|
+
create: '添加',
|
|
13
|
+
edit: '编辑',
|
|
14
|
+
del: '删除',
|
|
15
|
+
view: '查看',
|
|
16
|
+
save: '保存',
|
|
17
|
+
export: '导出',
|
|
18
|
+
imp: '导入',
|
|
19
|
+
refresh: '刷新',
|
|
20
|
+
back: '返回',
|
|
21
|
+
submit: '提交',
|
|
22
|
+
cancel: '取消',
|
|
23
|
+
},
|
|
24
|
+
'en-US': {
|
|
25
|
+
create: 'Create',
|
|
26
|
+
edit: 'Edit',
|
|
27
|
+
del: 'Delete',
|
|
28
|
+
view: 'View',
|
|
29
|
+
save: 'Save',
|
|
30
|
+
export: 'Export',
|
|
31
|
+
imp: 'Import',
|
|
32
|
+
refresh: 'Refresh',
|
|
33
|
+
back: 'Back',
|
|
34
|
+
submit: 'Submit',
|
|
35
|
+
cancel: 'Cancel',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const t = (locale: string, key: string) => {
|
|
40
|
+
return locals[locale][key] || key;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type AcButtonProps = ButtonProps & {
|
|
44
|
+
lang: 'zh-CN' | 'en-US';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const BtnCreate: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
48
|
+
return <Button size="small" {...props}>
|
|
49
|
+
➕
|
|
50
|
+
<span>{t(lang, 'create')}</span>
|
|
51
|
+
</Button>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const BtnEdit: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
55
|
+
return <Button size="small" {...props}>
|
|
56
|
+
✏️
|
|
57
|
+
<span>{t(lang, 'edit')}</span>
|
|
58
|
+
</Button>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const BtnDelete: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
62
|
+
return <Button size="small" {...props}>
|
|
63
|
+
🗑️
|
|
64
|
+
<span>{t(lang, 'del')}</span>
|
|
65
|
+
</Button>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const BtnView: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
69
|
+
return <Button size="small" {...props}>
|
|
70
|
+
👁️
|
|
71
|
+
<span>{t(lang, 'view')}</span>
|
|
72
|
+
</Button>;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const BtnSave: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
76
|
+
return <Button size="small" {...props}>
|
|
77
|
+
💾
|
|
78
|
+
<span>{t(lang, 'save')}</span>
|
|
79
|
+
</Button>;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const BtnExport: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
83
|
+
return <Button size="small" {...props}>
|
|
84
|
+
📤
|
|
85
|
+
<span>{t(lang, 'export')}</span>
|
|
86
|
+
</Button>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const BtnImport: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
90
|
+
return <Button size="small" {...props}>
|
|
91
|
+
📥
|
|
92
|
+
<span>{t(lang, 'imp')}</span>
|
|
93
|
+
</Button>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const BtnRefresh: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
97
|
+
return <Button size="small" {...props}>
|
|
98
|
+
⚡️
|
|
99
|
+
<span>{t(lang, 'refresh')}</span>
|
|
100
|
+
</Button>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const BtnBack: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
104
|
+
return <Button size="small" {...props}>
|
|
105
|
+
🔙
|
|
106
|
+
<span>{t(lang, 'back')}</span>
|
|
107
|
+
</Button>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const BtnSubmit: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
111
|
+
return <Button size="small" {...props}>
|
|
112
|
+
📨
|
|
113
|
+
<span>{t(lang, 'submit')}</span>
|
|
114
|
+
</Button>;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const BtnCancel: FC<AcButtonProps> = ({ lang = 'zh-CN', ...props }) => {
|
|
118
|
+
return <Button size="small" {...props}>
|
|
119
|
+
❌
|
|
120
|
+
<span>{t(lang, 'cancel')}</span>
|
|
121
|
+
</Button>;
|
|
122
|
+
};
|
package/src/lib/table.tsx
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @Author: aric 1290657123@qq.com
|
|
3
3
|
* @Date: 2025-10-03 07:11:26
|
|
4
|
-
* @LastEditors: aric
|
|
5
|
-
* @LastEditTime: 2025-10-
|
|
4
|
+
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
+
* @LastEditTime: 2025-10-18 17:16:07
|
|
6
6
|
*/
|
|
7
|
-
import React, { FC } from 'react';
|
|
8
|
-
import { Table, TableProps, message } from 'antd';
|
|
9
|
-
import cx from 'classnames';
|
|
10
7
|
import type { EventMittNamespace } from '@jswork/event-mitt';
|
|
11
8
|
import { ReactHarmonyEvents } from '@jswork/harmony-events';
|
|
12
9
|
import '@jswork/next-create-fetcher';
|
|
10
|
+
import { Table, TableProps, message } from 'antd';
|
|
11
|
+
import cx from 'classnames';
|
|
12
|
+
import React, { FC } from 'react';
|
|
13
13
|
|
|
14
14
|
const CLASS_NAME = 'ac-table';
|
|
15
15
|
|
|
@@ -19,14 +19,22 @@ export type AcTableProps = TableProps & {
|
|
|
19
19
|
* @default '@'
|
|
20
20
|
*/
|
|
21
21
|
name?: string;
|
|
22
|
+
params?: Record<string, any>;
|
|
22
23
|
/**
|
|
23
24
|
* 自定义数据获取函数
|
|
24
25
|
* @param params { current: number; pageSize: number }
|
|
25
26
|
* @returns Promise<{ data: any[]; total: number }>
|
|
26
27
|
*/
|
|
27
|
-
fetcher: (params: {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
fetcher: (params: {
|
|
29
|
+
current: number;
|
|
30
|
+
pageSize: number;
|
|
31
|
+
params?: Record<string, any>;
|
|
32
|
+
}) => Promise<{ data: any[]; total: number }>;
|
|
33
|
+
/**
|
|
34
|
+
* @param page
|
|
35
|
+
* @param size
|
|
36
|
+
*/
|
|
37
|
+
onPageChange?: (page: number, size: number) => void;
|
|
30
38
|
defaultCurrent?: number;
|
|
31
39
|
defaultPageSize?: number;
|
|
32
40
|
total?: number; // 如果 fetcher 不返回 total,可在此固定(不推荐)
|
|
@@ -37,10 +45,7 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
37
45
|
static formSchema = CLASS_NAME;
|
|
38
46
|
private harmonyEvents: ReactHarmonyEvents | null = null;
|
|
39
47
|
static event: EventMittNamespace.EventMitt;
|
|
40
|
-
static events = [
|
|
41
|
-
'refetch',
|
|
42
|
-
'reset',
|
|
43
|
-
];
|
|
48
|
+
static events = ['refetch', 'reset'];
|
|
44
49
|
|
|
45
50
|
static defaultProps = {
|
|
46
51
|
name: '@',
|
|
@@ -76,10 +81,10 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
76
81
|
|
|
77
82
|
fetchData = async (page: number, size: number) => {
|
|
78
83
|
const abortController = new AbortController();
|
|
79
|
-
const { fetcher } = this.props;
|
|
84
|
+
const { fetcher, params } = this.props;
|
|
80
85
|
this.setState({ isLoading: true });
|
|
81
86
|
try {
|
|
82
|
-
const result = await fetcher({ current: page, pageSize: size });
|
|
87
|
+
const result = await fetcher({ current: page, pageSize: size, params });
|
|
83
88
|
if (!abortController.signal.aborted) {
|
|
84
89
|
this.setState({
|
|
85
90
|
dataSource: result.data || [],
|
|
@@ -109,22 +114,26 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
109
114
|
|
|
110
115
|
reset = async () => {
|
|
111
116
|
const { defaultCurrent, defaultPageSize } = this.props;
|
|
112
|
-
this.setState(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
this.setState(
|
|
118
|
+
{
|
|
119
|
+
current: defaultCurrent,
|
|
120
|
+
pageSize: defaultPageSize,
|
|
121
|
+
},
|
|
122
|
+
() => {
|
|
123
|
+
void this.fetchData(defaultCurrent!, defaultPageSize!);
|
|
124
|
+
}
|
|
125
|
+
);
|
|
118
126
|
};
|
|
119
127
|
|
|
120
128
|
/* ----- public eventBus methods end ----- */
|
|
121
129
|
|
|
122
130
|
render() {
|
|
123
|
-
const { className, pagination, onPageChange, ...rest } = this.props;
|
|
131
|
+
const { className, pagination, onPageChange, params, ...rest } = this.props;
|
|
124
132
|
const { dataSource, isLoading, current, pageSize, total } = this.state;
|
|
125
133
|
return (
|
|
126
134
|
<Table
|
|
127
|
-
className={cx(className, CLASS_NAME)}
|
|
135
|
+
className={cx(className, CLASS_NAME)}
|
|
136
|
+
loading={isLoading}
|
|
128
137
|
dataSource={dataSource}
|
|
129
138
|
pagination={{
|
|
130
139
|
total,
|
|
@@ -146,12 +155,16 @@ export class AcTable extends React.Component<AcTableProps, any> {
|
|
|
146
155
|
|
|
147
156
|
export type AcTableMainProps = Omit<AcTableProps, 'fetcher'> & {
|
|
148
157
|
name: string;
|
|
149
|
-
dataPath?: string
|
|
158
|
+
dataPath?: string;
|
|
150
159
|
totalPath?: string;
|
|
151
160
|
};
|
|
152
161
|
|
|
153
162
|
export const AcTableMain: FC<AcTableMainProps> = (props) => {
|
|
154
|
-
const { name, dataPath, totalPath, ...rest } = {
|
|
163
|
+
const { name, dataPath, totalPath, params, ...rest } = {
|
|
164
|
+
dataPath: 'rows',
|
|
165
|
+
totalPath: 'total',
|
|
166
|
+
...props,
|
|
167
|
+
};
|
|
155
168
|
const resourceId = `${name}_index`;
|
|
156
169
|
const fetcher = nx.createFetcher(resourceId, { dataPath, totalPath });
|
|
157
170
|
|
|
@@ -167,4 +180,3 @@ export const AcTableMain: FC<AcTableMainProps> = (props) => {
|
|
|
167
180
|
/>
|
|
168
181
|
);
|
|
169
182
|
};
|
|
170
|
-
|
package/src/main.ts
CHANGED
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
|
|
4
4
|
export const breadcrumbDefault = ({ item, index, items }) => {
|
|
5
5
|
const last = items?.length - 1 === index;
|
|
6
|
-
const
|
|
6
|
+
const { label, ...rest } = item;
|
|
7
|
+
const child = last ? <span {...rest}>{label}</span> : <a {...rest}>{label}</a>;
|
|
7
8
|
return <Breadcrumb.Item key={index}>{child}</Breadcrumb.Item>;
|
|
8
9
|
};
|
package/src/tpls/kv/index.tsx
CHANGED
|
@@ -22,12 +22,12 @@ const defaults = {
|
|
|
22
22
|
*/
|
|
23
23
|
export const kv = ({ item, index }, options: Options) => {
|
|
24
24
|
const opts = { ...defaults, ...options };
|
|
25
|
-
const { component: Component, value, label, ...
|
|
25
|
+
const { component: Component, value, label, ...rest } = opts;
|
|
26
26
|
const val = item[value];
|
|
27
27
|
const children = item[label];
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
|
-
<Component key={index} value={val} {...
|
|
30
|
+
<Component key={index} value={val} {...rest}>
|
|
31
31
|
{children}
|
|
32
32
|
</Component>
|
|
33
33
|
);
|
|
@@ -60,9 +60,9 @@ export const radioKv = (args, opts) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
export const treeKv = ({ item }, cb) => {
|
|
63
|
-
const { value, label, ...
|
|
63
|
+
const { value, label, ...rest } = item;
|
|
64
64
|
return (
|
|
65
|
-
<Tree.TreeNode key={value} title={label} {...
|
|
65
|
+
<Tree.TreeNode key={value} title={label} {...rest}>
|
|
66
66
|
{cb()}
|
|
67
67
|
</Tree.TreeNode>
|
|
68
68
|
);
|