@ningboyz/apis 1.4.199 → 1.5.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 (247) hide show
  1. package/.prettierrc +15 -15
  2. package/index.ts +121 -121
  3. package/package.json +27 -27
  4. package/packages/antv/cnfg.ts +57 -57
  5. package/packages/antv/index.ts +20 -20
  6. package/packages/antv/main.ts +65 -65
  7. package/packages/antv/para.ts +57 -57
  8. package/packages/antv/types.ts +59 -59
  9. package/packages/axios.ts +168 -168
  10. package/packages/bill/cnfg.ts +72 -72
  11. package/packages/bill/index.ts +17 -17
  12. package/packages/bill/main.ts +127 -127
  13. package/packages/bill/types.ts +80 -80
  14. package/packages/card/data.ts +101 -101
  15. package/packages/card/form.ts +19 -19
  16. package/packages/card/fwcz.ts +107 -107
  17. package/packages/card/gblb.ts +118 -118
  18. package/packages/card/hyhb.ts +72 -72
  19. package/packages/card/index.ts +59 -59
  20. package/packages/card/main.ts +318 -318
  21. package/packages/card/p4pz.ts +97 -97
  22. package/packages/card/room.ts +62 -62
  23. package/packages/card/types.ts +915 -915
  24. package/packages/card/zcbd.ts +122 -122
  25. package/packages/card/zccf.ts +113 -113
  26. package/packages/card/zccz.ts +121 -121
  27. package/packages/card/zcdb.ts +131 -131
  28. package/packages/card/zclb.ts +98 -98
  29. package/packages/card/zclbGblb.ts +33 -33
  30. package/packages/card/zczj.ts +21 -21
  31. package/packages/card/zczjProp.ts +21 -21
  32. package/packages/cnfg/index.ts +14 -14
  33. package/packages/cnfg/main.ts +46 -46
  34. package/packages/cnfg/types.ts +4 -4
  35. package/packages/core/dddw.ts +76 -76
  36. package/packages/core/dept.ts +141 -141
  37. package/packages/core/dict.ts +80 -80
  38. package/packages/core/index.ts +65 -65
  39. package/packages/core/laid.ts +89 -89
  40. package/packages/core/local.ts +29 -29
  41. package/packages/core/mast.ts +42 -42
  42. package/packages/core/part.ts +65 -65
  43. package/packages/core/path.ts +74 -74
  44. package/packages/core/skdw.ts +68 -68
  45. package/packages/core/sysbilltype.ts +57 -57
  46. package/packages/core/sysclas.ts +16 -16
  47. package/packages/core/sysenvr.ts +15 -15
  48. package/packages/core/syskjnd.ts +19 -19
  49. package/packages/core/sysmenu.ts +148 -148
  50. package/packages/core/systravel.ts +48 -48
  51. package/packages/core/type.ts +82 -82
  52. package/packages/core/types.ts +930 -930
  53. package/packages/core/unit.ts +141 -141
  54. package/packages/core/user.ts +553 -553
  55. package/packages/cron/index.ts +14 -14
  56. package/packages/cron/main.ts +66 -66
  57. package/packages/cron/types.ts +18 -18
  58. package/packages/elem/data.ts +66 -66
  59. package/packages/elem/index.ts +15 -15
  60. package/packages/elem/main.ts +79 -79
  61. package/packages/elem/types.ts +47 -47
  62. package/packages/expd/index.ts +14 -14
  63. package/packages/expd/main.ts +31 -31
  64. package/packages/expd/types.ts +18 -18
  65. package/packages/flow/duty.ts +59 -59
  66. package/packages/flow/flow.ts +117 -117
  67. package/packages/flow/index.ts +25 -25
  68. package/packages/flow/main.ts +66 -66
  69. package/packages/flow/node.ts +89 -89
  70. package/packages/flow/types.ts +250 -250
  71. package/packages/flow/void.ts +71 -71
  72. package/packages/gams/cnfg.ts +95 -95
  73. package/packages/gams/dial.ts +21 -21
  74. package/packages/gams/index.ts +28 -28
  75. package/packages/gams/item.ts +61 -61
  76. package/packages/gams/k0km.ts +61 -61
  77. package/packages/gams/k8km.ts +124 -124
  78. package/packages/gams/type.ts +59 -59
  79. package/packages/gams/types.ts +269 -269
  80. package/packages/grow/grow.ts +18 -18
  81. package/packages/grow/index.ts +14 -14
  82. package/packages/grow/types.ts +4 -4
  83. package/packages/gzjg/gzlm.ts +114 -114
  84. package/packages/gzjg/index.ts +20 -20
  85. package/packages/gzjg/main.ts +75 -75
  86. package/packages/gzjg/qzgs.ts +41 -41
  87. package/packages/gzjg/types.ts +126 -126
  88. package/packages/gztb/index.ts +14 -14
  89. package/packages/gztb/main.ts +67 -67
  90. package/packages/gztb/types.ts +28 -28
  91. package/packages/gzzd/index.ts +14 -14
  92. package/packages/gzzd/main.ts +142 -142
  93. package/packages/gzzd/types.ts +88 -88
  94. package/packages/hzcb/index.ts +29 -29
  95. package/packages/hzcb/main.ts +94 -94
  96. package/packages/hzcb/ndjh.ts +37 -37
  97. package/packages/hzcb/tdss.ts +36 -36
  98. package/packages/hzcb/types.ts +334 -319
  99. package/packages/hzcb/xmss.ts +36 -36
  100. package/packages/hzcb/xmtz.ts +62 -57
  101. package/packages/hzcb/xmyk.ts +62 -57
  102. package/packages/hznj/base.ts +41 -41
  103. package/packages/hznj/dzqr.ts +37 -37
  104. package/packages/hznj/index.ts +47 -47
  105. package/packages/hznj/main.ts +54 -54
  106. package/packages/hznj/noti.ts +77 -77
  107. package/packages/hznj/rwqx.ts +37 -37
  108. package/packages/hznj/type.ts +875 -875
  109. package/packages/hznj/xmjj.ts +44 -44
  110. package/packages/hznj/xmsy.ts +57 -57
  111. package/packages/hznj/zbcz.ts +36 -36
  112. package/packages/hznj/zbjg.ts +40 -40
  113. package/packages/hznj/zblr.ts +41 -41
  114. package/packages/hznj/zbly.ts +36 -36
  115. package/packages/hznj/zbth.ts +36 -36
  116. package/packages/hznk/base.ts +58 -58
  117. package/packages/hznk/data.ts +68 -68
  118. package/packages/hznk/fydw.ts +67 -67
  119. package/packages/hznk/fytq.ts +40 -40
  120. package/packages/hznk/index.ts +35 -35
  121. package/packages/hznk/main.ts +60 -60
  122. package/packages/hznk/note.ts +36 -36
  123. package/packages/hznk/type.ts +726 -726
  124. package/packages/hznk/xmys.ts +36 -36
  125. package/packages/hznk/yssq.ts +36 -36
  126. package/packages/index.ts +37 -37
  127. package/packages/japz/cnfg.ts +36 -36
  128. package/packages/japz/index.ts +29 -29
  129. package/packages/japz/item.ts +63 -63
  130. package/packages/japz/k0km.ts +36 -36
  131. package/packages/japz/k7km.ts +48 -48
  132. package/packages/japz/k8km.ts +36 -36
  133. package/packages/japz/k9km.ts +40 -40
  134. package/packages/japz/types.ts +449 -449
  135. package/packages/load/cell.ts +21 -21
  136. package/packages/load/data.ts +22 -22
  137. package/packages/load/index.ts +33 -33
  138. package/packages/load/main.ts +68 -68
  139. package/packages/load/nsdw.ts +50 -50
  140. package/packages/load/types.ts +85 -85
  141. package/packages/load/yqdw.ts +15 -15
  142. package/packages/load/yqkm.ts +15 -15
  143. package/packages/load/zydw.ts +16 -16
  144. package/packages/myoa/index.ts +19 -19
  145. package/packages/myoa/main.ts +238 -238
  146. package/packages/myoa/room.ts +57 -57
  147. package/packages/myoa/types.ts +269 -269
  148. package/packages/myoa/withcard.ts +151 -151
  149. package/packages/noti/index.ts +14 -14
  150. package/packages/noti/main.ts +213 -213
  151. package/packages/noti/types.ts +153 -153
  152. package/packages/ocri/index.ts +14 -14
  153. package/packages/ocri/path.ts +24 -24
  154. package/packages/ocri/types.ts +37 -37
  155. package/packages/pzpt/cnfg.ts +111 -111
  156. package/packages/pzpt/glfa.ts +70 -70
  157. package/packages/pzpt/glkm.ts +60 -60
  158. package/packages/pzpt/index.ts +47 -47
  159. package/packages/pzpt/item.ts +52 -52
  160. package/packages/pzpt/k0km.ts +51 -51
  161. package/packages/pzpt/k8km.ts +50 -50
  162. package/packages/pzpt/kbkm.ts +22 -22
  163. package/packages/pzpt/pzpz.ts +66 -66
  164. package/packages/pzpt/pzpzp6pz.ts +61 -61
  165. package/packages/pzpt/type.ts +50 -50
  166. package/packages/pzpt/types.ts +503 -503
  167. package/packages/pzpt/yqkb.ts +20 -20
  168. package/packages/pzpt/yqkm.ts +34 -34
  169. package/packages/tabl/index.ts +14 -14
  170. package/packages/tabl/main.ts +178 -178
  171. package/packages/tabl/types.ts +160 -160
  172. package/packages/take/index.ts +14 -14
  173. package/packages/take/main.ts +58 -58
  174. package/packages/take/types.ts +141 -141
  175. package/packages/talk/index.ts +14 -14
  176. package/packages/talk/main.ts +32 -32
  177. package/packages/talk/types.ts +29 -29
  178. package/packages/task/index.ts +14 -14
  179. package/packages/task/main.ts +65 -65
  180. package/packages/task/types.ts +18 -18
  181. package/packages/type.ts +9 -9
  182. package/packages/vary/index.ts +14 -14
  183. package/packages/vary/main.ts +88 -88
  184. package/packages/vary/types.ts +94 -94
  185. package/packages/wldy/data.ts +86 -86
  186. package/packages/wldy/index.ts +20 -20
  187. package/packages/wldy/item.ts +57 -57
  188. package/packages/wldy/page.ts +114 -114
  189. package/packages/wldy/types.ts +110 -110
  190. package/packages/wlzf/index.ts +14 -14
  191. package/packages/wlzf/main.ts +57 -57
  192. package/packages/wlzf/types.ts +49 -49
  193. package/packages/wtui/ctrl.ts +77 -77
  194. package/packages/wtui/envr.ts +19 -19
  195. package/packages/wtui/form.ts +67 -67
  196. package/packages/wtui/index.ts +44 -44
  197. package/packages/wtui/item.ts +67 -67
  198. package/packages/wtui/main.ts +103 -103
  199. package/packages/wtui/menu.ts +59 -59
  200. package/packages/wtui/node.ts +95 -95
  201. package/packages/wtui/todo.ts +83 -83
  202. package/packages/wtui/types.ts +408 -408
  203. package/packages/wtui/user.ts +39 -39
  204. package/packages/wtui/view.ts +98 -98
  205. package/packages/wtui/zone.ts +58 -58
  206. package/packages/wzpz/cnfg.ts +57 -57
  207. package/packages/wzpz/index.ts +29 -29
  208. package/packages/wzpz/item.ts +60 -60
  209. package/packages/wzpz/k0km.ts +137 -137
  210. package/packages/wzpz/k8km.ts +70 -70
  211. package/packages/wzpz/kbkm.ts +21 -21
  212. package/packages/wzpz/type.ts +57 -57
  213. package/packages/wzpz/types.ts +351 -351
  214. package/packages/yzcg/index.ts +14 -14
  215. package/packages/yzcg/main.ts +66 -66
  216. package/packages/yzcg/types.ts +34 -34
  217. package/packages/yzht/bill.ts +22 -22
  218. package/packages/yzht/glpz.ts +41 -41
  219. package/packages/yzht/index.ts +20 -20
  220. package/packages/yzht/main.ts +208 -208
  221. package/packages/yzht/types.ts +162 -162
  222. package/packages/yzpz/cnfg.ts +57 -57
  223. package/packages/yzpz/index.ts +29 -29
  224. package/packages/yzpz/item.ts +70 -70
  225. package/packages/yzpz/k0km.ts +51 -51
  226. package/packages/yzpz/k8km.ts +79 -79
  227. package/packages/yzpz/kbkm.ts +40 -40
  228. package/packages/yzpz/type.ts +57 -57
  229. package/packages/yzpz/types.ts +281 -281
  230. package/packages/zbhd/cnfg.ts +60 -60
  231. package/packages/zbhd/index.ts +17 -17
  232. package/packages/zbhd/main.ts +305 -305
  233. package/packages/zbhd/types.ts +281 -281
  234. package/packages/zbzd/index.ts +17 -17
  235. package/packages/zbzd/main.ts +215 -215
  236. package/packages/zbzd/types.ts +165 -165
  237. package/packages/zbzd/zbfl.ts +32 -32
  238. package/pnpm-lock.yaml +237 -0
  239. package/readme.md +1 -1
  240. package/packages/antv/type.ts~ +0 -57
  241. package/packages/card/index.ts~ +0 -47
  242. package/packages/card/tzclbsort.ts~ +0 -36
  243. package/packages/card/zccz.ts~ +0 -106
  244. package/packages/core/laid.ts~ +0 -84
  245. package/packages/expd/type.ts~ +0 -17
  246. package/packages/noti/type.ts~ +0 -29
  247. package/packages/wtui/type.ts~ +0 -380
