@ibiz-template/core 0.7.41-alpha.101 → 0.7.41-alpha.113

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 (143) hide show
  1. package/dist/index.esm.js +2 -1
  2. package/dist/index.system.min.js +1 -1
  3. package/out/environment/environment.d.ts.map +1 -1
  4. package/out/environment/environment.js +1 -0
  5. package/out/interface/api/environment/i-environment.d.ts +8 -0
  6. package/out/interface/api/environment/i-environment.d.ts.map +1 -1
  7. package/package.json +3 -2
  8. package/src/command/command-register.ts +121 -0
  9. package/src/command/command.ts +78 -0
  10. package/src/command/index.ts +8 -0
  11. package/src/command/utils/index.ts +2 -0
  12. package/src/command/utils/linked-list.ts +136 -0
  13. package/src/command/utils/util.ts +103 -0
  14. package/src/constant/core/core.ts +54 -0
  15. package/src/constant/emoji/emoji.ts +2929 -0
  16. package/src/constant/http-status-message/http-status-message.ts +18 -0
  17. package/src/constant/index.ts +4 -0
  18. package/src/constant/util/util.ts +3 -0
  19. package/src/context/index.ts +231 -0
  20. package/src/environment/environment.ts +65 -0
  21. package/src/error/http-error/entity-error.ts +29 -0
  22. package/src/error/http-error/http-error-factory.ts +24 -0
  23. package/src/error/http-error/http-error.ts +52 -0
  24. package/src/error/index.ts +7 -0
  25. package/src/error/model-error/model-error.ts +27 -0
  26. package/src/error/notice-error/notice-error.ts +16 -0
  27. package/src/error/runtime-error/runtime-error.ts +13 -0
  28. package/src/error/runtime-model-error/runtime-model-error.ts +27 -0
  29. package/src/ibizsys.ts +82 -0
  30. package/src/index.ts +14 -0
  31. package/src/install.ts +12 -0
  32. package/src/interface/api/chat-message/i-api-chat-message.ts +71 -0
  33. package/src/interface/api/chat-message/index.ts +1 -0
  34. package/src/interface/api/constant/index.ts +2 -0
  35. package/src/interface/api/constant/login-mode/login-mode.ts +25 -0
  36. package/src/interface/api/constant/menu-permission-mode/menu-permission-mode.ts +20 -0
  37. package/src/interface/api/environment/i-devtool-config.ts +56 -0
  38. package/src/interface/api/environment/i-environment.ts +532 -0
  39. package/src/interface/api/environment/index.ts +2 -0
  40. package/src/interface/api/global-param/i-api-context.ts +37 -0
  41. package/src/interface/api/global-param/i-global-param.ts +27 -0
  42. package/src/interface/api/global-param/index.ts +2 -0
  43. package/src/interface/api/ibizsys/i-api-ibizsys.ts +54 -0
  44. package/src/interface/api/ibizsys/i-app-data.ts +64 -0
  45. package/src/interface/api/ibizsys/i-org-data.ts +31 -0
  46. package/src/interface/api/ibizsys/index.ts +3 -0
  47. package/src/interface/api/index.ts +6 -0
  48. package/src/interface/api/utils/i-api-i18n.ts +56 -0
  49. package/src/interface/api/utils/index.ts +5 -0
  50. package/src/interface/api/utils/message-center/base/i-message-all.ts +8 -0
  51. package/src/interface/api/utils/message-center/base/i-message-base.ts +29 -0
  52. package/src/interface/api/utils/message-center/base/index.ts +2 -0
  53. package/src/interface/api/utils/message-center/command/add-in-changed/i-add-in-changed.ts +25 -0
  54. package/src/interface/api/utils/message-center/command/add-in-changed/i-command-add-in-changed.ts +16 -0
  55. package/src/interface/api/utils/message-center/command/async-action/i-command-async-action.ts +17 -0
  56. package/src/interface/api/utils/message-center/command/change/i-command-change.ts +8 -0
  57. package/src/interface/api/utils/message-center/command/create/i-command-create.ts +18 -0
  58. package/src/interface/api/utils/message-center/command/i-command-base.ts +23 -0
  59. package/src/interface/api/utils/message-center/command/i-message-command.ts +94 -0
  60. package/src/interface/api/utils/message-center/command/index.ts +20 -0
  61. package/src/interface/api/utils/message-center/command/internal-message/i-command-internal-message.ts +17 -0
  62. package/src/interface/api/utils/message-center/command/internal-message/i-internal-message.ts +132 -0
  63. package/src/interface/api/utils/message-center/command/mark-open-data/i-command-mark-open-data.ts +17 -0
  64. package/src/interface/api/utils/message-center/command/mark-open-data/i-mark-open-data.ts +47 -0
  65. package/src/interface/api/utils/message-center/command/remove/i-command-remove.ts +18 -0
  66. package/src/interface/api/utils/message-center/command/update/i-command-update.ts +18 -0
  67. package/src/interface/api/utils/message-center/common/i-app-data-entity.ts +16 -0
  68. package/src/interface/api/utils/message-center/common/i-message-center-event.ts +15 -0
  69. package/src/interface/api/utils/message-center/common/i-msg-meta-data.ts +13 -0
  70. package/src/interface/api/utils/message-center/common/i-portal-async-action.ts +144 -0
  71. package/src/interface/api/utils/message-center/common/i-portal-message.ts +84 -0
  72. package/src/interface/api/utils/message-center/common/index.ts +5 -0
  73. package/src/interface/api/utils/message-center/console/i-message-console.ts +17 -0
  74. package/src/interface/api/utils/message-center/error/i-message-error.ts +17 -0
  75. package/src/interface/api/utils/message-center/i-message-center.ts +53 -0
  76. package/src/interface/api/utils/message-center/index.ts +6 -0
  77. package/src/interface/api/utils/net/i-api-http-error.ts +43 -0
  78. package/src/interface/api/utils/net/i-api-net.ts +93 -0
  79. package/src/interface/api/utils/net/i-http-response.ts +67 -0
  80. package/src/interface/click-outside/click-outside.ts +51 -0
  81. package/src/interface/command/command/i-command-option.ts +47 -0
  82. package/src/interface/command/command/i-command.ts +68 -0
  83. package/src/interface/command/disposable/i-disposable.ts +12 -0
  84. package/src/interface/command/i-command-controller.ts +50 -0
  85. package/src/interface/command/index.ts +11 -0
  86. package/src/interface/context/index.ts +42 -0
  87. package/src/interface/error/index.ts +13 -0
  88. package/src/interface/i-chat-message/i-chat-message.ts +16 -0
  89. package/src/interface/ibizsys/i-ibizsys.ts +33 -0
  90. package/src/interface/ibizsys/index.ts +1 -0
  91. package/src/interface/index.ts +11 -0
  92. package/src/interface/utils/i-18n.ts +22 -0
  93. package/src/interface/utils/index.ts +1 -0
  94. package/src/locale/en/index.ts +30 -0
  95. package/src/locale/index.ts +2 -0
  96. package/src/locale/zh-CN/index.ts +28 -0
  97. package/src/params/params.ts +131 -0
  98. package/src/types.ts +26 -0
  99. package/src/utils/bit-mask/bit-mask.ts +87 -0
  100. package/src/utils/click-outside/click-outside.ts +108 -0
  101. package/src/utils/clone/clone.ts +38 -0
  102. package/src/utils/color/color.ts +84 -0
  103. package/src/utils/cookie-util/cookie-util.ts +192 -0
  104. package/src/utils/data-type/data-types.ts +93 -0
  105. package/src/utils/download-file/download-file.ts +110 -0
  106. package/src/utils/event/event.ts +69 -0
  107. package/src/utils/history-list/history-item.ts +41 -0
  108. package/src/utils/history-list/history-list.ts +137 -0
  109. package/src/utils/index.ts +24 -0
  110. package/src/utils/interceptor/core-interceptor.ts +127 -0
  111. package/src/utils/interceptor/index.ts +2 -0
  112. package/src/utils/interceptor/interceptor.ts +122 -0
  113. package/src/utils/logger/logger.ts +34 -0
  114. package/src/utils/message-center/base/message-all.ts +10 -0
  115. package/src/utils/message-center/base/message-base.ts +73 -0
  116. package/src/utils/message-center/command/add-in-changed/command-add-in-changed.ts +23 -0
  117. package/src/utils/message-center/command/async-action/command-async-action.ts +23 -0
  118. package/src/utils/message-center/command/change/command-change.ts +11 -0
  119. package/src/utils/message-center/command/command-base/command-base.ts +35 -0
  120. package/src/utils/message-center/command/create/command-create.ts +25 -0
  121. package/src/utils/message-center/command/internal-message/command-internal-message.ts +26 -0
  122. package/src/utils/message-center/command/mark-open-data/command-mark-open-data.ts +23 -0
  123. package/src/utils/message-center/command/message-command.ts +162 -0
  124. package/src/utils/message-center/command/remove/command-remove.ts +25 -0
  125. package/src/utils/message-center/command/update/command-update.ts +25 -0
  126. package/src/utils/message-center/console/message-console.ts +27 -0
  127. package/src/utils/message-center/error/message-error.ts +27 -0
  128. package/src/utils/message-center/index.ts +1 -0
  129. package/src/utils/message-center/message-center.ts +77 -0
  130. package/src/utils/namespace/namespace.ts +217 -0
  131. package/src/utils/net/http-response.ts +60 -0
  132. package/src/utils/net/net.ts +448 -0
  133. package/src/utils/recursive/find-recursive-child.ts +238 -0
  134. package/src/utils/string-util/string-util.ts +76 -0
  135. package/src/utils/style/remote-style.ts +17 -0
  136. package/src/utils/sync/await-timeout.ts +29 -0
  137. package/src/utils/sync/count-latch.ts +79 -0
  138. package/src/utils/sync/index.ts +2 -0
  139. package/src/utils/types/types.ts +24 -0
  140. package/src/utils/upload/select-file.ts +93 -0
  141. package/src/utils/upload/upload-file.ts +194 -0
  142. package/src/utils/url-helper/url-helper.ts +52 -0
  143. package/src/utils/util/util.ts +580 -0
