@quansitech/antd-admin 1.0.0 → 1.0.1

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.
Files changed (40) hide show
  1. package/components/Column/Cascader.tsx +78 -78
  2. package/components/Column/File.tsx +165 -167
  3. package/components/Column/Image.tsx +76 -76
  4. package/components/{Table/Option → Column/Readonly/Action}/Link.tsx +77 -67
  5. package/components/{Table/Option → Column/Readonly/Action}/types.d.ts +5 -4
  6. package/components/Column/Readonly/Action.tsx +80 -0
  7. package/components/Column/Readonly/Cascader.tsx +50 -50
  8. package/components/Column/Readonly/File.tsx +52 -53
  9. package/components/Column/Readonly/Image.tsx +38 -77
  10. package/components/Column/Readonly/Ueditor.tsx +18 -0
  11. package/components/Column/Readonly/types.d.ts +9 -8
  12. package/components/Column/Ueditor.tsx +313 -313
  13. package/components/Column/types.d.ts +29 -28
  14. package/components/Form/Action/Button.tsx +128 -124
  15. package/components/Form/Action/types.d.ts +5 -4
  16. package/components/Form/Actions.tsx +38 -34
  17. package/components/Form.tsx +179 -170
  18. package/components/FormContext.ts +8 -7
  19. package/components/Layout/New.tsx +252 -0
  20. package/components/Layout.tsx +52 -237
  21. package/components/LayoutContext.ts +25 -25
  22. package/components/ModalContext.ts +15 -15
  23. package/components/Table/Action/Button.tsx +88 -88
  24. package/components/Table/Action/StartEditable.tsx +58 -58
  25. package/components/Table/Action/types.d.ts +7 -6
  26. package/components/Table/ToolbarActions.tsx +43 -38
  27. package/components/Table.scss +4 -7
  28. package/components/Table.tsx +283 -279
  29. package/components/TableContext.ts +14 -13
  30. package/components/Tabs.tsx +71 -71
  31. package/lib/container.ts +83 -81
  32. package/lib/customRule.ts +9 -9
  33. package/lib/global.ts +10 -10
  34. package/lib/helpers.tsx +145 -149
  35. package/lib/http.ts +73 -73
  36. package/lib/schemaHandler.ts +121 -121
  37. package/lib/upload.ts +177 -177
  38. package/package.json +2 -6
  39. package/readme.md +128 -128
  40. package/components/Column/Readonly/Option.tsx +0 -58
