@ibiz-template/core 0.0.1-beta.1 → 0.0.1-beta.130

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 (64) hide show
  1. package/dist/system/index.system.js +1 -1
  2. package/out/constant/core/core.d.ts +9 -0
  3. package/out/constant/core/core.d.ts.map +1 -1
  4. package/out/constant/core/core.js +9 -0
  5. package/out/context/index.d.ts +63 -4
  6. package/out/context/index.d.ts.map +1 -1
  7. package/out/context/index.js +73 -3
  8. package/out/environment/environment.d.ts.map +1 -1
  9. package/out/environment/environment.js +5 -0
  10. package/out/error/http-error/http-error.d.ts.map +1 -1
  11. package/out/error/http-error/http-error.js +0 -4
  12. package/out/interface/click-outside/click-outside.d.ts +1 -1
  13. package/out/interface/click-outside/click-outside.d.ts.map +1 -1
  14. package/out/interface/i-environment/i-environment.d.ts +36 -0
  15. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  16. package/out/types.d.ts +31 -0
  17. package/out/types.d.ts.map +1 -1
  18. package/out/utils/download-file/download-file.d.ts +10 -0
  19. package/out/utils/download-file/download-file.d.ts.map +1 -1
  20. package/out/utils/download-file/download-file.js +20 -0
  21. package/out/utils/index.d.ts +4 -0
  22. package/out/utils/index.d.ts.map +1 -1
  23. package/out/utils/index.js +4 -0
  24. package/out/utils/net/net.d.ts +18 -1
  25. package/out/utils/net/net.d.ts.map +1 -1
  26. package/out/utils/net/net.js +29 -3
  27. package/out/utils/plural/plural.d.ts.map +1 -1
  28. package/out/utils/plural/plural.js +2 -0
  29. package/out/utils/string-util/string-util.d.ts +46 -0
  30. package/out/utils/string-util/string-util.d.ts.map +1 -0
  31. package/out/utils/string-util/string-util.js +71 -0
  32. package/out/utils/sync/await-timeout.d.ts +14 -0
  33. package/out/utils/sync/await-timeout.d.ts.map +1 -0
  34. package/out/utils/sync/await-timeout.js +23 -0
  35. package/out/utils/sync/count-latch.d.ts +60 -0
  36. package/out/utils/sync/count-latch.d.ts.map +1 -0
  37. package/out/utils/sync/count-latch.js +90 -0
  38. package/out/utils/sync/index.d.ts +3 -0
  39. package/out/utils/sync/index.d.ts.map +1 -0
  40. package/out/utils/sync/index.js +2 -0
  41. package/out/utils/upload/select-file.d.ts +53 -0
  42. package/out/utils/upload/select-file.d.ts.map +1 -0
  43. package/out/utils/upload/select-file.js +47 -0
  44. package/out/utils/upload/upload-file.d.ts +46 -0
  45. package/out/utils/upload/upload-file.d.ts.map +1 -0
  46. package/out/utils/upload/upload-file.js +150 -0
  47. package/package.json +7 -6
  48. package/src/constant/core/core.ts +10 -0
  49. package/src/context/index.ts +115 -5
  50. package/src/environment/environment.ts +5 -0
  51. package/src/error/http-error/http-error.ts +0 -4
  52. package/src/interface/i-environment/i-environment.ts +41 -0
  53. package/src/types.ts +35 -0
  54. package/src/utils/download-file/download-file.ts +21 -0
  55. package/src/utils/index.ts +4 -0
  56. package/src/utils/net/net.ts +31 -3
  57. package/src/utils/plural/plural.ts +3 -0
  58. package/src/utils/string-util/string-util.ts +75 -0
  59. package/src/utils/sync/await-timeout.ts +27 -0
  60. package/src/utils/sync/count-latch.ts +96 -0
  61. package/src/utils/sync/index.ts +2 -0
  62. package/src/utils/upload/select-file.ts +86 -0
  63. package/src/utils/upload/upload-file.ts +206 -0
  64. package/LICENSE +0 -21
@@ -3,6 +3,7 @@ import { merge } from 'lodash-es';
3
3
  import { stringify } from 'qs';
4
4
  import { notNilEmpty } from 'qx-util';
5
5
  import { HttpError } from '../../error';
6
+ import { CoreInterceptor } from '../interceptor';
6
7
  /**
7
8
  * 全局请求工具类
8
9
  *
@@ -19,6 +20,14 @@ export class Net {
19
20
  * @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
20
21
  */
