@quansitech/antd-admin 1.0.0 → 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.
Files changed (41) 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 +176 -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 +280 -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/lib/writeExtra.js +31 -0
  39. package/package.json +2 -6
  40. package/readme.md +151 -128
  41. 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
+ }
@@ -0,0 +1,31 @@
1
+ import fs from "node:fs"
2
+ import path from "node:path"
3
+ import * as process from "node:process";
4
+
5
+ export default function () {
6
+ // 分析额外组件
7
+ if (!fs.existsSync(process.cwd() + '/vendor')) {
8
+ throw new Error('Please run `composer install` first.');
9
+ }
10
+
11
+ const installed = JSON.parse(fs.readFileSync(process.cwd() + '/vendor/composer/installed.json'))
12
+ const extras = installed.packages.filter(p => !!p.extra?.qscmf?.['antd-admin']).map(p => ({
13
+ name: p.name,
14
+ path: p['install-path'],
15
+ component: p.extra.qscmf['antd-admin'].component,
16
+ }));
17
+
18
+ const extra_script = `
19
+ import container from "@quansitech/antd-admin/lib/container.ts";
20
+
21
+ ${extras.map(e => {
22
+ const cs = [];
23
+ for (const componentKey in e.component) {
24
+ cs.push(`container.register('${componentKey}', () => import('../../../vendor${path.join('/', e.path, e.component[componentKey])}'));`)
25
+ }
26
+ return cs.join('\n');
27
+ })}
28
+ `
29
+
30
+ fs.writeFileSync(process.cwd() + '/resources/js/backend/extra.ts', extra_script);
31
+ }
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@quansitech/antd-admin",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",