@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.
@@ -1,24 +1,37 @@
1
1
  // src/hooks/useHighSecurity.ts
2
- import { highSecurity } from "../api";
3
2
  import { useState } from "react";
4
- var useHighSecurity = () => {
5
- const [securityData, setSecurityData] = useState({});
6
- const requestSecurityData = async ({ gameId, param, env }) => {
7
- var _a;
8
- const { ret, data } = await highSecurity({
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
- game_id: Number(gameId),
11
- page_id: location.pathname,
23
+ pageId: pageId || location.pathname,
12
24
  param
13
25
  });
14
- if (ret === 0) {
15
- securityData[param == null ? void 0 : param[0].key] = (_a = data == null ? void 0 : data[0]) == null ? void 0 : _a.value;
16
- setSecurityData({ ...securityData });
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/平台列表请求函数:返回与 src/utils/request 响应拦截器解析后的结构一致({ code, msg, data }) */
21
- export type OsPlatformFetcher = () => Promise<commonEesType<OsPlatformData>>;
22
- /**
23
- * 默认 fetcher:基于 src/utils/request 请求 OS/平台枚举接口。
24
- * 与源项目 account-business-frontend 的 getOsPlatformList 接口路径一致;
25
- * audience 参数由 request 拦截器自动补齐。
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 注入,不传时使用内置默认 fetcher
40
- * (基于 src/utils/request 请求 /api/internal/business/manage/osPlatformList)。
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 { useOsPlatformList } from '@pnt/business-components';
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
- * // 或注入自定义 fetcher(建议用 useCallback 保持引用稳定)
52
- * // const { osPlatformList } = useOsPlatformList(() => http.get('/my/os/platform'));
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?: OsPlatformFetcher) => {
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 = defaultOsPlatformFetcher) => {
36
- const [osPlatformList, setOsPlatformList] = useState(
37
- () => {
38
- var _a;
39
- return (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
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
  };