21
22
  constructor(config) {
23
+ /**
24
+ * 是否为 http || https 开头
25
+ *
26
+ * @author chitanda
27
+ * @date 2022-11-07 14:11:28
28
+ * @protected
29
+ */
30
+ this.urlReg = /^http[s]?:\/\/[^\s]*/;
22
31
  /**
23
32
  * 注册的拦截器
24
33
  *
@@ -28,6 +37,7 @@ export class Net {
28
37
  */
29
38
  this.interceptors = new Map();
30
39
  this.instance = axios.create(config);
40
+ this.addInterceptor('Default', new CoreInterceptor());
31
41
  }
32
42
  /**
33
43
  * 添加拦截器
@@ -67,7 +77,7 @@ export class Net {
67
77
  get presetConfig() {
68
78
  return {
69
79
  // 请求前缀路径
70
- baseURL: this.instance.defaults.baseURL || ibiz.env.baseUrl,
80
+ baseURL: ibiz.env.baseUrl,
71
81
  headers: {
72
82
  'Content-Type': 'application/json;charset=UTF-8',
73
83
  Accept: 'application/json',
@@ -84,10 +94,15 @@ export class Net {
84
94
  * @returns {*}
85
95
  */
86
96
  mergeConfig(...configs) {
97
+ const config = this.presetConfig;
87
98
  if (configs.length === 0) {
88
- return this.presetConfig;
99
+ return config;
89
100
  }
90
- return merge(this.presetConfig, ...configs);
101
+ const { url } = configs[0];
102
+ if (url && this.urlReg.test(url)) {
103
+ delete config.baseURL;
104
+ }
105
+ return merge(config, ...configs);
91
106
  }