package/lib/upload.ts CHANGED
@@ -1,177 +1,177 @@
1
- import http from "./http";
2
- import {AxiosError} from "axios";
3
- import {UploadRequestOption} from "rc-upload/lib/interface";
4
- import {GetProp, message, Upload, UploadFile, UploadProps} from "antd";
5
- import {md5} from "js-md5"
6
-
7
- type QsUploadFile = UploadFile & {
8
- hash_id?: string,
9
- }
10
-
11
- export async function customRequest(options: UploadRequestOption & {
12
- file: QsUploadFile
13
- }) {
14
- const policyRes = await http({
15
- url: options.action,
16
- method: 'get',
17
- headers: options.headers,
18
- fetchOptions: {
19
- noHandle: true
20
- },
21
- params: {
22
- title: options.file.name,
23
- hash_id: options.file.hash_id,
24
- file_type: options.file?.type || '' as string
25
- }
26
- })
27
- if (policyRes.data.status) {
28
- options.onSuccess && options.onSuccess({
29
- ...policyRes.data,
30
- url: policyRes.data.url || policyRes.data.file_url
31
- })
32
- return
33
- }
34
-
35
- const formData = new FormData();
36
- let url = ''
37
- if (policyRes.data.server_url) {
38
- url = policyRes.data.server_url
39
- } else if (policyRes.data.url) {
40
- url = policyRes.data.url
41
- }
42
- if (policyRes.data.params) {
43
- for (const key in policyRes.data.params) {
44
- formData.append(key, policyRes.data.params[key])
45
- }
46
- }
47
-
48
- formData.append('file', options.file)
49
- try {
50
- const res = await http({
51
- url: url,
52
- method: 'post',
53
- data: formData,
54
- fetchOptions: {
55
- noHandle: true
56
- },
57
- headers: options.headers,
58
- onUploadProgress(ev) {
59
- options.onProgress && options.onProgress({
60
- percent: (ev.progress || 0) * 100
61
- })
62
- },
63
- })
64
-
65
- if (res.data.info) {
66
- message.error(res.data.info)
67
- options.onError && options.onError(new Error(res.data.info), res.data)
68
- return
69
- }
70
-
71
- options.onSuccess && options.onSuccess({
72
- ...res.data,
73
- url: res.data.url || res.data.file_url
74
- })
75
- } catch (e) {
76
- if (e instanceof AxiosError) {
77
- options.onError && options.onError(e, e.response?.data)
78
- }
79
- if (e instanceof Error) {
80
- options.onError && options.onError({
81
- name: e.name,
82
- message: e.message,
83
- method: options.method,
84
- url: options.action
85
- })
86
- }
87
- throw e
88
- }
89
- }
90
-
91
- export type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
92
-
93
- export function getBase64(file: FileType): Promise<string> {
94
- return new Promise((resolve, reject) => {
95
- const reader = new FileReader();
96
- reader.readAsDataURL(file);
97
- reader.onload = () => resolve(reader.result as string);
98
- reader.onerror = (error) => reject(error);
99
- })
100
- }
101
-
102
- /**
103
- * 计算文件MD5
104
- * https://github.com/quansitech/file-md5-wasm/blob/master/js/calc_file_hash.js
105
- * @param file
106
- */
107
- export function calc_file_hash(file: File) {
108
- const MD5_RANGE_SIZE = 10 * 1024 * 1024;
109
- const CUT_LIMIT = 40 * 1024 * 1024;
110
-
111
- function makeMd5Range(fileSize: number) {
112
- if (CUT_LIMIT > fileSize) {
113
- return [[0, fileSize]];
114
- }
115
-
116
- // MD5_RANGE_SIZE设置为10
117
- const first = [0.0, MD5_RANGE_SIZE];
118
- const last = [fileSize - MD5_RANGE_SIZE, fileSize];
119
-
120
- // 中间段算法
121
- const rangeMod = fileSize - 3.0 * MD5_RANGE_SIZE;
122
- const midStart = fileSize % rangeMod;
123
- const middle = [MD5_RANGE_SIZE + midStart, MD5_RANGE_SIZE + midStart + MD5_RANGE_SIZE];
124
-
125
- return [first, middle, last];
126
- }
127
-
128
- return new Promise<string>(function (resolve, reject) {
129
- const fileSize = file.size;
130
- const range = makeMd5Range(fileSize);
131
-
132
- let index = 0;
133
- const hash = md5.create();// 创建MD5哈希对象
134
-
135
- const reader = new FileReader();
136
-
137
- reader.onload = function (e) {
138
- // 处理当前分块的读取结果
139
- const chunkData = e.target?.result;
140
-
141
- hash.update(chunkData as string); // 更新哈希计算结果
142
-
143
- if (index < range.length - 1) {
144
- index++;
145
- readNextChunk(range, index);
146
- } else {
147
- const fileMD5 = hash.hex(); // 计算文件的最终MD5哈希值
148
-
149
- resolve(fileMD5);
150
- }
151
- };
152
-
153
- reader.onerror = function (e) {
154
- reject(e);
155
-
156
- };
157
-
158
- function readNextChunk(chunkRange: number[][], index: number) {
159
- const chunk = file.slice(chunkRange[index][0], chunkRange[index][1]);
160
- reader.readAsArrayBuffer(chunk);
161
- }
162
-
163
- readNextChunk(range, index);
164
- });
165
-
166
- }
167
-
168
- export async function beforeUpload(file: File & {
169
- hash_id?: string,
170
- }, fileList: UploadFile[], allFileList: UploadFile[]) {
171
- file.hash_id = await calc_file_hash(file)
172
- const f = allFileList.filter((item: QsUploadFile) => !!item.hash_id).find((item: QsUploadFile) => item.hash_id === file.hash_id)
173
- if (f) {
174
- message.error(file.name + '文件已上传')
175
- return Upload.LIST_IGNORE
176
- }
177
- }
1
+ import http from "./http";
2
+ import {AxiosError} from "axios";
3
+ import {UploadRequestOption} from "rc-upload/lib/interface";
4
+ import {GetProp, message, Upload, UploadFile, UploadProps} from "antd";
5
+ import {md5} from "js-md5"
6
+
7
+ type QsUploadFile = UploadFile & {
8
+ hash_id?: string,
9
+ }
10
+
11
+ export async function customRequest(options: UploadRequestOption & {
12
+ file: QsUploadFile
13
+ }) {
14
+ const policyRes = await http({
15
+ url: options.action,
16
+ method: 'get',
17
+ headers: options.headers,
18
+ fetchOptions: {
19
+ noHandle: true
20
+ },
21
+ params: {
22
+ title: options.file.name,
23
+ hash_id: options.file.hash_id,
24
+ file_type: options.file?.type || '' as string
25
+ }
26
+ })
27
+ if (policyRes.data.status) {
28
+ options.onSuccess && options.onSuccess({
29
+ ...policyRes.data,
30
+ url: policyRes.data.url || policyRes.data.file_url
31
+ })
32
+ return
33
+ }
34
+
35
+ const formData = new FormData();
36
+ let url = ''
37
+ if (policyRes.data.server_url) {
38
+ url = policyRes.data.server_url
39
+ } else if (policyRes.data.url) {
40
+ url = policyRes.data.url
41
+ }
42
+ if (policyRes.data.params) {
43
+ for (const key in policyRes.data.params) {
44
+ formData.append(key, policyRes.data.params[key])
45
+ }
46
+ }
47
+
48
+ formData.append('file', options.file)
49
+ try {
50
+ const res = await http({
51
+ url: url,
52
+ method: 'post',
53
+ data: formData,
54
+ fetchOptions: {
55
+ noHandle: true
56
+ },
57
+ headers: options.headers,
58
+ onUploadProgress(ev) {
59
+ options.onProgress && options.onProgress({
60
+ percent: (ev.progress || 0) * 100
61
+ })
62
+ },
63
+ })
64
+
65
+ if (res.data.info) {
66
+ message.error(res.data.info)
67
+ options.onError && options.onError(new Error(res.data.info), res.data)
68
+ return
69
+ }
70
+
71
+ options.onSuccess && options.onSuccess({
72
+ ...res.data,
73
+ url: res.data.url || res.data.file_url
74
+ })
75
+ } catch (e) {
76
+ if (e instanceof AxiosError) {
77
+ options.onError && options.onError(e, e.response?.data)
78
+ }
79
+ if (e instanceof Error) {
80
+ options.onError && options.onError({
81
+ name: e.name,
82
+ message: e.message,
83
+ method: options.method,
84
+ url: options.action
85
+ })
86
+ }
87
+ throw e
88
+ }
89
+ }
90
+
91
+ export type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
92
+
93
+ export function getBase64(file: FileType): Promise<string> {
94
+ return new Promise((resolve, reject) => {
95
+ const reader = new FileReader();
96
+ reader.readAsDataURL(file);
97
+ reader.onload = () => resolve(reader.result as string);
98
+ reader.onerror = (error) => reject(error);
99
+ })
100
+ }
101
+
102
+ /**
103
+ * 计算文件MD5
104
+ * https://github.com/quansitech/file-md5-wasm/blob/master/js/calc_file_hash.js
105
+ * @param file
106
+ */
107
+ export function calc_file_hash(file: File) {
108
+ const MD5_RANGE_SIZE = 10 * 1024 * 1024;
109
+ const CUT_LIMIT = 40 * 1024 * 1024;
110
+
111
+ function makeMd5Range(fileSize: number) {
112
+ if (CUT_LIMIT > fileSize) {
113
+ return [[0, fileSize]];
114
+ }
115
+
116
+ // MD5_RANGE_SIZE设置为10
117
+ const first = [0.0, MD5_RANGE_SIZE];
118
+ const last = [fileSize - MD5_RANGE_SIZE, fileSize];
119
+
120
+ // 中间段算法
121
+ const rangeMod = fileSize - 3.0 * MD5_RANGE_SIZE;
122
+ const midStart = fileSize % rangeMod;
123
+ const middle = [MD5_RANGE_SIZE + midStart, MD5_RANGE_SIZE + midStart + MD5_RANGE_SIZE];
124
+
125
+ return [first, middle, last];
126
+ }
127
+
128
+ return new Promise<string>(function (resolve, reject) {
129
+ const fileSize = file.size;
130
+ const range = makeMd5Range(fileSize);
131
+
132
+ let index = 0;
133
+ const hash = md5.create();// 创建MD5哈希对象
134
+
135
+ const reader = new FileReader();
136
+
137
+ reader.onload = function (e) {
138
+ // 处理当前分块的读取结果
139
+ const chunkData = e.target?.result;
140
+
141
+ hash.update(chunkData as string); // 更新哈希计算结果
142
+
143
+ if (index < range.length - 1) {
144
+ index++;
145
+ readNextChunk(range, index);
146
+ } else {
147
+ const fileMD5 = hash.hex(); // 计算文件的最终MD5哈希值
148
+
149
+ resolve(fileMD5);
150
+ }
151
+ };
152
+
153
+ reader.onerror = function (e) {
154
+ reject(e);
155
+
156
+ };
157
+
158
+ function readNextChunk(chunkRange: number[][], index: number) {
159
+ const chunk = file.slice(chunkRange[index][0], chunkRange[index][1]);
160
+ reader.readAsArrayBuffer(chunk);
161
+ }
162
+
163
+ readNextChunk(range, index);
164
+ });
165
+
166
+ }
167
+
168
+ export async function beforeUpload(file: File & {
169
+ hash_id?: string,
170
+ }, fileList: UploadFile[], allFileList: UploadFile[]) {
171
+ file.hash_id = await calc_file_hash(file)
172
+ const f = allFileList.filter((item: QsUploadFile) => !!item.hash_id).find((item: QsUploadFile) => item.hash_id === file.hash_id)
173
+ if (f) {
174
+ message.error(file.name + '文件已上传')
175
+ return Upload.LIST_IGNORE
176
+ }
177
+ }
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@quansitech/antd-admin",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
7
- },
8
5
  "files": [
9
6
  "components",
10
7
  "lib"
@@ -18,8 +15,7 @@
18
15
  "lodash": "^4.17.21",
19
16
  "react": "^18.3.0",
20
17
  "react-dom": "^18.3.0",
21
- "js-md5": "^0.8.3",
22
- "prettier": "^3.3.3"
18
+ "js-md5": "^0.8.3"
23
19
  },