@@ -0,0 +1,76 @@
1
+ import { notNilEmpty } from 'qx-util';
2
+
3
+ /**
4
+ * @description 字符串工具类
5
+ * @export
6
+ * @class StringUtil
7
+ */
8
+ export class StringUtil {
9
+ /**
10
+ * @description 上下文替换正则
11
+ * @static
12
+ * @memberof StringUtil
13
+ */
14
+ static contextReg = /\$\{context.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
15
+
16
+ /**
17
+ * @description 数据替换正则
18
+ * @static
19
+ * @memberof StringUtil
20
+ */
21
+ static dataReg = /\$\{data.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
22
+
23
+ /**
24
+ * @description 参数替换正则
25
+ * @static
26
+ * @memberof StringUtil
27
+ */
28
+ static paramsReg = /\$\{params.[a-zA-Z_$][a-zA-Z0-9_$]{1,}\}/g;
29
+
30
+ /**
31
+ * @description 填充字符串中的数据 用法:传入需要替换的字符串和对象 返回值是string类型
32
+ * @example
33
+ * ```
34
+ * StringUtil.fill('姓名:${context.name},年龄:${data.age}', { name: '张三', age: 10 }, {name: '王二', age: 19}, { name: '李四', age: 25 }); // => '姓名:张三,年龄:25'
35
+ * StringUtil.fill('', { name: '张三', age: 10 }, {name: '王二', age: 19}, { name: '李四', age: 25 }); // => ''
36
+ * ```
37
+ * @static
38
+ * @param {string} str 需填充字符串
39
+ * @param {IContext} [context] 上下文
40
+ * @param {IParams} [params] 参数
41
+ * @param {IData} [data] 数据
42
+ * @return {*} {string}
43
+ * @memberof StringUtil
44
+ */
45
+ static fill(
46
+ str: string,
47
+ context?: IContext,
48
+ params?: IParams,
49
+ data?: IData,
50
+ ): string {
51
+ if (notNilEmpty(str)) {
52
+ if (notNilEmpty(context)) {
53
+ const strArr = str.match(this.contextReg);
54
+ strArr?.forEach(_key => {
55
+ const key = _key.slice(10, _key.length - 1);
56
+ str = str.replace(`\${context.${key}}`, context![key] || '');
57
+ });
58
+ }
59
+ if (notNilEmpty(params)) {
60
+ const strArr = str.match(this.paramsReg);
61
+ strArr?.forEach(_key => {
62
+ const key = _key.slice(9, _key.length - 1);
63
+ str = str.replace(`\${params.${key}}`, params![key] || '');
64
+ });
65
+ }
66
+ if (notNilEmpty(data)) {
67
+ const strArr = str.match(this.dataReg);
68
+ strArr?.forEach(_key => {
69
+ const key = _key.slice(7, _key.length - 1);
70
+ str = str.replace(`\${data.${key}}`, data![key] || '');
71
+ });
72
+ }
73
+ }
74
+ return str;
75
+ }
76
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @description 设置远程样式表
3
+ * @export
4
+ * @param {string} url
5
+ * @returns {*} {Promise<void>}
6
+ */
7
+ export async function setRemoteStyle(url: string): Promise<void> {
8
+ try {
9
+ const res = await ibiz.net.get(url);
10
+ const styleDom = document.createElement('style');
11
+ styleDom.setAttribute('title', 'app-style-css');
12
+ styleDom.innerText = res.data as unknown as string;
13
+ document.head.appendChild(styleDom);
14
+ } catch (error) {
15
+ ibiz.log.debug(ibiz.i18n.t('core.utils.remoteStylesheet'), url);
16
+ }
17
+ }
@@ -0,0 +1,29 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * @description 设置延迟wait毫米后执行fun方法,返回fun的返回值。用法:传入等待时间,函数和参数 返回fun的返回值
4
+ * @example
5
+ * ```
6
+ * awaitTimeout(100, () => 'Hello, World!'); // => 'Hello, World!'
7
+ * awaitTimeout(100, (name: string) => `Hello, ${name}!`, ['John']); // => 'Hello, John!'
8
+ * ```
9
+ * @export
10
+ * @template T
11
+ * @param {number} wait
12
+ * @param {T} fun
13
+ * @param {any[]} params
14
+ * @returns {*} {Promise<ReturnType<T>>}
15
+ */
16
+ export async function awaitTimeout<T extends (...args: any) => any>(
17
+ wait: number,
18
+ fun?: T,
19
+ params?: any[],
20
+ ): Promise<ReturnType<T> | undefined> {
21
+ await new Promise(resolve => {
22
+ setTimeout(() => {
23
+ resolve(true);
24
+ }, wait);
25
+ });
26
+ if (fun) {
27
+ return fun(...(params || []));
28
+ }
29
+ }
@@ -0,0 +1,79 @@
1
+ import { RuntimeError } from '../../error';
2
+
3
+ /**
4
+ * @description 计数插销工具类
5
+ * @export
6
+ * @class CountLatch
7
+ */
8
+ export class CountLatch {
9
+ private promise: Promise<void> | null = null;
10
+
11
+ private resolve: ((value: void) => void) | null = null;
12
+
13
+ /**
14
+ * @description 计数,当前等待的异步逻辑个数
15
+ * @type {number}
16
+ * @memberof CountLatch
17
+ */
18
+ count: number = 0;
19
+
20
+ /**
21
+ * @description 开启promise
22
+ * @private
23
+ * @memberof CountLatch
24
+ */
25
+ private startPromise(): void {
26
+ this.promise = new Promise(resolve => {
27
+ this.resolve = resolve;
28
+ });
29
+ }
30
+
31
+ /**
32
+ * @description 结束promise
33
+ * @private
34
+ * @memberof CountLatch
35
+ */
36
+ private endPromise(): void {
37
+ if (this.resolve) {
38
+ this.resolve();
39
+ this.resolve = null;
40
+ this.promise = null;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @description 上锁,计数加一,第一次计数,开启异步
46
+ * @memberof CountLatch
47
+ */
48
+ lock(): void {
49
+ this.count += 1;
50
+ if (!this.promise) {
51
+ this.startPromise();
52
+ }
53
+ }
54
+
55
+ /**
56
+ * @description 解锁,计数减一,归零时结束异步
57
+ * @memberof CountLatch
58
+ */
59
+ unlock(): void {
60
+ if (this.count < 1) {
61
+ throw new RuntimeError(ibiz.i18n.t('core.utils.notMatchLockUnlock'));
62
+ }
63
+ this.count -= 1;
64
+ if (this.count === 0) {
65
+ this.endPromise();
66
+ }
67
+ }
68
+
69
+ /**
70
+ * @description 等待,计数归零异步结束
71
+ * @returns {*} {Promise<void>}
72
+ * @memberof CountLatch
73
+ */
74
+ async await(): Promise<void> {
75
+ if (this.promise) {
76
+ await this.promise;
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,2 @@
1
+ export { awaitTimeout } from './await-timeout';
2
+ export { CountLatch } from './count-latch';
@@ -0,0 +1,24 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * 从T里面排除U里相同的属性后剩下的属性组成的类型
4
+ */
5
+ export type OmitObject<T, U> = { [K in keyof Omit<T, keyof U>]: T[K] };
6
+
7
+ /**
8
+ * 返回T和U的并集,其中U里面的属性都变成可选
9
+ */
10
+ export type PartialWithObject<T, U> = {
11
+ [K in keyof Omit<T, keyof U>]: T[K];
12
+ } & Partial<U>;
13
+
14
+ /**
15
+ * 从T里面只获取索引类型为string的键
16
+ */
17
+ export type StrKeyOf<T> = {
18
+ [K in keyof T]: T[K] extends string ? K : never;
19
+ }[keyof T];
20
+
21
+ /**
22
+ * 构造函数接口,声明一个返回对象是T的构造函数,不传则返回类型是any
23
+ */
24
+ export type Constructor<T extends object = any> = new (...args: any[]) => T;
@@ -0,0 +1,93 @@
1
+ import { merge } from 'lodash-es';
2
+
3
+ /**
4
+ * @description 文件List转数组
5
+ * @export
6
+ * @param {FileList} fileList
7
+ * @returns {*} {File[]}
8
+ */
9
+ export function fileListToArr(fileList: FileList): File[] {
10
+ const files = [];
11
+ for (let i = 0; i < fileList.length; i++) {
12
+ files.push(fileList[i]);
13
+ }
14
+ return files;
15
+ }
16
+
17
+ /**
18
+ * @description JS打开文件上传操作配置参数
19
+ * @export
20
+ * @interface SelectFileOpts
21
+ */
22
+ export interface SelectFileOpts {
23
+ /**
24
+ * @description 接受的文件类型
25
+ * @type {string}
26
+ * @memberof SelectFileOpts
27
+ */
28
+ accept?: string;
29
+ /**
30
+ * @description 是否支持多选
31
+ * @type {boolean}
32
+ * @memberof SelectFileOpts
33
+ */
34
+ multiple?: boolean;
35
+ /**
36
+ * @description 选中文件后回调
37
+ * @memberof SelectFileOpts
38
+ */
39
+ onSelected: (_fileList: File[]) => void;
40
+ /**
41
+ * @description 没有选中文件,点击了取消的场景
42
+ * @memberof SelectFileOpts
43
+ */
44
+ onCancel?: () => void;
45
+ }
46
+
47
+ /**
48
+ * @description JS打开文件上传操作
49
+ * @export
50
+ * @param {SelectFileOpts} _opts 配置参数
51
+ */
52
+ export function selectFile(_opts: SelectFileOpts): void {
53
+ const opts: { multiple: boolean; accept: string } & SelectFileOpts = merge(
54
+ {
55
+ multiple: true,
56
+ accept: '',
57
+ },
58
+ _opts,
59
+ );
60
+ const input = document.createElement('input');
61
+ input.setAttribute('type', 'file');
62
+ input.setAttribute('multiple', `${opts.multiple}`);
63
+ input.setAttribute('accept', opts.accept);
64
+ let fileCancel = true; // 是否取消
65
+ input.onchange = (e): void => {
66
+ const inputEl = e.target as HTMLInputElement;
67
+ const files = inputEl.files ? fileListToArr(inputEl.files) : [];
68
+ if (files.length === 0) {
69
+ return;
70
+ }
71
+ // 选中了文件就不算取消
72
+ fileCancel = false;
73
+ opts.onSelected(files);
74
+ inputEl.value = ''; // 如果不置空,相同的文件不会触发change事件
75
+ };
76
+ document.body.appendChild(input);
77
+ input.click();
78
+ // 模拟取消事件
79
+ window.addEventListener(
80
+ 'focus',
81
+ () => {
82
+ setTimeout(() => {
83
+ if (fileCancel && opts.onCancel) {
84
+ // 取消逻辑处理
85
+ opts.onCancel();
86
+ }
87
+ }, 300);
88
+ },
89
+ { once: true },
90
+ );
91
+
92
+ document.body.removeChild(input);
93
+ }
@@ -0,0 +1,194 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ /* eslint-disable no-param-reassign */
3
+ import { cloneDeep, isFunction, merge, round, uniqueId } from 'lodash-es';
4
+ import { RuntimeError } from '../../error';
5
+ import { HttpResponse } from '../net/http-response';
6
+ import { selectFile } from './select-file';
7
+
8
+ export interface IUploadFile {
9
+ name: string;
10
+ uid: string;
11
+ status: 'uploading' | 'finished' | 'fail' | 'cancel';
12
+ percentage: number;
13
+ response?: HttpResponse;
14
+ error?: unknown;
15
+ }
16
+
17
+ export interface IUploadFileOpts {
18
+ uploadUrl: string;
19
+ /**
20
+ * @description 接受的文件类型
21
+ * @type {string}
22
+ * @memberof IUploadFileOpts
23
+ */
24
+ accept?: string;
25
+ /**
26
+ * @description 是否支持多选
27
+ * @type {boolean}
28
+ * @memberof IUploadFileOpts
29
+ */
30
+ multiple?: boolean;
31
+ separate?: string;
32
+ request?: (_files: File[]) => Promise<HttpResponse>;
33
+ beforeUpload?: (_fileData: File[], _files: IUploadFile[]) => boolean;
34
+ finish?: (_resultFiles: IUploadFile[]) => void;
35
+ success?: (_resultFiles: IUploadFile[], _res: HttpResponse) => void;
36
+ error?: (_resultFiles: IUploadFile[], _error: unknown) => void;
37
+ progress?: (_files: IUploadFile[]) => void;
38
+ }
39
+
40
+ /**
41
+ * @description 上传文件
42
+ * @export
43
+ * @param {IUploadFileOpts} _opts
44
+ */
45
+ export function uploadFile(_opts: IUploadFileOpts): void {
46
+ const opts: Required<IUploadFileOpts> = merge(
47
+ {
48
+ multiple: true,
49
+ accept: '',
50
+ separate: true,
51
+ beforeUpload: (_fileData: File[], _files: IUploadFile[]) => true,
52
+ finish: (_resultFiles: IUploadFile[]) => {},
53
+ success: (_resultFiles: IUploadFile[], _res: HttpResponse) => {},
54
+ error: (_resultFiles: IUploadFile[], _error: unknown) => {},
55
+ progress: (_files: IUploadFile[]) => {},
56
+ },
57
+ _opts,
58
+ );
59
+
60
+ /**
61
+ * @description 进度条回调
62
+ * @param {IParams} event
63
+ * @param {IUploadFile[]} files
64
+ */
65
+ const onUploadProgress = (event: IParams, files: IUploadFile[]): void => {
66
+ files.forEach(file => {
67
+ file.percentage = round(event.progress * 100);
68
+ });
69
+ opts.progress(cloneDeep(files));
70
+ };
71
+
72
+ /**
73
+ * @description 上传请求方法,返回响应对象
74
+ * @param {File[]} files
75
+ * @param {(_event: IParams) => void} _onProgress
76
+ * @returns {*} {Promise<HttpResponse>}
77
+ */
78
+ const uploadRequest = async (
79
+ files: File[],
80
+ _onProgress: (_event: IParams) => void,
81
+ ): Promise<HttpResponse> => {
82
+ // 自定义上传请求
83
+ if (opts.request && isFunction(opts.request)) {
84
+ return opts.request(files);
85
+ }
86
+
87
+ // 默认每次单个文件上传,可能存在接口一次上传多个文件,
88
+ const data = new FormData();
89
+ files.forEach(file => {
90
+ data.append('file', file);
91
+ });
92
+ // const res = await ibiz.net.request(opts.uploadUrl, {
93
+ // method: 'post',
94
+ // baseURL: '',
95
+ // data,
96
+ // headers: { 'Content-Type': 'multipart/form-data' },
97
+ // onUploadProgress: onProgress,
98
+ // });
99
+ // return res;
100
+ throw new RuntimeError(ibiz.i18n.t('core.utils.multiApplicationMode'));
101
+ };
102
+
103
+ /**
104
+ * @description 执行一次上传,可能是一个文件也可能是多个文件
105
+ * @param {File[]} files
106
+ * @returns {*} {Promise<IUploadFile[]>}
107
+ */
108
+ const executeSingleUpload = async (files: File[]): Promise<IUploadFile[]> => {
109
+ const resultFiles: IUploadFile[] = files.map(file => {
110
+ return {
111
+ status: 'uploading',
112
+ name: file.name,
113
+ uid: uniqueId(),
114
+ percentage: 0,
115
+ };
116
+ });
117
+
118
+ // 上传前回调,可以取消此次下载
119
+ const pass = opts.beforeUpload(files, resultFiles);
120
+ if (!pass) {
121
+ resultFiles.forEach(file => {
122
+ file.status = 'cancel';
123
+ });
124
+ ibiz.log.debug('取消上传', resultFiles);
125
+ return resultFiles;
126
+ }
127
+
128
+ try {
129
+ const res = await uploadRequest(files, event => {
130
+ onUploadProgress(event, resultFiles);
131
+ });
132
+ resultFiles.forEach(file => {
133
+ file.status = 'finished';
134
+ });
135
+ // 上传成功事件
136
+ opts.success(resultFiles, res);
137
+ resultFiles.forEach(file => {
138
+ file.response = res;
139
+ });
140
+ } catch (error) {
141
+ resultFiles.forEach(file => {
142
+ file.status = 'fail';
143
+ });
144
+ // 上传失败事件
145
+ opts.error(resultFiles, error);
146
+ resultFiles.forEach(file => {
147
+ file.error = error;
148
+ });
149
+ ibiz.log.error(error);
150
+ ibiz.log.error(
151
+ ibiz.i18n.t('core.utils.uploadFailed', {
152
+ file: files.map(file => file.name).join(','),
153
+ }),
154
+ );
155
+ }
156
+ return resultFiles;
157
+ };
158
+
159
+ /**
160
+ * @description 执行上传文件逻辑
161
+ * @param {File[]} files
162
+ * @returns {*} {Promise<void>}
163
+ */
164
+ const uploadFiles = async (files: File[]): Promise<void> => {
165
+ const uploadSequence = opts.separate ? files.map(file => [file]) : [files];
166
+ const res = await Promise.allSettled(
167
+ uploadSequence.map(async sequence => {
168
+ return executeSingleUpload(sequence);
169
+ }),
170
+ );
171
+
172
+ // 整合所有的返回文件
173
+ const resultFiles: IUploadFile[] = [];
174
+ res.forEach(result => {
175
+ if (result.status === 'fulfilled') {
176
+ resultFiles.push(...result.value);
177
+ }
178
+ });
179
+
180
+ opts.finish(resultFiles);
181
+ };
182
+
183
+ const select = (): void => {
184
+ selectFile({
185
+ accept: opts.accept,
186
+ multiple: opts.multiple,
187
+ onSelected: files => {
188
+ uploadFiles(files);
189
+ },
190
+ });
191
+ };
192
+
193
+ select();
194
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @description 路径解析助手
3
+ * @export
4
+ * @class UrlHelper
5
+ */
6
+ export class UrlHelper {
7
+ /**
8
+ * @description 路由路径前面的基础路径。如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123,返回:http://172.16.103.120:30061/portalwebapp/#
9
+ * @readonly
10
+ * @static
11
+ * @type {string}
12
+ * @memberof UrlHelper
13
+ */
14
+ static get routeBase(): string {
15
+ const hashIndex = window.location.href.lastIndexOf('#/');
16
+ return window.location.href.slice(0, hashIndex + 1);
17
+ }
18
+
19
+ /**
20
+ * @description 应用的的基础路径。如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123,返回:http://172.16.103.120:30061/portalwebapp
21
+ * @readonly
22
+ * @static
23
+ * @type {string}
24
+ * @memberof UrlHelper
25
+ */
26
+ static get appBase(): string {
27
+ const { origin, pathname } = window.location;
28
+ return `${origin}${pathname}`.replace(/\/$/, '');
29
+ }
30
+
31
+ /**
32
+ * @description #开始到末尾,即路由地址。如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123,返回:/index/appportalview?params=123
33
+ * @readonly
34
+ * @static
35
+ * @type {string}
36
+ * @memberof UrlHelper
37
+ */
38
+ static get routePath(): string {
39
+ return window.location.hash.replace('#', '');
40
+ }
41
+
42
+ /**
43
+ * @description 当前地址的全路径,包含域名和参数。如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
44
+ * @readonly
45
+ * @static
46
+ * @type {string}
47
+ * @memberof UrlHelper
48
+ */
49
+ static get fullPath(): string {
50
+ return window.location.href;
51
+ }
52
+ }