@indfnd/utils 0.1.29 → 0.1.31

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.29",
3
+ "version": "0.1.31",
4
4
  "author": "huxuetong",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
package/src/api/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from './com'
4
4
  export * from './index-desc'
5
5
  export * from './item'
6
6
  export * from './user'
7
+ export * from './permission'
@@ -0,0 +1,31 @@
1
+ import { axios } from '@/utils'
2
+ import { config } from '@/config'
3
+ import { getLocalStorage, setLocalStorage } from '@/utils/storage'
4
+
5
+ const UC_CONTEXT = config.ucExtServerContext
6
+
7
+ const DATAVERSION_KEY = 'ind-cache-dataVersion-applicationTree'
8
+
9
+ export async function getApplicationTreeApi(params) {
10
+ //1.读取缓存,获得版本号
11
+ const cachedData = getLocalStorage(DATAVERSION_KEY)
12
+
13
+ //2. 请求后端版本号
14
+ const dataVersionList = await axios.get(`${UC_CONTEXT}/cacheManage/getCacheDataVersion`, {})
15
+ const serverVersion = dataVersionList.data['applicationTree']
16
+
17
+ //3. 对比版本号
18
+ if (cachedData?.dataVersion !== serverVersion) {
19
+ //3.1 重新请求后端服务获取最新数据,并写入缓存
20
+ const response = await axios.get(`${UC_CONTEXT}/tree/uc-application/getApplicationTree`, {
21
+ params,
22
+ })
23
+ const dataValue = {
24
+ dataVersion: serverVersion,
25
+ response: response,
26
+ }
27
+ setLocalStorage(DATAVERSION_KEY, dataValue)
28
+ }
29
+ //(4)3.2 使用缓存数据
30
+ return getLocalStorage(DATAVERSION_KEY)?.response
31
+ }
package/src/api/user.ts CHANGED
@@ -1,8 +1,29 @@
1
1
  import { axios } from '@/utils'
2
2
  import { config } from '@/config'
3
+ import { getLocalStorage, setLocalStorage } from '@/utils/storage'
3
4
 
4
5
  const UC_CONTEXT = config.ucExtServerContext
5
6
 
6
- export function listUserTreeApi(params) {
7
- return axios.get(`${UC_CONTEXT}/tree/uc-user/listUserTree`, { params })
7
+ const DATAVERSION_KEY = 'ind-cache-dataVersion-organTree'
8
+
9
+ export async function listUserTreeApi(params) {
10
+ //1.读取缓存,获得版本号
11
+ const cachedData = getLocalStorage(DATAVERSION_KEY)
12
+
13
+ //2. 请求后端版本号
14
+ const dataVersionList = await axios.get(`${UC_CONTEXT}/cacheManage/getCacheDataVersion`, {})
15
+ const serverVersion = dataVersionList.data['organTree']
16
+
17
+ //3. 对比版本号
18
+ if (cachedData?.dataVersion !== serverVersion) {
19
+ //3.1 重新请求后端服务获取最新数据,并写入缓存
20
+ const response = await axios.get(`${UC_CONTEXT}/tree/uc-user/listUserTree`, { params })
21
+ const dataValue = {
22
+ dataVersion: serverVersion,
23
+ response: response,
24
+ }
25
+ setLocalStorage(DATAVERSION_KEY, dataValue)
26
+ }
27
+ //(4)3.2 使用缓存数据
28
+ return getLocalStorage(DATAVERSION_KEY)?.response
8
29
  }
@@ -1,6 +1,7 @@
1
- export * from './platform';
2
- export * from './com';
3
- export * from './index-desc';
4
- export * from './item';
5
- export * from './user';
6
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './platform'
2
+ export * from './com'
3
+ export * from './index-desc'
4
+ export * from './item'
5
+ export * from './user'
6
+ export * from './permission'
7
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function getApplicationTreeApi(params: any): Promise<any>
2
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../../src/api/permission.ts"],"names":[],"mappings":"AAQA,wBAAsB,qBAAqB,CAAC,MAAM,KAAA,gBAsBjD"}
@@ -1,2 +1,2 @@
1
- export declare function listUserTreeApi(params: any): Promise<import("axios").AxiosResponse<any, any>>;
2
- //# sourceMappingURL=user.d.ts.map
1
+ export declare function listUserTreeApi(params: any): Promise<any>
2
+ //# sourceMappingURL=user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/api/user.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,CAAC,MAAM,KAAA,oDAErC"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/api/user.ts"],"names":[],"mappings":"AAQA,wBAAsB,eAAe,CAAC,MAAM,KAAA,gBAoB3C"}