24
20
  "devDependencies": {
25
21
  "@types/lodash": "^4.14.193",
package/readme.md CHANGED
@@ -1,128 +1,128 @@
1
- # Qs-antd-admin
2
-
3
- 该项目作为qs-cmf的后台前端组件库,基于[ant-design-pro](https://procomponents.ant.design/components)
4
-
5
- ## 安装
6
-
7
- ```shell
8
- npm install @quansitech/antd-admin
9
- ```
10
-
11
- ## 使用参考
12
-
13
- ### valueType列表
14
-
15
- 参考 [ant-design-pro#valueType](https://procomponents.ant.design/components/schema#valuetype-%E5%88%97%E8%A1%A8)
16
-
17
- ## 自定义组件
18
-
19
- 对外暴露 [container](./lib/container.ts) 供外部调用
20
-
21
- ```ts
22
- import container from "@quansitech/antd-admin/lib/container";
23
-
24
- container.register('[组件名]', () => import('[组件路径]'));
25
- ```
26
-
27
- ### 通用
28
-
29
- #### 通用Column Schema
30
-
31
- - 组件名前缀:``` Column. ```
32
- - 用途:表单项组件(非只读模式)、表格列编辑组件、表格搜索项组件
33
- - 示例:
34
-
35
- ```tsx
36
- // [组件.tsx]
37
- import {ColumnProps} from "@quansitech/antd-admin/compontents/Column/types";
38
-
39
- export default function (props: ColumnProps) {
40
-
41
- return <>
42
- 组件内容
43
- </>
44
- }
45
-
46
- // [app.tsx]
47
- import container from "@quansitech/antd-admin/lib/container";
48
-
49
- container.register('Column.组件名', () => import('[组件路径]'));
50
- ```
51
-
52
- - 若要补充组件库,请把组件放``` compontents/Column/ ``` 目录下
53
-
54
- #### 只读Column Schema
55
-
56
- - 组件名前缀:``` Column.Readonly. ```
57
- - 用途:表单项组件(只读模式)、表格列组件
58
- - 示例:
59
-
60
- ```tsx
61
- // [组件.tsx]
62
- import {ColumnProps} from "@quansitech/antd-admin/compontents/Column/Readonly/types";
63
-
64
- export default function (props: ColumnProps) {
65
-
66
- return <>
67
- 组件内容
68
- </>
69
- }
70
-
71
- // [app.tsx]
72
- import container from "@quansitech/antd-admin/lib/container";
73
-
74
- container.register('Column.Readonly.组件名', () => import('[组件路径]'));
75
- ```
76
-
77
- - 若要补充组件库,请把组件放``` compontents/Column/Readonly/ ``` 目录下
78
-
79
- ### 表格Table
80
-
81
- #### 工具栏操作组件
82
-
83
- - 组件名前缀:``` Table.Column.Action. ```
84
- - 示例:
85
-
86
- ```tsx
87
- // [组件.tsx]
88
-
89
- import {TableActionProps} from "@quansitech/antd-admin/compontents/Table/Action/types";
90
-
91
- export default function (props: TableActionProps) {
92
- return <Button>{props.title}</Button>
93
- }
94
-
95
- // [app.tsx]
96
-
97
- import container from "@quansitech/antd-admin/lib/container";
98
-
99
- container.register('Table.Column.Action.组件名', () => import('[组件路径]'));
100
-
101
- ```
102
-
103
- - 若要补充组件库,请把组件放``` compontents/Table/Action/ ``` 目录下
104
-
105
- #### 行操作组件
106
-
107
- - 组件名前缀:``` Table.Column.Option ```
108
- - 示例:
109
-
110
- ```tsx
111
- // [组件.tsx]
112
-
113
- import {TableColumnOptionProps} from "@quansitech/antd-admin/compontents/Table/Column/Option/types";
114
-
115
- export default function (props: TableColumnOptionProps) {
116
- <a onClick={onClick}>{props.title}</a>
117
- }
118
-
119
- // [app.tsx]
120
-
121
- import container from "@quansitech/antd-admin/lib/container";
122
-
123
- container.register('Table.Column.Option.组件名', () => import('[组件路径]'));
124
-
125
- ```
126
-
127
- - 若要补充组件库,请把组件放``` compontents/Table/Column/Option/ ``` 目录下
128
-
1
+ # Qs-antd-admin
2
+
3
+ 该项目作为qs-cmf的后台前端组件库,基于[ant-design-pro](https://procomponents.ant.design/components)
4
+
5
+ ## 安装
6
+
7
+ ```shell
8
+ npm install @quansitech/antd-admin
9
+ ```
10
+
11
+ ## 使用参考
12
+
13
+ ### valueType列表
14
+
15
+ 参考 [ant-design-pro#valueType](https://procomponents.ant.design/components/schema#valuetype-%E5%88%97%E8%A1%A8)
16
+
17
+ ## 自定义组件
18
+
19
+ 对外暴露 [container](./lib/container.ts) 供外部调用
20
+
21
+ ```ts
22
+ import container from "@quansitech/antd-admin/lib/container";
23
+
24
+ container.register('[组件名]', () => import('[组件路径]'));
25
+ ```
26
+
27
+ ### 通用
28
+
29
+ #### 通用Column Schema
30
+
31
+ - 组件名前缀:``` Column. ```
32
+ - 用途:表单项组件(非只读模式)、表格列编辑组件、表格搜索项组件
33
+ - 示例:
34
+
35
+ ```tsx
36
+ // [组件.tsx]
37
+ import {ColumnProps} from "@quansitech/antd-admin/compontents/Column/types";
38
+
39
+ export default function (props: ColumnProps) {
40
+
41
+ return <>
42
+ 组件内容
43
+ </>
44
+ }
45
+
46
+ // [app.tsx]
47
+ import container from "@quansitech/antd-admin/lib/container";
48
+
49
+ container.register('Column.组件名', () => import('[组件路径]'));
50
+ ```
51
+
52
+ - 若要补充组件库,请把组件放``` compontents/Column/ ``` 目录下
53
+
54
+ #### 只读Column Schema
55
+
56
+ - 组件名前缀:``` Column.Readonly. ```
57
+ - 用途:表单项组件(只读模式)、表格列组件
58
+ - 示例:
59
+
60
+ ```tsx
61
+ // [组件.tsx]
62
+ import {ColumnProps} from "@quansitech/antd-admin/compontents/Column/Readonly/types";
63
+
64
+ export default function (props: ColumnProps) {
65
+
66
+ return <>
67
+ 组件内容
68
+ </>
69
+ }
70
+
71
+ // [app.tsx]
72
+ import container from "@quansitech/antd-admin/lib/container";
73
+
74
+ container.register('Column.Readonly.组件名', () => import('[组件路径]'));
75
+ ```
76
+
77
+ - 若要补充组件库,请把组件放``` compontents/Column/Readonly/ ``` 目录下
78
+
79
+ ### 表格Table
80
+
81
+ #### 工具栏操作组件
82
+
83
+ - 组件名前缀:``` Table.Column.Action. ```
84
+ - 示例:
85
+
86
+ ```tsx
87
+ // [组件.tsx]
88
+
89
+ import {TableActionProps} from "@quansitech/antd-admin/compontents/Table/Action/types";
90
+
91
+ export default function (props: TableActionProps) {
92
+ return <Button>{props.title}</Button>
93
+ }
94
+
95
+ // [app.tsx]
96
+
97
+ import container from "@quansitech/antd-admin/lib/container";
98
+
99
+ container.register('Table.Column.Action.组件名', () => import('[组件路径]'));
100
+
101
+ ```
102
+
103
+ - 若要补充组件库,请把组件放``` compontents/Table/Action/ ``` 目录下
104
+
105
+ #### 行操作组件
106
+
107
+ - 组件名前缀:``` Table.Column.Option ```
108
+ - 示例:
109
+
110
+ ```tsx
111
+ // [组件.tsx]
112
+
113
+ import {TableColumnOptionProps} from "@quansitech/antd-admin/compontents/Column/Readonly/Action/types";
114
+
115
+ export default function (props: TableColumnOptionProps) {
116
+ <a onClick={onClick}>{props.title}</a>
117
+ }
118
+
119
+ // [app.tsx]
120
+
121
+ import container from "@quansitech/antd-admin/lib/container";
122
+
123
+ container.register('Column.Readonly.Action.组件名', () => import('[组件路径]'));
124
+
125
+ ```
126
+
127
+ - 若要补充组件库,请把组件放``` compontents/Column/Readonly/Action/ ``` 目录下
128
+