@ibiz-template/core 0.0.1-alpha.6 → 0.0.1-beta.17

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 (165) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/command/command-register.d.ts +66 -0
  3. package/out/command/command-register.d.ts.map +1 -0
  4. package/out/command/command-register.js +113 -0
  5. package/out/command/command.d.ts +54 -0
  6. package/out/command/command.d.ts.map +1 -0
  7. package/out/command/command.js +71 -0
  8. package/out/command/index.d.ts +10 -0
  9. package/out/command/index.d.ts.map +1 -0
  10. package/out/command/index.js +9 -0
  11. package/out/command/interface/command/command-option.d.ts +23 -0
  12. package/out/command/interface/command/command-option.d.ts.map +1 -0
  13. package/out/command/interface/command/command-option.js +1 -0
  14. package/out/command/interface/command/command.d.ts +74 -0
  15. package/out/command/interface/command/command.d.ts.map +1 -0
  16. package/out/command/interface/command/command.js +1 -0
  17. package/out/command/interface/disposable/disposable.d.ts +4 -0
  18. package/out/command/interface/disposable/disposable.d.ts.map +1 -0
  19. package/out/command/interface/disposable/disposable.js +1 -0
  20. package/out/command/interface/index.d.ts +4 -0
  21. package/out/command/interface/index.d.ts.map +1 -0
  22. package/out/command/interface/index.js +1 -0
  23. package/out/command/utils/index.d.ts +3 -0
  24. package/out/command/utils/index.d.ts.map +1 -0
  25. package/out/command/utils/index.js +2 -0
  26. package/out/command/utils/linked-list.d.ts +16 -0
  27. package/out/command/utils/linked-list.d.ts.map +1 -0
  28. package/out/command/utils/linked-list.js +120 -0
  29. package/out/command/utils/util.d.ts +27 -0
  30. package/out/command/utils/util.d.ts.map +1 -0
  31. package/out/command/utils/util.js +77 -0
  32. package/out/constant/index.d.ts +3 -0
  33. package/out/constant/index.d.ts.map +1 -1
  34. package/out/constant/index.js +3 -0
  35. package/out/constant/login-mode/login-mode.d.ts +23 -0
  36. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  37. package/out/constant/login-mode/login-mode.js +24 -0
  38. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  39. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  40. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  41. package/out/constant/util/util.d.ts +5 -0
  42. package/out/constant/util/util.d.ts.map +1 -0
  43. package/out/constant/util/util.js +5 -0
  44. package/out/context/index.d.ts +19 -32
  45. package/out/context/index.d.ts.map +1 -1
  46. package/out/context/index.js +52 -60
  47. package/out/environment/environment.d.ts.map +1 -1
  48. package/out/environment/environment.js +11 -2
  49. package/out/error/http-error/http-error.d.ts.map +1 -1
  50. package/out/error/http-error/http-error.js +0 -4
  51. package/out/factory-center.d.ts +11 -0
  52. package/out/factory-center.d.ts.map +1 -0
  53. package/out/factory-center.js +10 -0
  54. package/out/ibizsys.d.ts +17 -1
  55. package/out/ibizsys.d.ts.map +1 -1
  56. package/out/ibizsys.js +17 -1
  57. package/out/index.d.ts +3 -1
  58. package/out/index.d.ts.map +1 -1
  59. package/out/index.js +3 -1
  60. package/out/install.d.ts.map +1 -1
  61. package/out/install.js +4 -2
  62. package/out/interface/click-outside/click-outside.d.ts +70 -0
  63. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  64. package/out/interface/click-outside/click-outside.js +1 -0
  65. package/out/interface/i-environment/i-environment.d.ts +72 -4
  66. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  67. package/out/interface/index.d.ts +1 -0
  68. package/out/interface/index.d.ts.map +1 -1
  69. package/out/interface/index.js +1 -1
  70. package/out/types.d.ts +10 -0
  71. package/out/types.d.ts.map +1 -1
  72. package/out/utils/click-outside/click-outside.d.ts +14 -0
  73. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  74. package/out/utils/click-outside/click-outside.js +85 -0
  75. package/out/utils/color/color.d.ts +13 -0
  76. package/out/utils/color/color.d.ts.map +1 -0
  77. package/out/utils/color/color.js +76 -0
  78. package/out/utils/download-file/download-file.d.ts +31 -0
  79. package/out/utils/download-file/download-file.d.ts.map +1 -0
  80. package/out/utils/download-file/download-file.js +107 -0
  81. package/out/utils/event/event.d.ts +34 -0
  82. package/out/utils/event/event.d.ts.map +1 -0
  83. package/out/utils/event/event.js +60 -0
  84. package/out/utils/index.d.ts +10 -1
  85. package/out/utils/index.d.ts.map +1 -1
  86. package/out/utils/index.js +10 -1
  87. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  88. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  89. package/out/utils/interceptor/core-interceptor.js +30 -0
  90. package/out/utils/interceptor/index.d.ts +3 -0
  91. package/out/utils/interceptor/index.d.ts.map +1 -0
  92. package/out/utils/interceptor/index.js +2 -0
  93. package/out/utils/interceptor/interceptor.d.ts +74 -3
  94. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  95. package/out/utils/interceptor/interceptor.js +73 -22
  96. package/out/utils/logger/logger.d.ts +3 -0
  97. package/out/utils/logger/logger.d.ts.map +1 -0
  98. package/out/utils/logger/logger.js +2 -0
  99. package/out/utils/net/http-response.d.ts +4 -9
  100. package/out/utils/net/http-response.d.ts.map +1 -1
  101. package/out/utils/net/http-response.js +0 -7
  102. package/out/utils/net/net.d.ts +82 -31
  103. package/out/utils/net/net.d.ts.map +1 -1
  104. package/out/utils/net/net.js +109 -40
  105. package/out/utils/sync/count-latch.d.ts +60 -0
  106. package/out/utils/sync/count-latch.d.ts.map +1 -0
  107. package/out/utils/sync/count-latch.js +93 -0
  108. package/out/utils/sync/index.d.ts +2 -0
  109. package/out/utils/sync/index.d.ts.map +1 -0
  110. package/out/utils/sync/index.js +1 -0
  111. package/out/utils/upload/select-file.d.ts +53 -0
  112. package/out/utils/upload/select-file.d.ts.map +1 -0
  113. package/out/utils/upload/select-file.js +47 -0
  114. package/out/utils/upload/upload-file.d.ts +46 -0
  115. package/out/utils/upload/upload-file.d.ts.map +1 -0
  116. package/out/utils/upload/upload-file.js +150 -0
  117. package/out/utils/url-helper/url-helper.d.ts +51 -0
  118. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  119. package/out/utils/url-helper/url-helper.js +59 -0
  120. package/out/utils/util/util.d.ts +20 -4
  121. package/out/utils/util/util.d.ts.map +1 -1
  122. package/out/utils/util/util.js +59 -5
  123. package/package.json +19 -9
  124. package/src/command/command-register.ts +135 -0
  125. package/src/command/command.ts +79 -0
  126. package/src/command/index.ts +11 -0
  127. package/src/command/interface/command/command-option.ts +22 -0
  128. package/src/command/interface/command/command.ts +86 -0
  129. package/src/command/interface/disposable/disposable.ts +3 -0
  130. package/src/command/interface/index.ts +9 -0
  131. package/src/command/utils/index.ts +2 -0
  132. package/src/command/utils/linked-list.ts +136 -0
  133. package/src/command/utils/util.ts +95 -0
  134. package/src/constant/index.ts +3 -0
  135. package/src/constant/login-mode/login-mode.ts +23 -0
  136. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  137. package/src/constant/util/util.ts +5 -0
  138. package/src/context/index.ts +69 -59
  139. package/src/environment/environment.ts +11 -2
  140. package/src/error/http-error/http-error.ts +0 -4
  141. package/src/factory-center.ts +9 -0
  142. package/src/ibizsys.ts +19 -1
  143. package/src/index.ts +3 -1
  144. package/src/install.ts +4 -2
  145. package/src/interface/click-outside/click-outside.ts +71 -0
  146. package/src/interface/i-environment/i-environment.ts +81 -4
  147. package/src/interface/index.ts +1 -0
  148. package/src/types.ts +10 -0
  149. package/src/utils/click-outside/click-outside.ts +110 -0
  150. package/src/utils/color/color.ts +84 -0
  151. package/src/utils/download-file/download-file.ts +109 -0
  152. package/src/utils/event/event.ts +77 -0
  153. package/src/utils/index.ts +10 -1
  154. package/src/utils/interceptor/core-interceptor.ts +35 -0
  155. package/src/utils/interceptor/index.ts +2 -0
  156. package/src/utils/interceptor/interceptor.ts +109 -22
  157. package/src/utils/logger/logger.ts +3 -0
  158. package/src/utils/net/http-response.ts +6 -9
  159. package/src/utils/net/net.ts +144 -51
  160. package/src/utils/sync/count-latch.ts +99 -0
  161. package/src/utils/sync/index.ts +1 -0
  162. package/src/utils/upload/select-file.ts +86 -0
  163. package/src/utils/upload/upload-file.ts +206 -0
  164. package/src/utils/url-helper/url-helper.ts +62 -0
  165. package/src/utils/util/util.ts +72 -14
