@indfnd/utils 0.1.38 → 0.1.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indfnd/utils",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "author": "huxuetong",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -34,7 +34,7 @@
34
34
  "re-publish": "yarn publish --access public"
35
35
  },
36
36
  "dependencies": {
37
- "axios": "^0.24.0",
37
+ "axios": "^1.8.0",
38
38
  "dayjs": "^1.11.9",
39
39
  "lodash": "^4.17.21",
40
40
  "md5": "^2.3.0",
@@ -26,19 +26,21 @@ instance.formPost = function (url, data, config) {
26
26
  */
27
27
  export const wrapApi = (api, isPost = false) => {
28
28
  // 每个函数都有自己的 controller,避免互相干扰
29
- let currentController = null
29
+ let controllerMapping = {}
30
30
 
31
31
  const wrappedFunction = async function (...args) {
32
+ let url = args[0]
33
+
32
34
  // 取消之前的请求
33
- if (currentController) {
35
+ if (controllerMapping[url]) {
34
36
  console.log('currentController.abort trigger, now cancel before request')
35
- currentController.abort()
36
- currentController = null
37
+ controllerMapping[url].abort()
38
+ controllerMapping[url] = null
37
39
  }
38
40
 
39
41
  // 创建新的 AbortController
40
42
  const controller = new AbortController()
41
- currentController = controller
43
+ controllerMapping[url] = controller
42
44
 
43
45
  // 准备参数
44
46
  const newArgs = [...args]
@@ -97,7 +99,7 @@ export const wrapApi = (api, isPost = false) => {
97
99
  const result = await api(...newArgs)
98
100
 
99
101
  // 请求成功后清理 controller
100
- currentController = null
102
+ controllerMapping[url] = null
101
103
  return result
102
104
  } catch (error) {
103
105
  // 如果是取消错误,重新抛出
@@ -113,24 +115,24 @@ export const wrapApi = (api, isPost = false) => {
113
115
  throw error
114
116
  } finally {
115
117
  // 如果当前 controller 仍然是这个请求的,清理它
116
- if (currentController === controller) {
117
- currentController = null
118
+ if (controllerMapping[url] === controller) {
119
+ controllerMapping[url] = null
118
120
  }
119
121
  }
120
122
  }
121
123
 
122
- // 添加取消方法,允许外部取消
123
- wrappedFunction.cancel = (reason) => {
124
- if (currentController) {
125
- currentController.abort(reason)
126
- currentController = null
127
- }
128
- }
129
-
130
- // 添加检查是否正在请求的方法
131
- wrappedFunction.isPending = () => {
132
- return currentController !== null
133
- }
124
+ // // 添加取消方法,允许外部取消
125
+ // wrappedFunction.cancel = (reason) => {
126
+ // if (controllerMapping[url]) {
127
+ // controllerMapping[url].abort(reason)
128
+ // controllerMapping[url] = null
129
+ // }
130
+ // }
131
+
132
+ // // 添加检查是否正在请求的方法
133
+ // wrappedFunction.isPending = () => {
134
+ // return controllerMapping[url] !== null
135
+ // }
134
136
 
135
137
  return wrappedFunction
136
138
  }
@@ -4,24 +4,36 @@ const TOKEN_KEY = 'v8-token'
4
4
 
5
5
  const TOKEN_KEY_IBP = 'lambo-token'
6
6
 
7
+ function isHb() {
8
+ return __IS_HB__
9
+ }
10
+
7
11
  // 要从门户跳转过来,sessionStorage不能带token过来,改成localStorage
8
12
  export function setToken(token: string) {
9
- setLocalStorage(TOKEN_KEY, token)
10
13
  setSessionStorage(TOKEN_KEY_IBP, token)
11
- Cookie.set('TOKEN_KEY', token, 1)
12
- Cookie.set('lambo-sso-key', token, 1)
14
+
15
+ // 以下逻辑将会话信息持久化存储了,湖北企业微信环境每次点击都走一次单点登录逻辑,不持久化存储
16
+ if (!isHb) {
17
+ setLocalStorage(TOKEN_KEY, token)
18
+ Cookie.set('TOKEN_KEY', token, 1)
19
+ Cookie.set('lambo-sso-key', token, 1)
20
+ }
13
21
  }
14
22
 
15
23
  export function getToken(): string | boolean {
16
24
  let token = getSessionStorage(TOKEN_KEY_IBP)
17
- if (!token) {
18
- token = Cookie.get('lambo-sso-key')
19
- }
20
- if (!token) {
21
- token = Cookie.get('TOKEN_KEY')
22
- }
23
- if (!token) {
24
- token = getLocalStorage(TOKEN_KEY)
25
+
26
+ // 以下逻辑将会话信息持久化存储了,湖北企业微信环境每次点击都走一次单点登录逻辑,不持久化存储
27
+ if (!isHb) {
28
+ if (!token) {
29
+ token = Cookie.get('lambo-sso-key')
30
+ }
31
+ if (!token) {
32
+ token = Cookie.get('TOKEN_KEY')
33
+ }
34
+ if (!token) {
35
+ token = getLocalStorage(TOKEN_KEY)
36
+ }
25
37
  }
26
38
  return token || false
27
39
  }
@@ -1,2 +1,2 @@
1
- export declare function listComTreeApi(params: any): Promise<import("axios").AxiosResponse<any>>;
1
+ export declare function listComTreeApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
2
2
  //# sourceMappingURL=com.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"com.d.ts","sourceRoot":"","sources":["../../src/api/com.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,CAAC,MAAM,KAAA,+CAQpC"}
1
+ {"version":3,"file":"com.d.ts","sourceRoot":"","sources":["../../src/api/com.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,CAAC,MAAM,KAAA,wDAQpC"}
@@ -1,2 +1,2 @@
1
- export declare function listIndexDescApi(params: any): Promise<import("axios").AxiosResponse<any>>;
1
+ export declare function listIndexDescApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
2
2
  //# sourceMappingURL=index-desc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-desc.d.ts","sourceRoot":"","sources":["../../src/api/index-desc.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,MAAM,KAAA,+CAEtC"}
1
+ {"version":3,"file":"index-desc.d.ts","sourceRoot":"","sources":["../../src/api/index-desc.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,CAAC,MAAM,KAAA,wDAEtC"}
@@ -1,4 +1,4 @@
1
- export declare function listItemTreeApi(params: any): Promise<import("axios").AxiosResponse<any>>;
2
- export declare function getPriceInfo(): Promise<import("axios").AxiosResponse<any>>;
3
- export declare function getItem(params: any): Promise<import("axios").AxiosResponse<any>>;
1
+ export declare function listItemTreeApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
2
+ export declare function getPriceInfo(): Promise<import("axios").AxiosResponse<any, any, {}>>;
3
+ export declare function getItem(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
4
4
  //# sourceMappingURL=item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../../src/api/item.ts"],"names":[],"mappings":"AAOA,wBAAgB,eAAe,CAAC,MAAM,KAAA,+CAYrC;AACD,wBAAgB,YAAY,gDAE3B;AACD,wBAAgB,OAAO,CAAC,MAAM,KAAA,+CAE7B"}
1
+ {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../../src/api/item.ts"],"names":[],"mappings":"AAOA,wBAAgB,eAAe,CAAC,MAAM,KAAA,wDAYrC;AACD,wBAAgB,YAAY,yDAE3B;AACD,wBAAgB,OAAO,CAAC,MAAM,KAAA,wDAE7B"}
@@ -1,4 +1,4 @@
1
- export declare function getDictsMapApi(dictId: string): Promise<import("axios").AxiosResponse<any>>;
1
+ export declare function getDictsMapApi(dictId: string): Promise<import("axios").AxiosResponse<any, any, {}>>;
2
2
  export declare function getDictApi(dictId: string): Promise<any>;
3
3
  export declare function getDictMapApi(dictIdArr: string[]): Promise<{}>;
4
4
  //# sourceMappingURL=dict.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dict.d.ts","sourceRoot":"","sources":["../../../src/api/platform/dict.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,+CAE5C;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,gBAgB9C;AAkBD,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eActD"}
1
+ {"version":3,"file":"dict.d.ts","sourceRoot":"","sources":["../../../src/api/platform/dict.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,wDAE5C;AAED,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,gBAgB9C;AAkBD,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eActD"}
@@ -1,11 +1,11 @@
1
- export declare function getPermissionApi(): Promise<import("axios").AxiosResponse<any>>;
2
- export declare function getMenuHistoryApi(): Promise<import("axios").AxiosResponse<any>>;
3
- export declare function menuHistoryApi(params: any): Promise<import("axios").AxiosResponse<any>>;
4
- export declare function deleteMenuHistoryApi(historyId: any): Promise<import("axios").AxiosResponse<any>>;
5
- export declare function getMenuCollectApi(): Promise<import("axios").AxiosResponse<any>>;
6
- export declare function addMenuCollectApi(params: any): Promise<import("axios").AxiosResponse<any>>;
7
- export declare function deleteMenuCollectApi(collectId: any): Promise<import("axios").AxiosResponse<any>>;
8
- export declare function removeMenuCollectApi(params: any): Promise<import("axios").AxiosResponse<any>>;
9
- export declare function getAppListApi(): Promise<import("axios").AxiosResponse<any>>;
10
- export declare function getMaxTabNumValueApi(): Promise<import("axios").AxiosResponse<any>>;
1
+ export declare function getPermissionApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
2
+ export declare function getMenuHistoryApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
3
+ export declare function menuHistoryApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
4
+ export declare function deleteMenuHistoryApi(historyId: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
5
+ export declare function getMenuCollectApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
6
+ export declare function addMenuCollectApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
7
+ export declare function deleteMenuCollectApi(collectId: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
8
+ export declare function removeMenuCollectApi(params: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
9
+ export declare function getAppListApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
10
+ export declare function getMaxTabNumValueApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
11
11
  //# sourceMappingURL=menu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/api/platform/menu.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,gDAE/B;AAED,wBAAgB,iBAAiB,gDAEhC;AAED,wBAAgB,cAAc,CAAC,MAAM,KAAA,+CAEpC;AAED,wBAAgB,oBAAoB,CAAC,SAAS,KAAA,+CAE7C;AAED,wBAAgB,iBAAiB,gDAEhC;AAED,wBAAgB,iBAAiB,CAAC,MAAM,KAAA,+CAEvC;AAED,wBAAgB,oBAAoB,CAAC,SAAS,KAAA,+CAE7C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,+CAE1C;AAED,wBAAgB,aAAa,gDAE5B;AAED,wBAAgB,oBAAoB,gDAEnC"}
1
+ {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/api/platform/menu.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,yDAE/B;AAED,wBAAgB,iBAAiB,yDAEhC;AAED,wBAAgB,cAAc,CAAC,MAAM,KAAA,wDAEpC;AAED,wBAAgB,oBAAoB,CAAC,SAAS,KAAA,wDAE7C;AAED,wBAAgB,iBAAiB,yDAEhC;AAED,wBAAgB,iBAAiB,CAAC,MAAM,KAAA,wDAEvC;AAED,wBAAgB,oBAAoB,CAAC,SAAS,KAAA,wDAE7C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,wDAE1C;AAED,wBAAgB,aAAa,yDAE5B;AAED,wBAAgB,oBAAoB,yDAEnC"}
@@ -19,7 +19,7 @@ export declare function putOssFileUrl(): string;
19
19
  * @param responseType 数据类型,支持 arraybuffer | blob | document | json | text | stream
20
20
  * @returns 文件内容
21
21
  */
22
- export declare function getOssFileApi(fileId: string, responseType?: ResponseType): Promise<import("axios").AxiosResponse<any>>;
22
+ export declare function getOssFileApi(fileId: string, responseType?: ResponseType): Promise<import("axios").AxiosResponse<any, any, {}>>;
23
23
  /**
24
24
  * 将文件上传到文档中心
25
25
  *
@@ -27,14 +27,14 @@ export declare function getOssFileApi(fileId: string, responseType?: ResponseTyp
27
27
  * @param blob 文件的Blob数据
28
28
  * @returns 文件Id
29
29
  */
30
- export declare function putOssFileApi(filename: string, blob: Blob): import("axios").AxiosPromise<any>;
30
+ export declare function putOssFileApi(filename: string, blob: Blob): Promise<import("axios").AxiosResponse<any, any, {}>>;
31
31
  /**
32
32
  * 获取文档中心预览URL
33
33
  *
34
34
  * @param fileId 文件Id
35
35
  * @returns 文件内容
36
36
  */
37
- export declare function getPreviewUrlApi(fileId: string): Promise<import("axios").AxiosResponse<any>>;
37
+ export declare function getPreviewUrlApi(fileId: string): Promise<import("axios").AxiosResponse<any, any, {}>>;
38
38
  /**
39
39
  * 获取文档中心预览URL
40
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"oss.d.ts","sourceRoot":"","sources":["../../../src/api/platform/oss.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,YAAY,EAAE,MAAM,OAAO,CAAA;AAOxD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAK,UAExC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,WAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,+CAMxE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,qCAUzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,+CAQ9C;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBA0DrE"}
1
+ {"version":3,"file":"oss.d.ts","sourceRoot":"","sources":["../../../src/api/platform/oss.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,YAAY,EAAE,MAAM,OAAO,CAAA;AAOxD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAK,UAExC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,WAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,wDAMxE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,wDAUzD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,wDAQ9C;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBA0DrE"}
@@ -3,10 +3,10 @@ export declare function loginApi({ userName, password, validCodeId, validCodeInp
3
3
  password: any;
4
4
  validCodeId: any;
5
5
  validCodeInput: any;
6
- }): Promise<import("axios").AxiosResponse<any>>;
7
- export declare function getUserInfoApi(): Promise<import("axios").AxiosResponse<any>>;
8
- export declare function getGlobalPolicyApi(): Promise<import("axios").AxiosResponse<any>>;
9
- export declare function updatePasswordApi(data: any): Promise<import("axios").AxiosResponse<any>>;
6
+ }): Promise<import("axios").AxiosResponse<any, any, {}>>;
7
+ export declare function getUserInfoApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
8
+ export declare function getGlobalPolicyApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
9
+ export declare function updatePasswordApi(data: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
10
10
  export declare function getCaptchaURL(validCodeId: string): string;
11
- export declare function logoutApi(): Promise<import("axios").AxiosResponse<any>>;
11
+ export declare function logoutApi(): Promise<import("axios").AxiosResponse<any, any, {}>>;
12
12
  //# sourceMappingURL=user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/platform/user.ts"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE;;;;;CAAA,+CAQ3E;AAED,wBAAgB,cAAc,gDAE7B;AAED,wBAAgB,kBAAkB,gDAEjC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,+CAErC;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,UAEhD;AAED,wBAAgB,SAAS,gDAExB"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/platform/user.ts"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE;;;;;CAAA,wDAQ3E;AAED,wBAAgB,cAAc,yDAE7B;AAED,wBAAgB,kBAAkB,yDAEjC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,wDAErC;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,UAEhD;AAED,wBAAgB,SAAS,yDAExB"}
@@ -12,10 +12,6 @@ declare const instance: AxiosExtendsInstance;
12
12
  * @param {boolean} isPost - 是否是post请求
13
13
  * @returns {Function} 封装后可取消的api
14
14
  */
15
- export declare const wrapApi: (api: any, isPost?: boolean) => {
16
- (...args: any[]): Promise<any>;
17
- cancel(reason: any): void;
18
- isPending(): boolean;
19
- };
15
+ export declare const wrapApi: (api: any, isPost?: boolean) => (...args: any[]) => Promise<any>;
20
16
  export { instance as axios };
21
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/request/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAuC,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAG1F,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,QAAA,MAAM,QAAQ,EAAE,oBAA+D,CAAA;AAS/E;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO;;;;CA6GnB,CAAA;AAQD,OAAO,EAAE,QAAQ,IAAI,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/request/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,EAAuC,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAG1F,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,QAAA,MAAM,QAAQ,EAAE,oBAA+D,CAAA;AAS/E;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,kEA+GnB,CAAA;AAQD,OAAO,EAAE,QAAQ,IAAI,KAAK,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAKrC;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,OAAO,CAY3C"}
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAWA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QASrC;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,OAAO,CAgB3C"}