@wangtaizong/components 1.0.7 → 1.1.0
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/index.js +285 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/es/Button/index.d.ts +9 -0
- package/es/Button/index.js +25 -0
- package/es/Icon/index.d.ts +9 -0
- package/es/Icon/index.js +25 -0
- package/es/Upload/index.d.ts +16 -0
- package/es/Upload/index.js +221 -0
- package/es/antd/index.js +2 -0
- package/es/index.js +5 -0
- package/lib/Button/index.d.ts +9 -0
- package/lib/Button/index.js +29 -0
- package/lib/Icon/index.d.ts +9 -0
- package/lib/Icon/index.js +48 -0
- package/lib/Upload/index.d.ts +16 -0
- package/lib/Upload/index.js +243 -0
- package/lib/antd/index.d.ts +2 -0
- package/lib/antd/index.js +28 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +32 -0
- package/package.json +40 -68
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.dumirc.ts +0 -28
- package/.editorconfig +0 -13
- package/.eslintrc.js +0 -3
- package/.husky/commit-msg +0 -5
- package/.husky/pre-commit +0 -8
- package/.husky/pre-push +0 -8
- package/.prettierignore +0 -2
- package/.prettierrc.js +0 -19
- package/.stylelintrc +0 -3
- package/.vscode/settings.json +0 -3
- package/README.md +0 -0
- package/commitlint.config.js +0 -21
- package/docs/changelogs/index.md +0 -9
- package/docs/components/index.md +0 -1
- package/docs/guide/install.md +0 -39
- package/docs/index.md +0 -21
- package/docs/utils/index.md +0 -1
- package/lerna.json +0 -8
- package/packages/components/CHANGELOG.md +0 -0
- package/packages/components/package.json +0 -48
- package/packages/components/rollup.config.mjs +0 -108
- package/packages/components/src/Button/index.md +0 -13
- package/packages/components/src/Button/index.tsx +0 -34
- package/packages/components/src/Icon/index.md +0 -81
- package/packages/components/src/Icon/index.tsx +0 -34
- package/packages/components/src/Upload/index.md +0 -209
- package/packages/components/src/Upload/index.tsx +0 -218
- package/packages/components/src/antd/index.md +0 -12
- package/packages/components/src/index.md +0 -23
- package/packages/components/tsconfig.json +0 -32
- package/packages/utils/README.md +0 -11
- package/packages/utils/package.json +0 -35
- package/packages/utils/rollup.config.mjs +0 -63
- package/packages/utils/src/CHRRequest/index.md +0 -59
- package/packages/utils/src/CHRRequest/index.ts +0 -94
- package/packages/utils/src/index.ts +0 -17
- package/packages/utils/tsconfig.json +0 -28
- package/pnpm-workspace.yaml +0 -8
- package/public/favicon.ico +0 -0
- package/public/logo.webp +0 -0
- package/tsconfig.json +0 -14
- /package/{packages/components/src/antd/index.tsx → es/antd/index.d.ts} +0 -0
- /package/{packages/components/src/index.ts → es/index.d.ts} +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import * as Icons from '@ant-design/icons';
|
|
2
|
-
import React, { FC } from 'react';
|
|
3
|
-
|
|
4
|
-
interface ChrIconProps {
|
|
5
|
-
icon: string;
|
|
6
|
-
fontSize?: number;
|
|
7
|
-
className?: string;
|
|
8
|
-
style?: React.CSSProperties;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const CHRIcon: FC<ChrIconProps> = ({
|
|
12
|
-
icon,
|
|
13
|
-
fontSize = 20,
|
|
14
|
-
className,
|
|
15
|
-
style,
|
|
16
|
-
}) => {
|
|
17
|
-
const IconComponent = (Icons as any)[icon];
|
|
18
|
-
if (!IconComponent) {
|
|
19
|
-
console.warn(`Icon "${icon}" is not a valid icon component`);
|
|
20
|
-
return <></>;
|
|
21
|
-
}
|
|
22
|
-
return (
|
|
23
|
-
<IconComponent
|
|
24
|
-
className={className}
|
|
25
|
-
style={{
|
|
26
|
-
fontSize: fontSize + 'px',
|
|
27
|
-
cursor: 'pointer',
|
|
28
|
-
...style,
|
|
29
|
-
}}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default CHRIcon;
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
# CHRUpload 上传
|
|
2
|
-
|
|
3
|
-
文件上传组件,基于 Ant Design Upload 封装,支持文件/头像上传、大小限制、数量限制、认证等功能。
|
|
4
|
-
|
|
5
|
-
## 代码演示
|
|
6
|
-
|
|
7
|
-
### 基本用法
|
|
8
|
-
|
|
9
|
-
文件上传的基本用法,支持限制文件数量和大小。
|
|
10
|
-
|
|
11
|
-
```jsx
|
|
12
|
-
import { CHRUpload } from '@chr/components';
|
|
13
|
-
import { useState } from 'react';
|
|
14
|
-
|
|
15
|
-
export default () => {
|
|
16
|
-
const [fileList, setFileList] = useState([
|
|
17
|
-
{
|
|
18
|
-
name: 'example.txt',
|
|
19
|
-
url: 'http://localhost:3000/uploads/example.txt',
|
|
20
|
-
},
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
const handleChange = (file, newFileList) => {
|
|
24
|
-
setFileList(newFileList);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<CHRUpload
|
|
29
|
-
url="http://localhost:3000/upload"
|
|
30
|
-
value={fileList}
|
|
31
|
-
handleChange={handleChange}
|
|
32
|
-
maxCount={3}
|
|
33
|
-
limit={20}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### 头像上传
|
|
40
|
-
|
|
41
|
-
设置 `uploadType="avatar"`,组件会展示为头像上传样式,限制只能上传图片,且最多一张。
|
|
42
|
-
|
|
43
|
-
```jsx
|
|
44
|
-
import { CHRUpload } from '@chr/components';
|
|
45
|
-
import { useState } from 'react';
|
|
46
|
-
|
|
47
|
-
export default () => {
|
|
48
|
-
const [fileList, setFileList] = useState([]);
|
|
49
|
-
|
|
50
|
-
const handleChange = (file, newFileList) => {
|
|
51
|
-
setFileList(newFileList);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<CHRUpload
|
|
56
|
-
value={fileList}
|
|
57
|
-
uploadType="avatar"
|
|
58
|
-
url="http://localhost:3000/upload"
|
|
59
|
-
handleChange={handleChange}
|
|
60
|
-
/>
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 限制数量
|
|
66
|
-
|
|
67
|
-
通过 `maxCount` 限制上传文件数量。
|
|
68
|
-
|
|
69
|
-
```jsx
|
|
70
|
-
import { CHRUpload } from '@chr/components';
|
|
71
|
-
import { useState } from 'react';
|
|
72
|
-
|
|
73
|
-
export default () => {
|
|
74
|
-
const [fileList, setFileList] = useState([]);
|
|
75
|
-
|
|
76
|
-
const handleChange = (file, newFileList) => {
|
|
77
|
-
setFileList(newFileList);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<CHRUpload
|
|
82
|
-
url="http://localhost:3000/upload"
|
|
83
|
-
value={fileList}
|
|
84
|
-
handleChange={handleChange}
|
|
85
|
-
maxCount={2}
|
|
86
|
-
/>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### 限制大小
|
|
92
|
-
|
|
93
|
-
通过 `limit` 限制单个文件大小(MB)。
|
|
94
|
-
|
|
95
|
-
```jsx
|
|
96
|
-
import { CHRUpload } from '@chr/components';
|
|
97
|
-
import { useState } from 'react';
|
|
98
|
-
|
|
99
|
-
export default () => {
|
|
100
|
-
const [fileList, setFileList] = useState([]);
|
|
101
|
-
|
|
102
|
-
const handleChange = (file, newFileList) => {
|
|
103
|
-
setFileList(newFileList);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<CHRUpload
|
|
108
|
-
url="http://localhost:3000/upload"
|
|
109
|
-
value={fileList}
|
|
110
|
-
handleChange={handleChange}
|
|
111
|
-
limit={5}
|
|
112
|
-
/>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### 自定义接受类型
|
|
118
|
-
|
|
119
|
-
通过 `accept` 限制文件类型。
|
|
120
|
-
|
|
121
|
-
```jsx
|
|
122
|
-
import { CHRUpload } from '@chr/components';
|
|
123
|
-
import { useState } from 'react';
|
|
124
|
-
|
|
125
|
-
export default () => {
|
|
126
|
-
const [fileList, setFileList] = useState([]);
|
|
127
|
-
|
|
128
|
-
const handleChange = (file, newFileList) => {
|
|
129
|
-
setFileList(newFileList);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<CHRUpload
|
|
134
|
-
url="http://localhost:3000/upload"
|
|
135
|
-
value={fileList}
|
|
136
|
-
handleChange={handleChange}
|
|
137
|
-
accept=".jpg,.png"
|
|
138
|
-
/>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### 携带 Token
|
|
144
|
-
|
|
145
|
-
通过 `token` 添加认证头。
|
|
146
|
-
|
|
147
|
-
```jsx
|
|
148
|
-
import { CHRUpload } from '@chr/components';
|
|
149
|
-
import { useState } from 'react';
|
|
150
|
-
|
|
151
|
-
export default () => {
|
|
152
|
-
const [fileList, setFileList] = useState([]);
|
|
153
|
-
|
|
154
|
-
const handleChange = (file, newFileList) => {
|
|
155
|
-
setFileList(newFileList);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
return (
|
|
159
|
-
<CHRUpload
|
|
160
|
-
url="http://localhost:3000/upload"
|
|
161
|
-
value={fileList}
|
|
162
|
-
handleChange={handleChange}
|
|
163
|
-
token="your-jwt-token"
|
|
164
|
-
/>
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### 自定义上传按钮
|
|
170
|
-
|
|
171
|
-
通过 `children` 自定义上传触发器。
|
|
172
|
-
|
|
173
|
-
```jsx
|
|
174
|
-
import { CHRUpload } from '@chr/components';
|
|
175
|
-
import { useState } from 'react';
|
|
176
|
-
import { Button } from 'antd';
|
|
177
|
-
|
|
178
|
-
export default () => {
|
|
179
|
-
const [fileList, setFileList] = useState([]);
|
|
180
|
-
|
|
181
|
-
const handleChange = (file, newFileList) => {
|
|
182
|
-
setFileList(newFileList);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<CHRUpload
|
|
187
|
-
url="http://localhost:3000/upload"
|
|
188
|
-
value={fileList}
|
|
189
|
-
handleChange={handleChange}
|
|
190
|
-
>
|
|
191
|
-
<Button type="primary">点击上传</Button>
|
|
192
|
-
</CHRUpload>
|
|
193
|
-
);
|
|
194
|
-
};
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## API
|
|
198
|
-
|
|
199
|
-
| 属性 | 说明 | 类型 | 默认值 |
|
|
200
|
-
| ------------ | ---------------------------- | ------------------------ | --------------------------- |
|
|
201
|
-
| uploadType | 上传类型,`avatar` 或 `file` | string | `'file'` |
|
|
202
|
-
| url | 上传地址 | string | - |
|
|
203
|
-
| token | 认证 token,会添加到请求头 | string | - |
|
|
204
|
-
| maxCount | 最大上传数量 | number | `1` |
|
|
205
|
-
| limit | 文件大小限制(MB) | number | `10`(file)/ `2`(avatar) |
|
|
206
|
-
| accept | 接受的文件类型 | string | - |
|
|
207
|
-
| handleChange | 文件变化时的回调 | (file, fileList) => void | - |
|
|
208
|
-
| value | 文件列表,受控属性 | UploadFile[] | [] |
|
|
209
|
-
| children | 自定义上传触发器 | ReactNode | - |
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { Image } from 'antd';
|
|
2
|
-
import type { UploadProps } from 'antd/es/upload';
|
|
3
|
-
import type { UploadChangeParam, UploadFile } from 'antd/es/upload/interface';
|
|
4
|
-
import { ReactNode, useCallback, useMemo, useState } from 'react';
|
|
5
|
-
import { antd, CHRButton, CHRIcon } from '..';
|
|
6
|
-
|
|
7
|
-
interface CHRUploadProps {
|
|
8
|
-
children?: ReactNode;
|
|
9
|
-
uploadType?: 'avatar' | 'file';
|
|
10
|
-
url?: string;
|
|
11
|
-
token?: string;
|
|
12
|
-
maxCount?: number;
|
|
13
|
-
limit?: number;
|
|
14
|
-
accept?: string;
|
|
15
|
-
handleChange?: (file: UploadFile, fileList: UploadFile[]) => void;
|
|
16
|
-
value: UploadFile[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const CHRUpload = ({
|
|
20
|
-
value,
|
|
21
|
-
children,
|
|
22
|
-
uploadType = 'file',
|
|
23
|
-
url,
|
|
24
|
-
token,
|
|
25
|
-
maxCount = 1,
|
|
26
|
-
limit,
|
|
27
|
-
accept: acceptProp,
|
|
28
|
-
handleChange,
|
|
29
|
-
...restProps
|
|
30
|
-
}: CHRUploadProps &
|
|
31
|
-
Omit<
|
|
32
|
-
UploadProps,
|
|
33
|
-
'onChange' | 'fileList' | 'action' | 'headers' | 'accept' | 'maxCount'
|
|
34
|
-
>) => {
|
|
35
|
-
const className = restProps.className;
|
|
36
|
-
const [fileList, setFileList] = useState<UploadFile[]>(value || []);
|
|
37
|
-
const [previewOpen, setPreviewOpen] = useState(false);
|
|
38
|
-
const [previewImage, setPreviewImage] = useState('');
|
|
39
|
-
|
|
40
|
-
const getDefaultAccept = useCallback(() => {
|
|
41
|
-
if (uploadType === 'avatar') return 'image/*';
|
|
42
|
-
return undefined;
|
|
43
|
-
}, [uploadType]);
|
|
44
|
-
|
|
45
|
-
const getDefaultLimit = useCallback(() => {
|
|
46
|
-
if (uploadType === 'avatar') return 2;
|
|
47
|
-
if (uploadType === 'file') return 10;
|
|
48
|
-
return undefined;
|
|
49
|
-
}, [uploadType]);
|
|
50
|
-
|
|
51
|
-
const finalAccept = acceptProp ?? getDefaultAccept();
|
|
52
|
-
const finalLimit = limit ?? getDefaultLimit();
|
|
53
|
-
|
|
54
|
-
const beforeUpload = useCallback(
|
|
55
|
-
(file: File) => {
|
|
56
|
-
if (finalLimit) {
|
|
57
|
-
const isLimit = file.size / 1024 / 1024 < finalLimit;
|
|
58
|
-
if (!isLimit) {
|
|
59
|
-
antd.message.error(`文件大小不能超过 ${finalLimit}MB`);
|
|
60
|
-
return antd.Upload.LIST_IGNORE;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (finalAccept) {
|
|
64
|
-
const acceptList = finalAccept.split(',').map((item) => item.trim());
|
|
65
|
-
const fileType = file.type;
|
|
66
|
-
const fileName = file.name;
|
|
67
|
-
const isAccept = acceptList.some((accept) => {
|
|
68
|
-
if (accept.endsWith('/*')) {
|
|
69
|
-
const mainType = accept.replace('/*', '');
|
|
70
|
-
return fileType.startsWith(mainType + '/');
|
|
71
|
-
}
|
|
72
|
-
if (accept.startsWith('.')) {
|
|
73
|
-
return fileName.endsWith(accept);
|
|
74
|
-
}
|
|
75
|
-
return fileType === accept;
|
|
76
|
-
});
|
|
77
|
-
if (!isAccept && acceptList.length > 0) {
|
|
78
|
-
antd.message.error(`不支持的文件类型,仅支持 ${finalAccept}`);
|
|
79
|
-
return antd.Upload.LIST_IGNORE;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return true;
|
|
83
|
-
},
|
|
84
|
-
[finalLimit, finalAccept],
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const handleUploadChange = useCallback(
|
|
88
|
-
(info: UploadChangeParam<UploadFile>) => {
|
|
89
|
-
const { file, fileList: newFileList } = info;
|
|
90
|
-
|
|
91
|
-
let fileUrl = file.url;
|
|
92
|
-
if (file.response) {
|
|
93
|
-
fileUrl = file.response.file?.url || file.response.url;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 1. 状态提示
|
|
97
|
-
if (file.status === 'done') {
|
|
98
|
-
antd.message.success(`${file.name} 上传成功`);
|
|
99
|
-
file.url = fileUrl;
|
|
100
|
-
} else if (file.status === 'error') {
|
|
101
|
-
antd.message.error(`${file.name} 上传失败`);
|
|
102
|
-
file.status = 'error';
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let finalFileList = maxCount ? newFileList.slice(-maxCount) : newFileList;
|
|
106
|
-
|
|
107
|
-
finalFileList = finalFileList.map((item) => {
|
|
108
|
-
if (item.uid === file.uid) {
|
|
109
|
-
return { ...item, url: fileUrl, status: file.status };
|
|
110
|
-
}
|
|
111
|
-
return item;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
setFileList(finalFileList);
|
|
115
|
-
|
|
116
|
-
const simplifiedList = finalFileList.map((e: UploadFile) => ({
|
|
117
|
-
uid: e.uid,
|
|
118
|
-
name: e.name,
|
|
119
|
-
url: e.url || '',
|
|
120
|
-
status: e.status,
|
|
121
|
-
}));
|
|
122
|
-
handleChange?.(file, simplifiedList);
|
|
123
|
-
},
|
|
124
|
-
[maxCount, handleChange],
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const headers = useMemo(() => {
|
|
128
|
-
if (token) {
|
|
129
|
-
return { Authorization: `Bearer ${token}` };
|
|
130
|
-
}
|
|
131
|
-
return undefined;
|
|
132
|
-
}, [token]);
|
|
133
|
-
|
|
134
|
-
const getBase64 = (file: File): Promise<string> =>
|
|
135
|
-
new Promise((resolve, reject) => {
|
|
136
|
-
const reader = new FileReader();
|
|
137
|
-
reader.readAsDataURL(file);
|
|
138
|
-
reader.onload = () => resolve(reader.result as string);
|
|
139
|
-
reader.onerror = (error) => reject(error);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const handlePreview = useCallback(async (file: UploadFile) => {
|
|
143
|
-
if (!file.url && !file.preview && file.originFileObj) {
|
|
144
|
-
file.preview = await getBase64(file.originFileObj as File);
|
|
145
|
-
}
|
|
146
|
-
setPreviewImage(file.url || (file.preview as string));
|
|
147
|
-
setPreviewOpen(true);
|
|
148
|
-
}, []);
|
|
149
|
-
|
|
150
|
-
const avatarUploadButton = (
|
|
151
|
-
<button style={{ border: 0, background: 'none' }} type="button">
|
|
152
|
-
<CHRIcon icon="PlusOutlined" />
|
|
153
|
-
<div style={{ marginTop: 8 }}>上传</div>
|
|
154
|
-
</button>
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const renderByType = () => {
|
|
158
|
-
if (uploadType === 'avatar') {
|
|
159
|
-
return (
|
|
160
|
-
<>
|
|
161
|
-
<antd.Upload
|
|
162
|
-
name="file"
|
|
163
|
-
listType="picture-card"
|
|
164
|
-
className={className}
|
|
165
|
-
action={url}
|
|
166
|
-
headers={headers}
|
|
167
|
-
accept={finalAccept}
|
|
168
|
-
fileList={fileList}
|
|
169
|
-
beforeUpload={beforeUpload}
|
|
170
|
-
onChange={handleUploadChange}
|
|
171
|
-
onPreview={handlePreview}
|
|
172
|
-
maxCount={1}
|
|
173
|
-
{...restProps}
|
|
174
|
-
>
|
|
175
|
-
{fileList.length >= 1 ? null : avatarUploadButton}
|
|
176
|
-
</antd.Upload>
|
|
177
|
-
{previewImage && (
|
|
178
|
-
<Image
|
|
179
|
-
style={{ display: 'none' }}
|
|
180
|
-
preview={{
|
|
181
|
-
open: previewOpen,
|
|
182
|
-
onOpenChange: (visible) => setPreviewOpen(visible),
|
|
183
|
-
afterOpenChange: (visible) => !visible && setPreviewImage(''),
|
|
184
|
-
}}
|
|
185
|
-
src={previewImage}
|
|
186
|
-
/>
|
|
187
|
-
)}
|
|
188
|
-
</>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return (
|
|
193
|
-
<antd.Upload
|
|
194
|
-
className={className}
|
|
195
|
-
action={url}
|
|
196
|
-
headers={headers}
|
|
197
|
-
accept={finalAccept}
|
|
198
|
-
beforeUpload={beforeUpload}
|
|
199
|
-
fileList={fileList}
|
|
200
|
-
onChange={handleUploadChange}
|
|
201
|
-
maxCount={maxCount}
|
|
202
|
-
multiple={maxCount > 1}
|
|
203
|
-
{...restProps}
|
|
204
|
-
>
|
|
205
|
-
{children || (
|
|
206
|
-
<CHRButton>
|
|
207
|
-
<CHRIcon icon="UploadOutlined" />
|
|
208
|
-
上传文件
|
|
209
|
-
</CHRButton>
|
|
210
|
-
)}
|
|
211
|
-
</antd.Upload>
|
|
212
|
-
);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
return renderByType();
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export default CHRUpload;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
nav:
|
|
3
|
-
title: 基础组件
|
|
4
|
-
order: 0
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# 快速开始
|
|
8
|
-
|
|
9
|
-
:::code-group
|
|
10
|
-
|
|
11
|
-
```bash [npm]
|
|
12
|
-
npm install @kc-components
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
```bash [yarn]
|
|
16
|
-
yarn add @kc-components
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```bash [pnpm]
|
|
20
|
-
pnpm add @kc-components
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
:::
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES5",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"baseUrl": ".",
|
|
7
|
-
"paths": {
|
|
8
|
-
"@kc-components/*": ["packages/*/src"]
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
"jsx": "react-jsx",
|
|
12
|
-
"jsxImportSource": "react",
|
|
13
|
-
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"types": ["react", "react-dom"],
|
|
16
|
-
|
|
17
|
-
"strict": true,
|
|
18
|
-
"noImplicitAny": false,
|
|
19
|
-
"forceConsistentCasingInFileNames": true,
|
|
20
|
-
|
|
21
|
-
"esModuleInterop": true,
|
|
22
|
-
"allowSyntheticDefaultImports": true,
|
|
23
|
-
|
|
24
|
-
"sourceMap": true,
|
|
25
|
-
"inlineSources": true,
|
|
26
|
-
"importHelpers": false
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
/* 文件范围控制 */
|
|
30
|
-
"include": ["src/**/*"],
|
|
31
|
-
"exclude": ["node_modules", "dist", "es", "lib"]
|
|
32
|
-
}
|
package/packages/utils/README.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@chr/utils",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "通用方法",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"util"
|
|
7
|
-
],
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"sideEffects": false,
|
|
10
|
-
"main": "lib/index.js",
|
|
11
|
-
"unpkg": "dist/index.min.js",
|
|
12
|
-
"module": "es/index.js",
|
|
13
|
-
"types": "es/index.d.ts",
|
|
14
|
-
"files": [
|
|
15
|
-
"es",
|
|
16
|
-
"lib",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "rollup -c"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@rollup/plugin-commonjs": "^28.0.3",
|
|
24
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
25
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
26
|
-
"rollup": "^4.38.0",
|
|
27
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
28
|
-
"@chr/components": "workspace:*",
|
|
29
|
-
"alova": "catalog:"
|
|
30
|
-
},
|
|
31
|
-
"publishConfig": {
|
|
32
|
-
"access": "public",
|
|
33
|
-
"registry": "https://registry.npmjs.org/"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
3
|
-
import typescript from '@rollup/plugin-typescript';
|
|
4
|
-
import { defineConfig } from 'rollup';
|
|
5
|
-
import { terser } from 'rollup-plugin-terser';
|
|
6
|
-
|
|
7
|
-
const DIR_MAP = {
|
|
8
|
-
ESM: 'es',
|
|
9
|
-
CJS: 'lib',
|
|
10
|
-
UMD: 'dist',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const baseConfig = (tsConfig) => ({
|
|
14
|
-
input: 'src/index.ts',
|
|
15
|
-
plugins: [
|
|
16
|
-
nodeResolve({ extensions: ['.ts'] }),
|
|
17
|
-
commonjs(),
|
|
18
|
-
typescript(tsConfig),
|
|
19
|
-
],
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const esmConfig = defineConfig({
|
|
23
|
-
...baseConfig({
|
|
24
|
-
declaration: true,
|
|
25
|
-
declarationDir: DIR_MAP.ESM,
|
|
26
|
-
}),
|
|
27
|
-
output: {
|
|
28
|
-
dir: DIR_MAP.ESM,
|
|
29
|
-
format: 'esm',
|
|
30
|
-
preserveModules: true,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const cjsConfig = defineConfig({
|
|
35
|
-
...baseConfig({
|
|
36
|
-
declaration: true,
|
|
37
|
-
declarationDir: DIR_MAP.CJS,
|
|
38
|
-
}),
|
|
39
|
-
output: {
|
|
40
|
-
dir: DIR_MAP.CJS,
|
|
41
|
-
format: 'cjs',
|
|
42
|
-
exports: 'named',
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const umdConfig = defineConfig({
|
|
47
|
-
...baseConfig(),
|
|
48
|
-
output: [
|
|
49
|
-
{
|
|
50
|
-
file: DIR_MAP.UMD + '/index.js',
|
|
51
|
-
format: 'umd',
|
|
52
|
-
name: 'KcUtils',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
file: DIR_MAP.UMD + '/index.min.js',
|
|
56
|
-
format: 'umd',
|
|
57
|
-
name: 'KcUtils',
|
|
58
|
-
plugins: [terser()],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export default defineConfig([esmConfig, cjsConfig, umdConfig]);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# CHRRequest
|
|
2
|
-
|
|
3
|
-
## 代码演示
|
|
4
|
-
|
|
5
|
-
### 基本用法
|
|
6
|
-
|
|
7
|
-
```jsx
|
|
8
|
-
import { alovaGet, useRequest } from '@chr/utils';
|
|
9
|
-
import { CHRButton } from '@chr/components';
|
|
10
|
-
|
|
11
|
-
export default function PostExample() {
|
|
12
|
-
const { loading, data, error, send } = useRequest(
|
|
13
|
-
() =>
|
|
14
|
-
alovaGet('/api/dd', {
|
|
15
|
-
meta: {
|
|
16
|
-
ignoreAuth: true,
|
|
17
|
-
},
|
|
18
|
-
}),
|
|
19
|
-
{
|
|
20
|
-
immediate: false,
|
|
21
|
-
initialData: {},
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (!data.id) {
|
|
26
|
-
return (
|
|
27
|
-
<div>
|
|
28
|
-
<CHRButton onClick={() => send()}>请求</CHRButton>
|
|
29
|
-
{loading && <div>加载中...</div>}
|
|
30
|
-
{error && <div>加载失败:{error.message}</div>}
|
|
31
|
-
</div>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 有数据时展示详情
|
|
36
|
-
return (
|
|
37
|
-
<div>
|
|
38
|
-
<CHRButton onClick={() => send()}>请求</CHRButton>
|
|
39
|
-
<h2>文章详情</h2>
|
|
40
|
-
<p>
|
|
41
|
-
<strong>ID:</strong>
|
|
42
|
-
{data.id}
|
|
43
|
-
</p>
|
|
44
|
-
<p>
|
|
45
|
-
<strong>用户ID:</strong>
|
|
46
|
-
{data.userId}
|
|
47
|
-
</p>
|
|
48
|
-
<p>
|
|
49
|
-
<strong>标题:</strong>
|
|
50
|
-
{data.title}
|
|
51
|
-
</p>
|
|
52
|
-
<p>
|
|
53
|
-
<strong>内容:</strong>
|
|
54
|
-
</p>
|
|
55
|
-
<p>{data.body}</p>
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
```
|