@@ -1,4 +1,5 @@
1
- import { AxiosRequestHeaders } from 'axios';
1
+ import { RawAxiosRequestHeaders, AxiosRequestConfig, AxiosInstance, CreateAxiosDefaults } from 'axios';
2
+ import { Interceptor } from '../interceptor/interceptor';
2
3
  import { IHttpResponse } from './http-response';
3
4
  /**
4
5
  * 全局请求工具类
@@ -10,73 +11,133 @@ import { IHttpResponse } from './http-response';
10
11
  */
11
12
  export declare class Net {
12
13
  /**
13
- * 标准请求前缀
14
+ * axios实例
14
15
  *
15
- * @author chitanda
16
- * @date 2022-07-21 10:07:48
16
+ * @author lxm
17
+ * @date 2022-10-27 17:10:18
17
18
  * @protected
18
- * @type {string}
19
+ * @type {AxiosInstance}
19
20
  */
20
- protected _prefix: string;
21
- get prefix(): string;
21
+ protected instance: AxiosInstance;
22
22
  /**
23
23
  * Creates an instance of Net.
24
+ * @author lxm
25
+ * @date 2022-10-27 16:10:05
26
+ * @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
27
+ */
28
+ constructor(config?: CreateAxiosDefaults);
29
+ /**
30
+ * 注册的拦截器
24
31
  *
25
- * @author chitanda
26
- * @date 2022-07-21 10:07:27
27
- * @param {string} [prefix] 请求前缀
32
+ * @author lxm
33
+ * @date 2022-10-27 17:10:18
34
+ * @type {Map<string, Interceptor>}
35
+ */
36
+ interceptors: Map<string, Interceptor>;
37
+ /**
38
+ * 添加拦截器
39
+ *
40
+ * @author lxm
41
+ * @date 2022-10-27 17:10:42
42
+ * @param {string} name 唯一标识
43
+ * @param {Interceptor} interceptor 拦截器
44
+ */
45
+ addInterceptor(name: string, interceptor: Interceptor): void;
46
+ /**
47
+ * 删除拦截器
48
+ *
49
+ * @author lxm
50
+ * @date 2022-10-27 17:10:27
51
+ * @param {string} name 唯一标识
52
+ */
53
+ removeInterceptor(name: string): void;
54
+ /**
55
+ * 预置config,绑定动态的配置
56
+ *
57
+ * @author lxm
58
+ * @date 2022-10-27 16:10:48
59
+ * @readonly
60
+ * @protected
61
+ * @type {AxiosRequestConfig}
28
62
  */
29
- constructor(prefix?: string);
63
+ protected get presetConfig(): AxiosRequestConfig;
64
+ /**
65
+ * 从左到右递归合并配置参数(内置第一个合并的预置参数)
66
+ *
67
+ * @author lxm
68
+ * @date 2022-10-27 16:10:09
69
+ * @protected
70
+ * @param {...AxiosRequestConfig[]} configs
71
+ * @returns {*}
72
+ */
73
+ protected mergeConfig(...configs: AxiosRequestConfig[]): any;
30
74
  /**
31
75
  * Post 请求
32
76
  *
33
77
  * @author chitanda
34
- * @date 2022-07-14 15:07:01
78
+ * @date 2022-10-19 11:10:30
35
79
  * @param {string} url
80
+ * @param {IData} data
36
81
  * @param {IParams} [params={}]
82
+ * @param {RawAxiosRequestHeaders} [headers={}]
37
83
  * @return {*} {Promise<IHttpResponse>}
38
84
  */
39
- post(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
85
+ post(url: string, data: IData, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
40
86
  /**
41
87
  * Get 请求
42
88
  *
43
89
  * @author chitanda
44
- * @date 2022-07-14 15:07:08
90
+ * @date 2022-10-19 11:10:24
45
91
  * @param {string} url
46
92
  * @param {IParams} [params={}]
93
+ * @param {RawAxiosRequestHeaders} [headers={}]
94
+ * @param {IParams} [option={}]
47
95
  * @return {*} {Promise<IHttpResponse>}
48
96
  */
49
- get(url: string, params?: IParams, headers?: AxiosRequestHeaders, option?: IParams): Promise<IHttpResponse>;
97
+ get(url: string, params?: IParams, headers?: RawAxiosRequestHeaders, option?: AxiosRequestConfig): Promise<IHttpResponse>;
50
98
  /**
51
99
  * Delete 请求
52
100
  *
53
101
  * @author chitanda
54
- * @date 2022-07-14 15:07:43
102
+ * @date 2022-10-19 11:10:17
55
103
  * @param {string} url
56
104
  * @param {IParams} [params]
105
+ * @param {RawAxiosRequestHeaders} [headers={}]
57
106
  * @return {*} {Promise<IHttpResponse>}
58
107
  */
59
- delete(url: string, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
108
+ delete(url: string, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
60
109
  /**
61
110
  * Put 请求
62
111
  *
63
112
  * @author chitanda
64
- * @date 2022-07-14 15:07:49
113
+ * @date 2022-10-19 11:10:11
65
114
  * @param {string} url
66
115
  * @param {IData} data
116
+ * @param {IParams} [params={}]
117
+ * @param {RawAxiosRequestHeaders} [headers={}]
67
118
  * @return {*} {Promise<IHttpResponse>}
68
119
  */
69
- put(url: string, data: IData, params?: IParams, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
120
+ put(url: string, data: IData, params?: IParams, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
70
121
  /**
71
122
  * 获取模型数据
72
123
  *
73
124
  * @author chitanda
74
125
  * @date 2022-07-14 15:07:15
75
126
  * @param {string} url
76
- * @param {AxiosRequestHeaders} [headers={}]
127
+ * @param {RawAxiosRequestHeaders} [headers={}]
77
128
  * @return {*} {Promise<IHttpResponse>}
78
129
  */
79
- getModel(url: string, headers?: AxiosRequestHeaders): Promise<IHttpResponse>;
130
+ getModel(url: string, headers?: RawAxiosRequestHeaders): Promise<IHttpResponse>;
131
+ /**
132
+ * 基础请求方法,会合并预置配置
133
+ *
134
+ * @author lxm
135
+ * @date 2022-10-27 14:10:06
136
+ * @param {string} url
137
+ * @param {AxiosRequestConfig} [config={}]
138
+ * @returns {*} {Promise<IHttpResponse>}
139
+ */
140
+ request(url: string, config?: AxiosRequestConfig): Promise<IHttpResponse>;
80
141
  /**
81
142
  * 统一处理请求返回
82
143
  *
@@ -109,15 +170,5 @@ export declare class Net {
109
170
  * @return {*} {string}
110
171
  */
111
172
  private attachUrlParam;
112
- /**
113
- * 处理 url 参数
114
- *
115
- * @author chitanda
116
- * @date 2022-07-20 20:07:17
117
- * @private
118
- * @param {string} url
119
- * @return {*} {string}
120
- */
121
- private attachUrl;
122
173
  }
123
174
  //# sourceMappingURL=net.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAAc,mBAAmB,EAAiB,MAAM,OAAO,CAAC;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,CAAM;IAE/B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;;;OAMG;gBACS,MAAM,CAAC,EAAE,MAAM;IAM3B;;;;;;;;OAQG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAmBzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,EACjC,MAAM,GAAE,OAAY,GACnB,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;IAiBtB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAGlB"}
1
+ {"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/utils/net/net.ts"],"names":[],"mappings":"AAAA,OAAc,EAEZ,sBAAsB,EAEtB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;GAOG;AACH,qBAAa,GAAG;IACd;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;IAElC;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,mBAAmB;IAIxC;;;;;;OAMG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAEnD;;;;;;;OAOG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW;IAKrD;;;;;;OAMG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAQ9B;;;;;;;;OAQG;IACH,SAAS,KAAK,YAAY,IAAI,kBAAkB,CAS/C;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,OAAO,EAAE,kBAAkB,EAAE;IAOtD;;;;;;;;;;OAUG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,EACpC,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAiBzB;;;;;;;;;OASG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAUzB;;;;;;;;;;OAUG;IACG,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,KAAK,EACX,MAAM,GAAE,OAAY,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAczB;;;;;;;;OAQG;IACG,QAAQ,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,aAAa,CAAC;IAWzB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;;;;;OASG;IACH,OAAO,CAAC,cAAc;CAevB"}
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import { merge } from 'lodash-es';
2
3
  import { stringify } from 'qs';
3
4
  import { notNilEmpty } from 'qx-util';
4
5
  import { HttpError } from '../../error';
@@ -13,45 +14,99 @@ import { HttpError } from '../../error';
13
14
  export class Net {
14
15
  /**
15
16
  * Creates an instance of Net.
16
- *
17
- * @author chitanda
18
- * @date 2022-07-21 10:07:27
19
- * @param {string} [prefix] 请求前缀
17
+ * @author lxm
18
+ * @date 2022-10-27 16:10:05
19
+ * @param {CreateAxiosDefaults} [config] 创建实例用的默认配置
20
20
  */
21
- constructor(prefix) {
21
+ constructor(config) {
22
22
  /**
23
- * 标准请求前缀
23
+ * 注册的拦截器
24
24
  *
25
- * @author chitanda
26
- * @date 2022-07-21 10:07:48
27
- * @protected
28
- * @type {string}
25
+ * @author lxm
26
+ * @date 2022-10-27 17:10:18
27
+ * @type {Map<string, Interceptor>}
29
28
  */
30
- this._prefix = '';
31
- if (prefix) {
32
- this._prefix = prefix;
29
+ this.interceptors = new Map();
30
+ this.instance = axios.create(config);
31
+ }
32
+ /**
33
+ * 添加拦截器
34
+ *
35
+ * @author lxm
36
+ * @date 2022-10-27 17:10:42
37
+ * @param {string} name 唯一标识
38
+ * @param {Interceptor} interceptor 拦截器
39
+ */
40
+ addInterceptor(name, interceptor) {
41
+ interceptor.use(this.instance);
42
+ this.interceptors.set(name, interceptor);
43
+ }
44
+ /**
45
+ * 删除拦截器
46
+ *
47
+ * @author lxm
48
+ * @date 2022-10-27 17:10:27
49
+ * @param {string} name 唯一标识
50
+ */
51
+ removeInterceptor(name) {
52
+ const interceptor = this.interceptors.get(name);
53
+ if (interceptor) {
54
+ interceptor.eject(this.instance);
55
+ this.interceptors.delete(name);
33
56
  }
34
57
  }
35
- get prefix() {
36
- return this._prefix || ibiz.env.baseUrl;
58
+ /**
59
+ * 预置config,绑定动态的配置
60
+ *
61
+ * @author lxm
62
+ * @date 2022-10-27 16:10:48
63
+ * @readonly
64
+ * @protected
65
+ * @type {AxiosRequestConfig}
66
+ */
67
+ get presetConfig() {
68
+ return {
69
+ // 请求前缀路径
70
+ baseURL: this.instance.defaults.baseURL || ibiz.env.baseUrl,
71
+ headers: {
72
+ 'Content-Type': 'application/json;charset=UTF-8',
73
+ Accept: 'application/json',
74
+ },
75
+ };
76
+ }
77
+ /**
78
+ * 从左到右递归合并配置参数(内置第一个合并的预置参数)
79
+ *
80
+ * @author lxm
81
+ * @date 2022-10-27 16:10:09
82
+ * @protected
83
+ * @param {...AxiosRequestConfig[]} configs
84
+ * @returns {*}
85
+ */
86
+ mergeConfig(...configs) {
87
+ if (configs.length === 0) {
88
+ return this.presetConfig;
89
+ }
90
+ return merge(this.presetConfig, ...configs);
37
91
  }
38
92
  /**
39
93
  * Post 请求
40
94
  *
41
95
  * @author chitanda
42
- * @date 2022-07-14 15:07:01
96
+ * @date 2022-10-19 11:10:30
43
97
  * @param {string} url
98
+ * @param {IData} data
44
99
  * @param {IParams} [params={}]
100
+ * @param {RawAxiosRequestHeaders} [headers={}]
45
101
  * @return {*} {Promise<IHttpResponse>}
46
102
  */
47
103
  async post(url, data, params = {}, headers = {}) {
48
104
  url = this.handleAppPresetParam(url, params);
49
105
  try {
50
- const response = await axios({
106
+ const response = await this.request(url, {
51
107
  method: 'post',
52
- url,
53
108
  data,
54
- headers: Object.assign({ 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' }, headers),
109
+ headers,
55
110
  });
56
111
  return this.doResponseResult(response);
57
112
  }
@@ -63,9 +118,11 @@ export class Net {
63
118
  * Get 请求
64
119
  *
65
120
  * @author chitanda
66
- * @date 2022-07-14 15:07:08
121
+ * @date 2022-10-19 11:10:24
67
122
  * @param {string} url
68
123
  * @param {IParams} [params={}]
124
+ * @param {RawAxiosRequestHeaders} [headers={}]
125
+ * @param {IParams} [option={}]
69
126
  * @return {*} {Promise<IHttpResponse>}
70
127
  */
71
128
  async get(url, params = {}, headers = {}, option = {}) {
@@ -75,7 +132,7 @@ export class Net {
75
132
  // }
76
133
  url = this.attachUrlParam(url, params);
77
134
  try {
78
- const response = await axios.get(url, Object.assign({ headers }, option));
135
+ const response = await this.request(url, merge({ method: 'get', headers }, option));
79
136
  return this.doResponseResult(response);
80
137
  }
81
138
  catch (error) {
@@ -86,15 +143,16 @@ export class Net {
86
143
  * Delete 请求
87
144
  *
88
145
  * @author chitanda
89
- * @date 2022-07-14 15:07:43
146
+ * @date 2022-10-19 11:10:17
90
147
  * @param {string} url
91
148
  * @param {IParams} [params]
149
+ * @param {RawAxiosRequestHeaders} [headers={}]
92
150
  * @return {*} {Promise<IHttpResponse>}
93
151
  */
94
152
  async delete(url, params, headers = {}) {
95
153
  url = this.handleAppPresetParam(url, params);
96
154
  try {
97
- const response = await axios.delete(url, { headers });
155
+ const response = await this.request(url, { method: 'delete', headers });
98
156
  return this.doResponseResult(response);
99
157
  }
100
158
  catch (error) {
@@ -105,15 +163,21 @@ export class Net {
105
163
  * Put 请求
106
164
  *
107
165
  * @author chitanda
108
- * @date 2022-07-14 15:07:49
166
+ * @date 2022-10-19 11:10:11
109
167
  * @param {string} url
110
168
  * @param {IData} data
169
+ * @param {IParams} [params={}]
170
+ * @param {RawAxiosRequestHeaders} [headers={}]
111
171
  * @return {*} {Promise<IHttpResponse>}
112
172
  */
113
173
  async put(url, data, params = {}, headers = {}) {
114
174
  url = this.handleAppPresetParam(url, params);
115
175
  try {
116
- const response = await axios.put(url, data, { headers });
176
+ const response = await this.request(url, {
177
+ method: 'put',
178
+ data,
179
+ headers,
180
+ });
117
181
  return this.doResponseResult(response);
118
182
  }
119
183
  catch (error) {
@@ -126,12 +190,12 @@ export class Net {
126
190
  * @author chitanda
127
191
  * @date 2022-07-14 15:07:15
128
192
  * @param {string} url
129
- * @param {AxiosRequestHeaders} [headers={}]
193
+ * @param {RawAxiosRequestHeaders} [headers={}]
130
194
  * @return {*} {Promise<IHttpResponse>}
131
195
  */
132
196
  async getModel(url, headers = {}) {
133
197
  try {
134
- const response = await axios.get(url, {
198
+ const response = await this.instance.get(url, {
135
199
  headers,
136
200
  });
137
201
  return this.doResponseResult(response);
@@ -140,6 +204,24 @@ export class Net {
140
204
  throw new HttpError(error);
141
205
  }
142
206
  }
207
+ /**
208
+ * 基础请求方法,会合并预置配置
209
+ *
210
+ * @author lxm
211
+ * @date 2022-10-27 14:10:06
212
+ * @param {string} url
213
+ * @param {AxiosRequestConfig} [config={}]
214
+ * @returns {*} {Promise<IHttpResponse>}
215
+ */
216
+ async request(url, config = {}) {
217
+ try {
218
+ const response = await this.instance.request(this.mergeConfig({ url }, config));
219
+ return this.doResponseResult(response);
220
+ }
221
+ catch (error) {
222
+ throw new HttpError(error);
223
+ }
224
+ }
143
225
  /**
144
226
  * 统一处理请求返回
145
227
  *
@@ -190,7 +272,6 @@ export class Net {
190
272
  * @return {*} {string}
191
273
  */
192
274
  attachUrlParam(url, params) {
193
- url = this.attachUrl(url);
194
275
  const strParams = stringify(params);
195
276
  if (notNilEmpty(strParams)) {
196
277
  if (url.endsWith('?')) {
@@ -208,16 +289,4 @@ export class Net {
208
289
  }
209
290
  return url;
210
291
  }
211
- /**
212
- * 处理 url 参数
213
- *
214
- * @author chitanda
215
- * @date 2022-07-20 20:07:17
216
- * @private
217
- * @param {string} url
218
- * @return {*} {string}
219
- */
220
- attachUrl(url) {
221
- return `${this.prefix}${url}`;
222
- }
223
292
  }
@@ -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;IASJ;;;;;;OAMG;IACH,MAAM;IAYN;;;;;OAKG;IACG,KAAK;CAKZ"}
@@ -0,0 +1,93 @@
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
+ console.log('lock');
58
+ this.count += 1;
59
+ if (!this.promise) {
60
+ console.log('startPromise');
61
+ this.startPromise();
62
+ }
63
+ }
64
+ /**
65
+ * 解锁,计数减一
66
+ * 归零时结束异步
67
+ *
68
+ * @author lxm
69
+ * @date 2022-11-24 19:11:47
70
+ */
71
+ unlock() {
72
+ if (this.count < 1) {
73
+ throw new RuntimeError('lock和unlock次数不匹配!');
74
+ }
75
+ console.log('unlock');
76
+ this.count -= 1;
77
+ if (this.count === 0) {
78
+ debugger;
79
+ this.endPromise();
80
+ }
81
+ }
82
+ /**
83
+ * 等待,计数归零异步结束
84
+ *
85
+ * @author lxm
86
+ * @date 2022-11-24 19:11:20
87
+ */
88
+ async await() {
89
+ if (this.promise) {
90
+ await this.promise;
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,2 @@
1
+ export { CountLatch } from './count-latch';
2
+ //# 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,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ 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"}