92
107
  /**
93
108
  * Post 请求
@@ -222,6 +237,17 @@ export class Net {
222
237
  throw new HttpError(error);
223
238
  }
224
239
  }
240
+ /**
241
+ * 创建标准 axios 请求
242
+ *
243
+ * @author chitanda
244
+ * @date 2023-01-30 15:01:27
245
+ * @param {AxiosRequestConfig<IData>} config
246
+ * @return {*}
247
+ */
248
+ axios(config) {
249
+ return axios(config);
250
+ }
225
251
  /**
226
252
  * 统一处理请求返回
227
253
  *
@@ -1 +1 @@
1
- {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C"}
1
+ {"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../../src/utils/plural/plural.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C"}
@@ -1,4 +1,6 @@
1
1
  import pluralize from 'pluralize';
2
+ // 补充特殊转换规则
3
+ pluralize.addPluralRule(/(matr|vert|ind)ix|ex$/, '$1ices');
2
4
  /**
3
5
  * 英文转复数写法
4
6
  *
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 字符串工具类
3
+ *
4
+ * @author chitanda
5
+ * @date 2021-04-23 20:04:27
6
+ * @export
7
+ * @class StringUtil
8
+ */
9
+ export declare class StringUtil {
10
+ /**
11
+ * 上下文替换正则
12
+ *
13
+ * @author chitanda
14
+ * @date 2021-04-23 20:04:01
15
+ * @static
16
+ */
17
+ static contextReg: RegExp;
18
+ /**
19
+ * 数据替换正则
20
+ *
21
+ * @author chitanda
22
+ * @date 2021-04-23 20:04:09
23
+ * @static
24
+ */
25
+ static dataReg: RegExp;
26
+ /**
27
+ * 填充字符串中的数据
28
+ *
29
+ * @author chitanda
30
+ * @date 2021-04-23 20:04:17
31
+ * @static
32
+ * @param {string} str
33
+ * @param {*} [context]
34
+ * @param {*} [data]
35
+ * @return {*} {string}
36
+ */
37
+ static fill(str: string, context?: IContext, data?: IData): string;
38
+ /**
39
+ * 动态匹配${}
40
+ *
41
+ * @param str
42
+ * @param values
43
+ */
44
+ static dynamicMatch(str: string, values: any): string;
45
+ }
46
+ //# sourceMappingURL=string-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-util.d.ts","sourceRoot":"","sources":["../../../src/utils/string-util/string-util.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,SAAgD;IAEjE;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,SAA6C;IAE3D;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM;IAoBlE;;;;;OAKG;IAEH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,MAAM;CAOtD"}
@@ -0,0 +1,71 @@
1
+ import { notNilEmpty } from 'qx-util';
2
+ /**
3
+ * 字符串工具类
4
+ *
5
+ * @author chitanda
6
+ * @date 2021-04-23 20:04:27
7
+ * @export
8
+ * @class StringUtil
9
+ */
10
+ export class StringUtil {
11
+ /**
12
+ * 填充字符串中的数据
13
+ *
14
+ * @author chitanda
15
+ * @date 2021-04-23 20:04:17
16
+ * @static
17
+ * @param {string} str
18
+ * @param {*} [context]
19
+ * @param {*} [data]
20
+ * @return {*} {string}
21
+ */
22
+ static fill(str, context, data) {
23
+ if (notNilEmpty(str)) {
24
+ if (notNilEmpty(context)) {
25
+ const strArr = str.match(this.contextReg);
26
+ strArr === null || strArr === void 0 ? void 0 : strArr.forEach(_key => {
27
+ const key = _key.slice(10, _key.length - 1);
28
+ str = str.replace(`\${context.${key}}`, context[key] || '');
29
+ });
30
+ }
31
+ if (notNilEmpty(data)) {
32
+ const strArr = str.match(this.dataReg);
33
+ strArr === null || strArr === void 0 ? void 0 : strArr.forEach(_key => {
34
+ const key = _key.slice(7, _key.length - 1);
35
+ str = str.replace(`\${data.${key}}`, data[key] || '');
36
+ });
37
+ }
38
+ }
39
+ return str;
40
+ }
41
+ /**
42
+ * 动态匹配${}
43
+ *
44
+ * @param str
45
+ * @param values
46
+ */
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ static dynamicMatch(str, values) {
49
+ return str.replace(/\${(.*?)}/g, (_, key) => {
50
+ const [objKey, propName] = key.split('.');
51
+ const obj = values[objKey];
52
+ return obj ? obj[propName] : '';
53
+ });
54
+ }
55
+ }
56
+ /**
57
+ * 上下文替换正则
58
+ *
59
+ * @author chitanda
60
+ * @date 2021-04-23 20:04:01
61
+ * @static
62
+ */
63
+ StringUtil.contextReg = /\$\{context.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
64
+ /**
65
+ * 数据替换正则
66
+ *
67
+ * @author chitanda
68
+ * @date 2021-04-23 20:04:09
69
+ * @static
70
+ */
71
+ StringUtil.dataReg = /\$\{data.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 设置延迟wait毫米后执行fun方法,返回fun的返回值
3
+ *
4
+ * @author lxm
5
+ * @date 2023-03-06 08:20:57
6
+ * @export
7
+ * @template T
8
+ * @param {number} wait
9
+ * @param {T} fun
10
+ * @param {any[]} params
11
+ * @returns {*} {Promise<ReturnType<T>>}
12
+ */
13
+ export declare function awaitTimeout<T extends (...args: any) => any>(wait: number, fun?: T, params?: any[]): Promise<ReturnType<T> | undefined>;
14
+ //# sourceMappingURL=await-timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"await-timeout.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/await-timeout.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAChE,IAAI,EAAE,MAAM,EACZ,GAAG,CAAC,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,GAAG,EAAE,GACb,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CASpC"}
@@ -0,0 +1,23 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * 设置延迟wait毫米后执行fun方法,返回fun的返回值
4
+ *
5
+ * @author lxm
6
+ * @date 2023-03-06 08:20:57
7
+ * @export
8
+ * @template T
9
+ * @param {number} wait
10
+ * @param {T} fun
11
+ * @param {any[]} params
12
+ * @returns {*} {Promise<ReturnType<T>>}
13
+ */
14
+ export async function awaitTimeout(wait, fun, params) {
15
+ await new Promise(resolve => {
16
+ setTimeout(() => {
17
+ resolve(true);
18
+ }, wait);
19
+ });
20
+ if (fun) {
21
+ return fun(...(params || []));
22
+ }
23
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 计数插销工具类
3
+ *
4
+ * @author lxm
5
+ * @date 2022-11-24 19:11:49
6
+ * @export
7
+ * @class CountLatch
8
+ */
9
+ export declare class CountLatch {
10
+ private promise;
11
+ private resolve;
12
+ /**
13
+ * 计数,当前等待的异步逻辑个数
14
+ *
15
+ * @author lxm
16
+ * @date 2022-11-24 19:11:59
17
+ * @type {number}
18
+ */
19
+ count: number;
20
+ /**
21
+ * 开启promise
22
+ *
23
+ * @author lxm
24
+ * @date 2022-11-24 19:11:32
25
+ * @private
26
+ */
27
+ private startPromise;
28
+ /**
29
+ * 结束promise
30
+ *
31
+ * @author lxm
32
+ * @date 2022-11-24 19:11:44
33
+ * @private
34
+ */
35
+ private endPromise;
36
+ /**
37
+ * 上锁,计数加一
38
+ * 第一次计数,开启异步
39
+ *
40
+ * @author lxm
41
+ * @date 2022-11-24 19:11:27
42
+ */
43
+ lock(): void;
44
+ /**
45
+ * 解锁,计数减一
46
+ * 归零时结束异步
47
+ *
48
+ * @author lxm
49
+ * @date 2022-11-24 19:11:47
50
+ */
51
+ unlock(): void;
52
+ /**
53
+ * 等待,计数归零异步结束
54
+ *
55
+ * @author lxm
56
+ * @date 2022-11-24 19:11:20
57
+ */
58
+ await(): Promise<void>;
59
+ }
60
+ //# sourceMappingURL=count-latch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count-latch.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/count-latch.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA8B;IAE7C,OAAO,CAAC,OAAO,CAAwC;IAEvD;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAK;IAElB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAMpB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;;;OAMG;IACH,IAAI;IAOJ;;;;;;OAMG;IACH,MAAM;IAWN;;;;;OAKG;IACG,KAAK;CAKZ"}
@@ -0,0 +1,90 @@
1
+ import { RuntimeError } from '../../error';
2
+ /**
3
+ * 计数插销工具类
4
+ *
5
+ * @author lxm
6
+ * @date 2022-11-24 19:11:49
7
+ * @export
8
+ * @class CountLatch
9
+ */
10
+ export class CountLatch {
11
+ constructor() {
12
+ this.promise = null;
13
+ this.resolve = null;
14
+ /**
15
+ * 计数,当前等待的异步逻辑个数
16
+ *
17
+ * @author lxm
18
+ * @date 2022-11-24 19:11:59
19
+ * @type {number}
20
+ */
21
+ this.count = 0;
22
+ }
23
+ /**
24
+ * 开启promise
25
+ *
26
+ * @author lxm
27
+ * @date 2022-11-24 19:11:32
28
+ * @private
29
+ */
30
+ startPromise() {
31
+ this.promise = new Promise(resolve => {
32
+ this.resolve = resolve;
33
+ });
34
+ }
35
+ /**
36
+ * 结束promise
37
+ *
38
+ * @author lxm
39
+ * @date 2022-11-24 19:11:44
40
+ * @private
41
+ */
42
+ endPromise() {
43
+ if (this.resolve) {
44
+ this.resolve();
45
+ this.resolve = null;
46
+ this.promise = null;
47
+ }
48
+ }
49
+ /**
50
+ * 上锁,计数加一
51
+ * 第一次计数,开启异步
52
+ *
53
+ * @author lxm
54
+ * @date 2022-11-24 19:11:27
55
+ */
56
+ lock() {
57
+ this.count += 1;
58
+ if (!this.promise) {
59
+ this.startPromise();
60
+ }
61
+ }
62
+ /**
63
+ * 解锁,计数减一
64
+ * 归零时结束异步
65
+ *
66
+ * @author lxm
67
+ * @date 2022-11-24 19:11:47
68
+ */
69
+ unlock() {
70
+ if (this.count < 1) {
71
+ throw new RuntimeError('lock和unlock次数不匹配!');
72
+ }
73
+ this.count -= 1;
74
+ if (this.count === 0) {
75
+ debugger;
76
+ this.endPromise();
77
+ }
78
+ }
79
+ /**
80
+ * 等待,计数归零异步结束
81
+ *
82
+ * @author lxm
83
+ * @date 2022-11-24 19:11:20
84
+ */
85
+ async await() {
86
+ if (this.promise) {
87
+ await this.promise;
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,3 @@
1
+ export { awaitTimeout } from './await-timeout';
2
+ export { CountLatch } from './count-latch';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { awaitTimeout } from './await-timeout';
2
+ export { CountLatch } from './count-latch';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * 文件List转数组
3
+ *
4
+ * @author lxm
5
+ * @date 2022-11-18 13:11:03
6
+ * @export
7
+ * @param {FileList} fileList
8
+ * @returns {*}
9
+ */
10
+ export declare function fileListToArr(fileList: FileList): File[];
11
+ /**
12
+ * JS打开文件上传操作配置参数
13
+ *
14
+ * @author lxm
15
+ * @date 2022-11-20 21:11:47
16
+ * @export
17
+ * @interface SelectFileOpts
18
+ */
19
+ export interface SelectFileOpts {
20
+ /**
21
+ * 接受的文件类型
22
+ *
23
+ * @author lxm
24
+ * @date 2022-11-20 21:11:52
25
+ * @type {string}
26
+ */
27
+ accept?: string;
28
+ /**
29
+ * 是否支持多选
30
+ *
31
+ * @author lxm
32
+ * @date 2022-11-20 21:11:52
33
+ * @type {boolean}
34
+ */
35
+ multiple?: boolean;
36
+ /**
37
+ * 选中文件后回调
38
+ *
39
+ * @author lxm
40
+ * @date 2022-11-20 21:11:50
41
+ */
42
+ onSelected: (_fileList: File[]) => void;
43
+ }
44
+ /**
45
+ * JS打开文件上传操作
46
+ *
47
+ * @author lxm
48
+ * @date 2022-11-20 21:11:31
49
+ * @export
50
+ * @param {SelectFileOpts} _opts 配置参数
51
+ */
52
+ export declare function selectFile(_opts: SelectFileOpts): void;
53
+ //# sourceMappingURL=select-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-file.d.ts","sourceRoot":"","sources":["../../../src/utils/upload/select-file.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,CAMxD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,UAAU,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,QAwB/C"}
@@ -0,0 +1,47 @@
1
+ import { merge } from 'lodash-es';
2
+ /**
3
+ * 文件List转数组
4
+ *
5
+ * @author lxm
6
+ * @date 2022-11-18 13:11:03
7
+ * @export
8
+ * @param {FileList} fileList
9
+ * @returns {*}
10
+ */
11
+ export function fileListToArr(fileList) {
12
+ const files = [];
13
+ for (let i = 0; i < fileList.length; i++) {
14
+ files.push(fileList[i]);
15
+ }
16
+ return files;
17
+ }
18
+ /**
19
+ * JS打开文件上传操作
20
+ *
21
+ * @author lxm
22
+ * @date 2022-11-20 21:11:31
23
+ * @export
24
+ * @param {SelectFileOpts} _opts 配置参数
25
+ */
26
+ export function selectFile(_opts) {
27
+ const opts = merge({
28
+ multiple: true,
29
+ accept: '',
30
+ }, _opts);
31
+ const input = document.createElement('input');
32
+ input.setAttribute('type', 'file');
33
+ input.setAttribute('multiple', `${opts.multiple}`);
34
+ input.setAttribute('accept', opts.accept);
35
+ input.onchange = e => {
36
+ const inputEl = e.target;
37
+ const files = inputEl.files ? fileListToArr(inputEl.files) : [];
38
+ if (files.length === 0) {
39
+ return;
40
+ }
41
+ opts.onSelected(files);
42
+ inputEl.value = ''; // 如果不置空,相同的文件不会触发change事件
43
+ };
44
+ document.body.appendChild(input);
45
+ input.click();
46
+ document.body.removeChild(input);
47
+ }
@@ -0,0 +1,46 @@
1
+ import { HttpResponse } from '../net/http-response';
2
+ export interface IUploadFile {
3
+ name: string;
4
+ uid: string;
5
+ status: 'uploading' | 'finished' | 'fail' | 'cancel';
6
+ percentage: number;
7
+ response?: HttpResponse;
8
+ error?: unknown;
9
+ }
10
+ export interface IUploadFileOpts {
11
+ uploadUrl: string;
12
+ /**
13
+ * 接受的文件类型
14
+ *
15
+ * @author lxm
16
+ * @date 2022-11-20 21:11:52
17
+ * @type {string}
18
+ */
19
+ accept?: string;
20
+ /**
21
+ * 是否支持多选
22
+ *
23
+ * @author lxm
24
+ * @date 2022-11-20 21:11:52
25
+ * @type {Boolean}
26
+ */
27
+ multiple?: boolean;
28
+ separate?: string;
29
+ request?: (_files: File[]) => Promise<HttpResponse>;
30
+ beforeUpload?: (_fileData: File[], _files: IUploadFile[]) => boolean;
31
+ finish?: (_resultFiles: IUploadFile[]) => void;
32
+ success?: (_resultFiles: IUploadFile[], _res: HttpResponse) => void;
33
+ error?: (_resultFiles: IUploadFile[], _error: unknown) => void;
34
+ progress?: (_files: IUploadFile[]) => void;
35
+ }
36
+ /**
37
+ * 使用上传文件逻辑
38
+ *
39
+ * @author lxm
40
+ * @date 2022-11-20 21:11:52
41
+ * @export
42
+ * @param {IUploadFileOpts} _opts
43
+ * @returns {*}
44
+ */
45
+ export declare function uploadFile(_opts: IUploadFileOpts): void;
46
+ //# sourceMappingURL=upload-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../../src/utils/upload/upload-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,OAAO,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACpE,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,QA0JhD"}