@pnt-team/pnt-component-frontend 0.0.35 → 0.0.38
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/README.md +71 -64
- package/lib/cjs/components/PntSecureBox/index.d.ts +11 -0
- package/lib/cjs/components/PntSecureBox/index.js +11 -2
- package/lib/cjs/hooks/useHighSecurity.d.ts +47 -5
- package/lib/cjs/hooks/useHighSecurity.js +25 -12
- package/lib/cjs/hooks/useOsPlatformList.d.ts +14 -16
- package/lib/cjs/hooks/useOsPlatformList.js +5 -21
- package/lib/esm/components/PntSecureBox/index.d.ts +11 -0
- package/lib/esm/components/PntSecureBox/index.js +14 -3
- package/lib/esm/hooks/useHighSecurity.d.ts +47 -5
- package/lib/esm/hooks/useHighSecurity.js +25 -12
- package/lib/esm/hooks/useOsPlatformList.d.ts +14 -16
- package/lib/esm/hooks/useOsPlatformList.js +5 -10
- package/lib/umd/pnt-component-frontend.min.js +1 -1
- package/package.json +1 -1
- package/lib/cjs/api/index.d.ts +0 -17
- package/lib/cjs/api/index.js +0 -45
- package/lib/cjs/configs/host.d.ts +0 -12
- package/lib/cjs/configs/host.js +0 -39
- package/lib/cjs/configs/token.d.ts +0 -2
- package/lib/cjs/configs/token.js +0 -25
- package/lib/esm/api/index.d.ts +0 -17
- package/lib/esm/api/index.js +0 -11
- package/lib/esm/configs/host.d.ts +0 -12
- package/lib/esm/configs/host.js +0 -19
- package/lib/esm/configs/token.d.ts +0 -2
- package/lib/esm/configs/token.js +0 -5
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
// src/hooks/useHighSecurity.ts
|
|
2
|
-
import { highSecurity } from "../api";
|
|
3
2
|
import { useState } from "react";
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
var securityCache = /* @__PURE__ */ new Map();
|
|
4
|
+
var useHighSecurity = (fetcher) => {
|
|
5
|
+
const [securityData, setSecurityData] = useState(
|
|
6
|
+
() => {
|
|
7
|
+
const cached = {};
|
|
8
|
+
securityCache.forEach((value, key) => {
|
|
9
|
+
cached[key] = value;
|
|
10
|
+
});
|
|
11
|
+
return cached;
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
const requestSecurityData = async ({
|
|
15
|
+
gameId,
|
|
16
|
+
param,
|
|
17
|
+
env,
|
|
18
|
+
pageId
|
|
19
|
+
}) => {
|
|
20
|
+
const result = await fetcher({
|
|
21
|
+
gameId,
|
|
9
22
|
env: Number(env),
|
|
10
|
-
|
|
11
|
-
page_id: location.pathname,
|
|
23
|
+
pageId: pageId || location.pathname,
|
|
12
24
|
param
|
|
13
25
|
});
|
|
14
|
-
if (ret === 0) {
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
if (result.ret === 0 && result.data) {
|
|
27
|
+
result.data.forEach((item) => {
|
|
28
|
+
securityCache.set(item.key, item.value);
|
|
29
|
+
});
|
|
30
|
+
setSecurityData(Object.fromEntries(securityCache));
|
|
17
31
|
}
|
|
18
32
|
};
|
|
19
33
|
return {
|
|
20
34
|
securityData,
|
|
21
|
-
setSecurityData,
|
|
22
35
|
requestSecurityData
|
|
23
36
|
};
|
|
24
37
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { commonEesType } from '../utils/request';
|
|
2
1
|
/** OS 平台数据类型定义 */
|
|
3
2
|
export interface OsItem {
|
|
4
3
|
id: number;
|
|
@@ -17,14 +16,12 @@ export interface OsPlatformData {
|
|
|
17
16
|
os_list: OsItem[];
|
|
18
17
|
platform_list: PlatformItem[];
|
|
19
18
|
}
|
|
20
|
-
/** OS
|
|
21
|
-
export type OsPlatformFetcher = () => Promise<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
export declare const defaultOsPlatformFetcher: OsPlatformFetcher;
|
|
19
|
+
/** OS/平台列表请求函数:返回 { code, msg, data } 结构且 code === 0 视为成功 */
|
|
20
|
+
export type OsPlatformFetcher = () => Promise<{
|
|
21
|
+
code: number;
|
|
22
|
+
msg: string;
|
|
23
|
+
data: OsPlatformData;
|
|
24
|
+
}>;
|
|
28
25
|
/**
|
|
29
26
|
* 清除缓存(用于极少数需要强制刷新的场景,如后台更新了平台列表后)。
|
|
30
27
|
* @param fetcher 指定要清除的 fetcher;不传则清除全部缓存
|
|
@@ -36,20 +33,21 @@ export declare const clearOsPlatformListCache: (fetcher?: OsPlatformFetcher) =>
|
|
|
36
33
|
* 拉取 OS 与平台枚举数据并做模块级缓存,整个会话只请求一次;
|
|
37
34
|
* 并发调用共享同一个进行中的请求。
|
|
38
35
|
*
|
|
39
|
-
* 零业务侵入:数据接口通过 fetcher
|
|
40
|
-
*
|
|
36
|
+
* 零业务侵入:数据接口通过 fetcher 注入,不再依赖内部 request/configs,
|
|
37
|
+
* 避免将敏感配置打包进发布产物。
|
|
41
38
|
*
|
|
42
39
|
* @param fetcher 自定义请求函数,需返回 { code, msg, data } 结构且 code === 0 视为成功
|
|
43
40
|
* @returns osPlatformList OS/平台数据,请求完成或命中缓存前为 undefined
|
|
44
41
|
*
|
|
45
42
|
* @example
|
|
46
43
|
* ```tsx
|
|
47
|
-
* import
|
|
44
|
+
* import http from '@/utils/request';
|
|
45
|
+
* import { useOsPlatformList } from '@pnt-team/pnt-component-frontend';
|
|
48
46
|
*
|
|
49
47
|
* const Demo = () => {
|
|
50
|
-
* const { osPlatformList } = useOsPlatformList()
|
|
51
|
-
*
|
|
52
|
-
*
|
|
48
|
+
* const { osPlatformList } = useOsPlatformList(() =>
|
|
49
|
+
* http.get('/api/internal/business/manage/osPlatformList').then(r => r.data)
|
|
50
|
+
* );
|
|
53
51
|
*
|
|
54
52
|
* return (
|
|
55
53
|
* <Select
|
|
@@ -62,7 +60,7 @@ export declare const clearOsPlatformListCache: (fetcher?: OsPlatformFetcher) =>
|
|
|
62
60
|
* };
|
|
63
61
|
* ```
|
|
64
62
|
*/
|
|
65
|
-
export declare const useOsPlatformList: (fetcher
|
|
63
|
+
export declare const useOsPlatformList: (fetcher: OsPlatformFetcher) => {
|
|
66
64
|
osPlatformList: OsPlatformData | undefined;
|
|
67
65
|
};
|
|
68
66
|
export default useOsPlatformList;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// src/hooks/useOsPlatformList.ts
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
import http from "../utils/request";
|
|
4
|
-
var defaultOsPlatformFetcher = () => http.get("/api/internal/business/manage/osPlatformList");
|
|
5
3
|
var cacheMap = /* @__PURE__ */ new Map();
|
|
6
4
|
var fetchOsPlatformList = async (fetcher) => {
|
|
7
5
|
const cached = cacheMap.get(fetcher);
|
|
@@ -32,13 +30,11 @@ var clearOsPlatformListCache = (fetcher) => {
|
|
|
32
30
|
cacheMap.clear();
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
|
-
var useOsPlatformList = (fetcher
|
|
36
|
-
const [osPlatformList, setOsPlatformList] = useState(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
);
|
|
33
|
+
var useOsPlatformList = (fetcher) => {
|
|
34
|
+
const [osPlatformList, setOsPlatformList] = useState(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
37
|
+
});
|
|
42
38
|
useEffect(() => {
|
|
43
39
|
var _a;
|
|
44
40
|
const cached = (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
@@ -63,6 +59,5 @@ var useOsPlatformList_default = useOsPlatformList;
|
|
|
63
59
|
export {
|
|
64
60
|
clearOsPlatformListCache,
|
|
65
61
|
useOsPlatformList_default as default,
|
|
66
|
-
defaultOsPlatformFetcher,
|
|
67
62
|
useOsPlatformList
|
|
68
63
|
};
|