@@ -1,57 +1,57 @@
1
- import { TAntv } from "@ningboyz/types";
2
- import type { HttpRequest } from "../axios";
3
- import { IAntvParaDetaildbQuerys, IAntvParaSelectdbQuerys } from "./types";
4
-
5
- class ParaRequest {
6
- private httpRequest: HttpRequest;
7
- constructor(httpRequest: HttpRequest) {
8
- this.httpRequest = httpRequest;
9
- }
10
-
11
- /**
12
- * 获取数字提取参数列表
13
- * @param querys
14
- * @returns
15
- */
16
- selectdb(querys: IAntvParaSelectdbQuerys) {
17
- return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/selectdb", querys, undefined);
18
- }
19
-
20
- /**
21
- * 新增数字提取参数
22
- * @param querys
23
- * @returns
24
- */
25
- insertdb(Querys: object) {
26
- return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/insertdb", undefined, Querys);
27
- }
28
-
29
- /**
30
- * 修改数字提取参数
31
- * @param querys
32
- * @returns
33
- */
34
- updatedb(Querys: object) {
35
- return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/updatedb", undefined, Querys);
36
- }
37
-
38
- /**
39
- * 删除数字提取参数
40
- * @param querys
41
- * @returns
42
- */
43
- deletedb(Querys: object) {
44
- return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/deletedb", undefined, Querys);
45
- }
46
-
47
- /**
48
- * 获取数字提取参数详情
49
- * @param querys
50
- * @returns
51
- */
52
- detaildb(querys: IAntvParaDetaildbQuerys) {
53
- return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/detaildb", querys, undefined);
54
- }
55
- }
56
-
57
- export default ParaRequest;
1
+ import { TAntv } from "@ningboyz/types";
2
+ import type { HttpRequest } from "../axios";
3
+ import { IAntvParaDetaildbQuerys, IAntvParaSelectdbQuerys } from "./types";
4
+
5
+ class ParaRequest {
6
+ private httpRequest: HttpRequest;
7
+ constructor(httpRequest: HttpRequest) {
8
+ this.httpRequest = httpRequest;
9
+ }
10
+
11
+ /**
12
+ * 获取数字提取参数列表
13
+ * @param querys
14
+ * @returns
15
+ */
16
+ selectdb(querys: IAntvParaSelectdbQuerys) {
17
+ return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/selectdb", querys, undefined);
18
+ }
19
+
20
+ /**
21
+ * 新增数字提取参数
22
+ * @param querys
23
+ * @returns
24
+ */
25
+ insertdb(Querys: object) {
26
+ return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/insertdb", undefined, Querys);
27
+ }
28
+
29
+ /**
30
+ * 修改数字提取参数
31
+ * @param querys
32
+ * @returns
33
+ */
34
+ updatedb(Querys: object) {
35
+ return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/updatedb", undefined, Querys);
36
+ }
37
+
38
+ /**
39
+ * 删除数字提取参数
40
+ * @param querys
41
+ * @returns
42
+ */
43
+ deletedb(Querys: object) {
44
+ return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/deletedb", undefined, Querys);
45
+ }
46
+
47
+ /**
48
+ * 获取数字提取参数详情
49
+ * @param querys
50
+ * @returns
51
+ */
52
+ detaildb(querys: IAntvParaDetaildbQuerys) {
53
+ return this.httpRequest.post<TAntv.IAntvParaResponse[]>("/antv/tpara/detaildb", querys, undefined);
54
+ }
55
+ }
56
+
57
+ export default ParaRequest;
@@ -1,59 +1,59 @@
1
- /** cnfg */
2
- export interface IAntvCnfgSelectdbQuerys {
3
- antvmain: number;
4
- }
5
-
6
- export class TAntvCnfgSelectdbQuerys implements IAntvCnfgSelectdbQuerys {
7
- antvmain: number = -1;
8
- }
9
-
10
- export interface IAntvCnfgDetaildbQuerys {
11
- antvmain: number;
12
- }
13
-
14
- export class TAntvCnfgDetaildbQuerys implements IAntvCnfgDetaildbQuerys {
15
- antvmain: number = -1;
16
- }
17
-
18
- /** main */
19
- export interface IAntvMainDetaildbQuerys {
20
- antvmain: number;
21
- }
22
-
23
- export class TAntvMainDetaildbQuerys implements IAntvMainDetaildbQuerys {
24
- antvmain: number = -1;
25
- }
26
-
27
- export interface IAntvMainGet5DataQuerys {
28
- antvname: string;
29
- cnfgname: string;
30
- unittypetext: string;
31
- [key: string]: string;
32
- }
33
-
34
- export class TAntvMainGet5DataQuerys implements IAntvMainGet5DataQuerys {
35
- antvname: string = "";
36
- cnfgname: string = "";
37
- unittypetext: string = "";
38
-
39
- [key: string]: string;
40
- }
41
-
42
- /** para */
43
- export interface IAntvParaSelectdbQuerys {
44
- antvmain: number;
45
- antvcnfg: number;
46
- }
47
-
48
- export class TAntvParaSelectdbQuerys implements IAntvParaSelectdbQuerys {
49
- antvmain: number = -1;
50
- antvcnfg: number = -1;
51
- }
52
-
53
- export interface IAntvParaDetaildbQuerys {
54
- antvmain: number;
55
- }
56
-
57
- export class TAntvParaDetaildbQuerys implements IAntvParaDetaildbQuerys {
58
- antvmain: number = -1;
59
- }
1
+ /** cnfg */
2
+ export interface IAntvCnfgSelectdbQuerys {
3
+ antvmain: number;
4
+ }
5
+
6
+ export class TAntvCnfgSelectdbQuerys implements IAntvCnfgSelectdbQuerys {
7
+ antvmain: number = -1;
8
+ }
9
+
10
+ export interface IAntvCnfgDetaildbQuerys {
11
+ antvmain: number;
12
+ }
13
+
14
+ export class TAntvCnfgDetaildbQuerys implements IAntvCnfgDetaildbQuerys {
15
+ antvmain: number = -1;
16
+ }
17
+
18
+ /** main */
19
+ export interface IAntvMainDetaildbQuerys {
20
+ antvmain: number;
21
+ }
22
+
23
+ export class TAntvMainDetaildbQuerys implements IAntvMainDetaildbQuerys {
24
+ antvmain: number = -1;
25
+ }
26
+
27
+ export interface IAntvMainGet5DataQuerys {
28
+ antvname: string;
29
+ cnfgname: string;
30
+ unittypetext: string;
31
+ [key: string]: string;
32
+ }
33
+
34
+ export class TAntvMainGet5DataQuerys implements IAntvMainGet5DataQuerys {
35
+ antvname: string = "";
36
+ cnfgname: string = "";
37
+ unittypetext: string = "";
38
+
39
+ [key: string]: string;
40
+ }
41
+
42
+ /** para */
43
+ export interface IAntvParaSelectdbQuerys {
44
+ antvmain: number;
45
+ antvcnfg: number;
46
+ }
47
+
48
+ export class TAntvParaSelectdbQuerys implements IAntvParaSelectdbQuerys {
49
+ antvmain: number = -1;
50
+ antvcnfg: number = -1;
51
+ }
52
+
53
+ export interface IAntvParaDetaildbQuerys {
54
+ antvmain: number;
55
+ }
56
+
57
+ export class TAntvParaDetaildbQuerys implements IAntvParaDetaildbQuerys {
58
+ antvmain: number = -1;
59
+ }
package/packages/axios.ts CHANGED
@@ -1,168 +1,168 @@
1
- import type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from "axios";
2
- import axios from "axios";
3
- import _ from "lodash";
4
- import { TResp } from "@ningboyz/types";
5
- import { ISessionUserInfo, TSessionUserInfo } from "@ningboyz/types/src/store";
6
-
7
- export interface IAxiosConfig {
8
- baseURL: string;
9
- timeout?: number;
10
- getUserInfo?: () => ISessionUserInfo;
11
- interceptorsRequest?: (request: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any>;
12
- interceptorsResponse?: (response: AxiosResponse<any>) => AxiosResponse<any>;
13
- }
14
-
15
- class HttpRequest {
16
- private instance: AxiosInstance;
17
- private readonly METHOD_GET: string = "GET";
18
- private readonly METHOD_POST: string = "POST";
19
-
20
- // 实现一个方法将传入的querys每一个key都转换为小写
21
- private toLowerCase(querys: object) {
22
- return _.mapKeys(querys, (value, key) => key.toLowerCase());
23
- }
24
-
25
- constructor(config: IAxiosConfig) {
26
- const { baseURL, timeout = 60000, getUserInfo, interceptorsRequest, interceptorsResponse } = config;
27
- this.instance = axios.create({
28
- baseURL,
29
- timeout
30
- });
31
- /**用户传了请求中间件 */
32
- if (!_.isNil(interceptorsRequest)) {
33
- this.instance.interceptors.request.use(interceptorsRequest);
34
- } else {
35
- this.instance.interceptors.request.use((request) => {
36
- const userInfo = !_.isNil(getUserInfo) ? getUserInfo() : new TSessionUserInfo();
37
- /** 添加随机数,防止浏览器接口缓存 */
38
- const time = new Date().getTime() + Math.round(Math.random() * 1000);
39
- request.params = {
40
- whobuild: userInfo.whobuild !== 0 ? userInfo.whobuild : undefined,
41
- userindx: userInfo.userIndx !== 0 ? userInfo.userIndx : undefined,
42
- ...request.params,
43
- r: time
44
- };
45
- request.headers.usrtoken = userInfo.usrtoken ?? request.headers?.usrtoken;
46
- request.headers.dbconfig = userInfo.dbConfig;
47
- return request;
48
- });
49
- }
50
-
51
- /**用户传了响应中间件 */
52
- if (!_.isNil(interceptorsResponse)) {
53
- this.instance.interceptors.response.use(interceptorsResponse);
54
- } else {
55
- this.instance.interceptors.response.use((response) => {
56
- return response;
57
- });
58
- }
59
- }
60
-
61
- getFormData(data: object) {
62
- if (data instanceof FormData) {
63
- return data;
64
- }
65
- const formData = new FormData();
66
- formData.append("params", JSON.stringify(data));
67
- return formData;
68
- }
69
-
70
- get<T>(url: string, querys?: object): Promise<TResp.IResponse<T>> {
71
- const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
72
- return new Promise((resolve, reject) => {
73
- this.instance
74
- .request<T>({
75
- method: this.METHOD_GET,
76
- url,
77
- params: lowerQuerys
78
- })
79
- .then((res: AxiosResponse) => {
80
- resolve(res.data as TResp.IResponse<T>);
81
- })
82
- .catch((err: any) => {
83
- reject(err);
84
- });
85
- });
86
- }
87
-
88
- post<T>(url: string, querys?: object, params?: object, headers?: object): Promise<TResp.IResponse<T>> {
89
- const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
90
- return new Promise((resolve, reject) => {
91
- const data = !_.isNil(params) ? this.getFormData(params) : void 0;
92
- this.instance
93
- .request<T>({
94
- method: this.METHOD_POST,
95
- url,
96
- params: lowerQuerys,
97
- data,
98
- headers: {
99
- ...headers
100
- }
101
- })
102
- .then((res: AxiosResponse) => {
103
- resolve(res.data as TResp.IResponse<T>);
104
- })
105
- .catch((err: any) => {
106
- reject(err);
107
- });
108
- });
109
- }
110
-
111
- postJson<T>(url: string, querys?: object, params?: object, headers?: object): Promise<TResp.IResponse<T>> {
112
- const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
113
- return new Promise((resolve, reject) => {
114
- const data = !_.isNil(params) ? params: void 0;
115
- this.instance
116
- .request<T>({
117
- method: this.METHOD_POST,
118
- url,
119
- params: lowerQuerys,
120
- data,
121
- headers: {
122
- ...headers
123
- }
124
- })
125
- .then((res: AxiosResponse) => {
126
- resolve(res.data as TResp.IResponse<T>);
127
- })
128
- .catch((err: any) => {
129
- reject(err);
130
- });
131
- });
132
- }
133
-
134
-
135
- postFile<T>(url: string, querys?: object, params?: object): Promise<TResp.IResponse<T>> {
136
- const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
137
- return new Promise((resolve, reject) => {
138
- const data = !_.isNil(params) ? this.getFormData(params) : void 0;
139
- this.instance
140
- .request({
141
- url,
142
- method: this.METHOD_POST,
143
- params: lowerQuerys,
144
- data,
145
- headers: {
146
- "Content-Type": `multipart/form-data;boundary=${new Date().getTime()}`
147
- }
148
- })
149
- .then((res: AxiosResponse) => {
150
- resolve(res.data as TResp.IResponse<T>);
151
- })
152
- .catch((err: any) => {
153
- reject(err);
154
- });
155
- });
156
- }
157
-
158
- getInstance() {
159
- return this.instance;
160
- }
161
- }
162
-
163
- function createRequest(config: IAxiosConfig) {
164
- return new HttpRequest(config);
165
- }
166
-
167
- export { createRequest };
168
- export type { HttpRequest, AxiosResponse, InternalAxiosRequestConfig };
1
+ import type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from "axios";
2
+ import axios from "axios";
3
+ import _ from "lodash";
4
+ import { TResp } from "@ningboyz/types";
5
+ import { ISessionUserInfo, TSessionUserInfo } from "@ningboyz/types/src/store";
6
+
7
+ export interface IAxiosConfig {
8
+ baseURL: string;
9
+ timeout?: number;
10
+ getUserInfo?: () => ISessionUserInfo;
11
+ interceptorsRequest?: (request: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any>;
12
+ interceptorsResponse?: (response: AxiosResponse<any>) => AxiosResponse<any>;
13
+ }
14
+
15
+ class HttpRequest {
16
+ private instance: AxiosInstance;
17
+ private readonly METHOD_GET: string = "GET";
18
+ private readonly METHOD_POST: string = "POST";
19
+
20
+ // 实现一个方法将传入的querys每一个key都转换为小写
21
+ private toLowerCase(querys: object) {
22
+ return _.mapKeys(querys, (value, key) => key.toLowerCase());
23
+ }
24
+
25
+ constructor(config: IAxiosConfig) {
26
+ const { baseURL, timeout = 60000, getUserInfo, interceptorsRequest, interceptorsResponse } = config;
27
+ this.instance = axios.create({
28
+ baseURL,
29
+ timeout
30
+ });
31
+ /**用户传了请求中间件 */
32
+ if (!_.isNil(interceptorsRequest)) {
33
+ this.instance.interceptors.request.use(interceptorsRequest);
34
+ } else {
35
+ this.instance.interceptors.request.use((request) => {
36
+ const userInfo = !_.isNil(getUserInfo) ? getUserInfo() : new TSessionUserInfo();
37
+ /** 添加随机数,防止浏览器接口缓存 */
38
+ const time = new Date().getTime() + Math.round(Math.random() * 1000);
39
+ request.params = {
40
+ whobuild: userInfo.whobuild !== 0 ? userInfo.whobuild : undefined,
41
+ userindx: userInfo.userIndx !== 0 ? userInfo.userIndx : undefined,
42
+ ...request.params,
43
+ r: time
44
+ };
45
+ request.headers.usrtoken = userInfo.usrtoken ?? request.headers?.usrtoken;
46
+ request.headers.dbconfig = userInfo.dbConfig;
47
+ return request;
48
+ });
49
+ }
50
+
51
+ /**用户传了响应中间件 */
52
+ if (!_.isNil(interceptorsResponse)) {
53
+ this.instance.interceptors.response.use(interceptorsResponse);
54
+ } else {
55
+ this.instance.interceptors.response.use((response) => {
56
+ return response;
57
+ });
58
+ }
59
+ }
60
+
61
+ getFormData(data: object) {
62
+ if (data instanceof FormData) {
63
+ return data;
64
+ }
65
+ const formData = new FormData();
66
+ formData.append("params", JSON.stringify(data));
67
+ return formData;
68
+ }
69
+
70
+ get<T>(url: string, querys?: object): Promise<TResp.IResponse<T>> {
71
+ const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
72
+ return new Promise((resolve, reject) => {
73
+ this.instance
74
+ .request<T>({
75
+ method: this.METHOD_GET,
76
+ url,
77
+ params: lowerQuerys
78
+ })
79
+ .then((res: AxiosResponse) => {
80
+ resolve(res.data as TResp.IResponse<T>);
81
+ })
82
+ .catch((err: any) => {
83
+ reject(err);
84
+ });
85
+ });
86
+ }
87
+
88
+ post<T>(url: string, querys?: object, params?: object, headers?: object): Promise<TResp.IResponse<T>> {
89
+ const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
90
+ return new Promise((resolve, reject) => {
91
+ const data = !_.isNil(params) ? this.getFormData(params) : void 0;
92
+ this.instance
93
+ .request<T>({
94
+ method: this.METHOD_POST,
95
+ url,
96
+ params: lowerQuerys,
97
+ data,
98
+ headers: {
99
+ ...headers
100
+ }
101
+ })
102
+ .then((res: AxiosResponse) => {
103
+ resolve(res.data as TResp.IResponse<T>);
104
+ })
105
+ .catch((err: any) => {
106
+ reject(err);
107
+ });
108
+ });
109
+ }
110
+
111
+ postJson<T>(url: string, querys?: object, params?: object, headers?: object): Promise<TResp.IResponse<T>> {
112
+ const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
113
+ return new Promise((resolve, reject) => {
114
+ const data = !_.isNil(params) ? params: void 0;
115
+ this.instance
116
+ .request<T>({
117
+ method: this.METHOD_POST,
118
+ url,
119
+ params: lowerQuerys,
120
+ data,
121
+ headers: {
122
+ ...headers
123
+ }
124
+ })
125
+ .then((res: AxiosResponse) => {
126
+ resolve(res.data as TResp.IResponse<T>);
127
+ })
128
+ .catch((err: any) => {
129
+ reject(err);
130
+ });
131
+ });
132
+ }
133
+
134
+
135
+ postFile<T>(url: string, querys?: object, params?: object): Promise<TResp.IResponse<T>> {
136
+ const lowerQuerys = querys ? this.toLowerCase(querys) : undefined;
137
+ return new Promise((resolve, reject) => {
138
+ const data = !_.isNil(params) ? this.getFormData(params) : void 0;
139
+ this.instance
140
+ .request({
141
+ url,
142
+ method: this.METHOD_POST,
143
+ params: lowerQuerys,
144
+ data,
145
+ headers: {
146
+ "Content-Type": `multipart/form-data;boundary=${new Date().getTime()}`
147
+ }
148
+ })
149
+ .then((res: AxiosResponse) => {
150
+ resolve(res.data as TResp.IResponse<T>);
151
+ })
152
+ .catch((err: any) => {
153
+ reject(err);
154
+ });
155
+ });
156
+ }
157
+
158
+ getInstance() {
159
+ return this.instance;
160
+ }
161
+ }
162
+
163
+ function createRequest(config: IAxiosConfig) {
164
+ return new HttpRequest(config);
165
+ }
166
+
167
+ export { createRequest };
168
+ export type { HttpRequest, AxiosResponse, InternalAxiosRequestConfig };