@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
package/README.md
CHANGED
|
@@ -12,11 +12,11 @@ yarn add @pnt-team/pnt-component-frontend
|
|
|
12
12
|
|
|
13
13
|
### 依赖要求(peerDependencies)
|
|
14
14
|
|
|
15
|
-
| 依赖
|
|
16
|
-
|
|
17
|
-
| `react`
|
|
18
|
-
| `react-dom`
|
|
19
|
-
| `tdesign-react` | `>=1.5.0`
|
|
15
|
+
| 依赖 | 版本要求 | 说明 |
|
|
16
|
+
| --------------- | ---------- | -------------------------------------- |
|
|
17
|
+
| `react` | `>=16.9.0` | React 核心框架 |
|
|
18
|
+
| `react-dom` | `>=16.9.0` | React DOM 渲染 |
|
|
19
|
+
| `tdesign-react` | `>=1.5.0` | UI 组件库(本组件库基于 TDesign 封装) |
|
|
20
20
|
|
|
21
21
|
> ⚠️ 请确保项目中已安装以上依赖,否则组件可能无法正常运行。
|
|
22
22
|
|
|
@@ -46,13 +46,13 @@ import {
|
|
|
46
46
|
|
|
47
47
|
**Props:**
|
|
48
48
|
|
|
49
|
-
| 属性
|
|
50
|
-
|
|
51
|
-
| `data`
|
|
52
|
-
| `tips`
|
|
53
|
-
| `contentFn` | `(props: { onClick, onMouseLeave }) => ReactNode` | ✅
|
|
54
|
-
| `placement` | `PopupPlacement`
|
|
55
|
-
| `className` | `string`
|
|
49
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
50
|
+
| ----------- | ------------------------------------------------- | ---- | ------------------------------------ |
|
|
51
|
+
| `data` | `string \| (() => Promise<string>)` | ✅ | 需要复制的数据,支持字符串或异步函数 |
|
|
52
|
+
| `tips` | `(isCopy: boolean, isFail: boolean) => ReactNode` | ✅ | 提示内容渲染函数 |
|
|
53
|
+
| `contentFn` | `(props: { onClick, onMouseLeave }) => ReactNode` | ✅ | 触发元素渲染函数 |
|
|
54
|
+
| `placement` | `PopupPlacement` | ❌ | Popup 弹出位置,默认由 TDesign 决定 |
|
|
55
|
+
| `className` | `string` | ❌ | 自定义类名 |
|
|
56
56
|
|
|
57
57
|
**示例:**
|
|
58
58
|
|
|
@@ -84,13 +84,13 @@ import {
|
|
|
84
84
|
|
|
85
85
|
**Props:**
|
|
86
86
|
|
|
87
|
-
| 属性
|
|
88
|
-
|
|
89
|
-
| `iconUrl`
|
|
90
|
-
| `loading`
|
|
91
|
-
| `defaultImg` | `string`
|
|
92
|
-
| `params`
|
|
93
|
-
| `onRemove`
|
|
87
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
88
|
+
| ------------ | ----------------------------------------------- | ---- | -------------------------------- |
|
|
89
|
+
| `iconUrl` | `string \| undefined` | ✅ | 图片 URL 地址 |
|
|
90
|
+
| `loading` | `boolean` | ✅ | 上传加载状态 |
|
|
91
|
+
| `defaultImg` | `string` | ❌ | 默认图片(不传则使用内置默认图) |
|
|
92
|
+
| `params` | `{ style?: CSSProperties; [key: string]: any }` | ❌ | 自定义扩展参数 |
|
|
93
|
+
| `onRemove` | `(e: any) => void` | ❌ | 删除回调函数 |
|
|
94
94
|
|
|
95
95
|
**示例:**
|
|
96
96
|
|
|
@@ -114,15 +114,15 @@ import {
|
|
|
114
114
|
|
|
115
115
|
**Props:**
|
|
116
116
|
|
|
117
|
-
| 属性
|
|
118
|
-
|
|
119
|
-
| `dataKey`
|
|
120
|
-
| `dataValue` | `string`
|
|
121
|
-
| `env`
|
|
122
|
-
| `gameId`
|
|
123
|
-
| `renderDom` | `(content: string) => React.ReactNode` | ✅
|
|
124
|
-
| `viewText`
|
|
125
|
-
| `pageId`
|
|
117
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
118
|
+
| ----------- | -------------------------------------- | ---- | -------------------------------------- |
|
|
119
|
+
| `dataKey` | `string` | ✅ | 高敏信息的唯一标识 key |
|
|
120
|
+
| `dataValue` | `string` | ✅ | 初始显示值(通常为脱敏后的数据) |
|
|
121
|
+
| `env` | `string \| number` | ✅ | 环境标识(如 dev / test / production) |
|
|
122
|
+
| `gameId` | `string \| number` | ✅ | 游戏 ID |
|
|
123
|
+
| `renderDom` | `(content: string) => React.ReactNode` | ✅ | 自定义渲染函数 |
|
|
124
|
+
| `viewText` | `string` | ❌ | 查看按钮文案,默认 `'View'` |
|
|
125
|
+
| `pageId` | `string` | ❌ | 页面 ID(用于操作日志和权限验证) |
|
|
126
126
|
|
|
127
127
|
**示例:**
|
|
128
128
|
|
|
@@ -147,17 +147,17 @@ import {
|
|
|
147
147
|
|
|
148
148
|
**参数:**
|
|
149
149
|
|
|
150
|
-
| 参数
|
|
151
|
-
|
|
150
|
+
| 参数 | 类型 | 说明 |
|
|
151
|
+
| --------------------- | -------------------------------------------- | -------------------------------------- |
|
|
152
152
|
| `onPaginationRequest` | `(params: { pageNumber, pageSize }) => void` | 分页变化时的回调,外部在此发起列表请求 |
|
|
153
153
|
|
|
154
154
|
**返回值:**
|
|
155
155
|
|
|
156
|
-
| 返回值
|
|
157
|
-
|
|
158
|
-
| `paginationData`
|
|
159
|
-
| `setPaginationData` | `(data: PaginationData) => void`
|
|
160
|
-
| `paginationProps`
|
|
156
|
+
| 返回值 | 类型 | 说明 |
|
|
157
|
+
| ------------------- | -------------------------------------------------- | -------------------------------------------------- |
|
|
158
|
+
| `paginationData` | `{ currentPage, totalCount, totalPage, pageSize }` | 当前分页数据 |
|
|
159
|
+
| `setPaginationData` | `(data: PaginationData) => void` | 回写分页数据(通常由外部请求完成后调用) |
|
|
160
|
+
| `paginationProps` | `PaginationProps \| undefined` | 可直接展开到 `<Pagination {...paginationProps} />` |
|
|
161
161
|
|
|
162
162
|
**示例:**
|
|
163
163
|
|
|
@@ -195,18 +195,18 @@ const Demo = () => {
|
|
|
195
195
|
|
|
196
196
|
**参数:**
|
|
197
197
|
|
|
198
|
-
| 参数
|
|
199
|
-
|
|
200
|
-
| `permissions` | `BtnPermissionMap`
|
|
201
|
-
| `demoGame`
|
|
202
|
-
| `serviceInfo` | `{ serviceType?, serviceName? }`
|
|
198
|
+
| 参数 | 类型 | 说明 |
|
|
199
|
+
| ------------- | ---------------------------------------- | --------------------------------------------------- |
|
|
200
|
+
| `permissions` | `BtnPermissionMap` | 按钮权限映射 `{ [type]: { [key]: 1 \| -1 \| -2 } }` |
|
|
201
|
+
| `demoGame` | `{ id: number \| string; name: string }` | 演示游戏信息 |
|
|
202
|
+
| `serviceInfo` | `{ serviceType?, serviceName? }` | 当前服务信息 |
|
|
203
203
|
|
|
204
204
|
**返回值:**
|
|
205
205
|
|
|
206
|
-
| 返回值
|
|
207
|
-
|
|
208
|
-
| `btnPermission`
|
|
209
|
-
| `isDemoGame`
|
|
206
|
+
| 返回值 | 类型 | 说明 |
|
|
207
|
+
| ------------------ | --------------------------------------------- | -------------------------------------------- |
|
|
208
|
+
| `btnPermission` | `BtnPermissionMap` | 权限映射原文 |
|
|
209
|
+
| `isDemoGame` | `boolean` | 是否为演示游戏 |
|
|
210
210
|
| `getBtnPermission` | `(type, key, defaultValue?) => 1 \| -1 \| -2` | 获取按钮权限(1 有权限 / -1 隐藏 / -2 禁用) |
|
|
211
211
|
|
|
212
212
|
**示例:**
|
|
@@ -216,12 +216,19 @@ const Demo = ({ btnPermission, userInfo }) => {
|
|
|
216
216
|
const { isDemoGame, getBtnPermission } = useBtnPermission({
|
|
217
217
|
permissions: btnPermission,
|
|
218
218
|
demoGame: userInfo?.demoGame,
|
|
219
|
-
serviceInfo: {
|
|
219
|
+
serviceInfo: {
|
|
220
|
+
serviceType: userInfo?.serviceType,
|
|
221
|
+
serviceName: userInfo?.serviceName,
|
|
222
|
+
},
|
|
220
223
|
});
|
|
221
224
|
|
|
222
225
|
const createPerm = getBtnPermission('global', 'create');
|
|
223
226
|
if (createPerm === -1) return null; // 隐藏
|
|
224
|
-
return
|
|
227
|
+
return (
|
|
228
|
+
<Button disabled={createPerm === -2}>
|
|
229
|
+
新建{isDemoGame ? '(演示)' : ''}
|
|
230
|
+
</Button>
|
|
231
|
+
);
|
|
225
232
|
};
|
|
226
233
|
```
|
|
227
234
|
|
|
@@ -233,11 +240,11 @@ const Demo = ({ btnPermission, userInfo }) => {
|
|
|
233
240
|
|
|
234
241
|
**返回值:**
|
|
235
242
|
|
|
236
|
-
| 返回值
|
|
237
|
-
|
|
238
|
-
| `securityData`
|
|
239
|
-
| `setSecurityData`
|
|
240
|
-
| `requestSecurityData` | `({ gameId, param, env }) => void` | 请求解锁指定高敏数据
|
|
243
|
+
| 返回值 | 类型 | 说明 |
|
|
244
|
+
| --------------------- | ---------------------------------- | --------------------------------------- |
|
|
245
|
+
| `securityData` | `object` | 已解锁的高敏数据映射 `{ [key]: value }` |
|
|
246
|
+
| `setSecurityData` | `(data: object) => void` | 手动设置已解锁数据 |
|
|
247
|
+
| `requestSecurityData` | `({ gameId, param, env }) => void` | 请求解锁指定高敏数据 |
|
|
241
248
|
|
|
242
249
|
---
|
|
243
250
|
|
|
@@ -247,14 +254,14 @@ const Demo = ({ btnPermission, userInfo }) => {
|
|
|
247
254
|
|
|
248
255
|
**参数:**
|
|
249
256
|
|
|
250
|
-
| 参数
|
|
251
|
-
|
|
257
|
+
| 参数 | 类型 | 说明 |
|
|
258
|
+
| --------- | ------------------------------------ | -------------------------------------------- |
|
|
252
259
|
| `fetcher` | `() => Promise<{ code, msg, data }>` | 自定义请求函数(不传则使用内置默认 fetcher) |
|
|
253
260
|
|
|
254
261
|
**返回值:**
|
|
255
262
|
|
|
256
|
-
| 返回值
|
|
257
|
-
|
|
263
|
+
| 返回值 | 类型 | 说明 |
|
|
264
|
+
| ---------------- | ------------------------------------------------------------------- | ----------- |
|
|
258
265
|
| `osPlatformList` | `{ os_list: OsItem[]; platform_list: PlatformItem[] } \| undefined` | OS/平台数据 |
|
|
259
266
|
|
|
260
267
|
**示例:**
|
|
@@ -272,7 +279,7 @@ const { osPlatformList } = useOsPlatformList(() => http.get('/my/os/platform'));
|
|
|
272
279
|
label: p.platform_name_zh,
|
|
273
280
|
value: p.id,
|
|
274
281
|
}))}
|
|
275
|
-
|
|
282
|
+
/>;
|
|
276
283
|
```
|
|
277
284
|
|
|
278
285
|
> 💡 如需强制刷新缓存,可调用 `clearOsPlatformListCache()` 清除全部缓存,或传入指定 fetcher 清除对应缓存。
|
|
@@ -301,14 +308,14 @@ yarn test
|
|
|
301
308
|
|
|
302
309
|
## 技术栈
|
|
303
310
|
|
|
304
|
-
| 工具
|
|
305
|
-
|
|
306
|
-
| [father4](https://github.com/umijs/father)
|
|
307
|
-
| [dumi2](https://d.umijs.org/)
|
|
308
|
-
| [TDesign React](https://tdesign.tencent.com/react) | UI 组件库(peerDependency)
|
|
309
|
-
| TypeScript
|
|
310
|
-
| Sass
|
|
311
|
-
| Jest
|
|
311
|
+
| 工具 | 用途 |
|
|
312
|
+
| -------------------------------------------------- | ----------------------------- |
|
|
313
|
+
| [father4](https://github.com/umijs/father) | 组件库构建(ESM / CJS / UMD) |
|
|
314
|
+
| [dumi2](https://d.umijs.org/) | 文档生成与开发调试 |
|
|
315
|
+
| [TDesign React](https://tdesign.tencent.com/react) | UI 组件库(peerDependency) |
|
|
316
|
+
| TypeScript | 类型安全 |
|
|
317
|
+
| Sass | 样式方案 |
|
|
318
|
+
| Jest | 单元测试 |
|
|
312
319
|
|
|
313
320
|
## 相关资源
|
|
314
321
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HighSecurityFetcher } from "../../hooks/useHighSecurity";
|
|
1
2
|
import React, { FC } from 'react';
|
|
2
3
|
import './index.scss';
|
|
3
4
|
interface PntSecureBoxProps {
|
|
@@ -38,6 +39,11 @@ interface PntSecureBoxProps {
|
|
|
38
39
|
* @description 用于记录操作日志和权限验证
|
|
39
40
|
*/
|
|
40
41
|
pageId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 高敏数据请求函数
|
|
44
|
+
* @description 通过外部注入请求函数,避免组件库内部依赖敏感配置
|
|
45
|
+
*/
|
|
46
|
+
fetcher: HighSecurityFetcher;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* 高敏信息展示统一组件
|
|
@@ -50,14 +56,19 @@ interface PntSecureBoxProps {
|
|
|
50
56
|
* @param {(content: string) => React.ReactNode} props.renderDom - 自定义渲染函数
|
|
51
57
|
* @param {string} [props.viewText] - 自定义查看按钮文案
|
|
52
58
|
* @param {string} [props.pageId] - 页面 ID
|
|
59
|
+
* @param {HighSecurityFetcher} props.fetcher - 高敏数据请求函数
|
|
53
60
|
*
|
|
54
61
|
* @example
|
|
55
62
|
* ```tsx
|
|
63
|
+
* import http from '@/utils/request';
|
|
64
|
+
* import { PntSecureBox } from '@pnt-team/pnt-component-frontend';
|
|
65
|
+
*
|
|
56
66
|
* <PntSecureBox
|
|
57
67
|
* dataKey="userPhone"
|
|
58
68
|
* dataValue="138****8888"
|
|
59
69
|
* env="production"
|
|
60
70
|
* gameId={12345}
|
|
71
|
+
* fetcher={(params) => http.post('/api/v3/business/game_info/high-security-decrypt', params).then(r => r.data)}
|
|
61
72
|
* renderDom={(content) => <span>{content}</span>}
|
|
62
73
|
* viewText="查看"
|
|
63
74
|
* />
|
|
@@ -37,8 +37,17 @@ var import_utils = require("../../utils");
|
|
|
37
37
|
var import_react = __toESM(require("react"));
|
|
38
38
|
var import_index = require("./index.scss");
|
|
39
39
|
var PntSecureBox = (prop) => {
|
|
40
|
-
const {
|
|
41
|
-
|
|
40
|
+
const {
|
|
41
|
+
dataKey,
|
|
42
|
+
dataValue,
|
|
43
|
+
env,
|
|
44
|
+
gameId,
|
|
45
|
+
renderDom,
|
|
46
|
+
viewText,
|
|
47
|
+
pageId,
|
|
48
|
+
fetcher
|
|
49
|
+
} = prop;
|
|
50
|
+
const { securityData, requestSecurityData } = (0, import_useHighSecurity.useHighSecurity)(fetcher);
|
|
42
51
|
return /* @__PURE__ */ import_react.default.createElement("div", { className: "pnt-secure-box" }, /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, renderDom(
|
|
43
52
|
(0, import_utils.isSecurityData)(dataValue) ? securityData[dataKey] || "******" : dataValue
|
|
44
53
|
), (0, import_utils.isSecurityData)(dataValue) && !securityData.hasOwnProperty(dataKey) && /* @__PURE__ */ import_react.default.createElement(
|
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** 高敏数据请求参数 */
|
|
2
|
+
export interface HighSecurityRequestParams {
|
|
3
|
+
/** 游戏 ID */
|
|
4
|
+
gameId: string | number;
|
|
5
|
+
/** 环境标识 */
|
|
6
|
+
env: string | number;
|
|
7
|
+
/** 页面 ID(不传则默认取 location.pathname) */
|
|
8
|
+
pageId?: string;
|
|
9
|
+
/** 需要解锁的参数列表 */
|
|
10
|
+
param: Array<{
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/** 高敏数据请求函数:返回 { ret, data } 结构且 ret === 0 视为成功 */
|
|
16
|
+
export type HighSecurityFetcher = (params: HighSecurityRequestParams) => Promise<{
|
|
17
|
+
ret: number;
|
|
18
|
+
data?: Array<{
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* 高敏数据解锁 Hook(L3 业务 Hook)
|
|
25
|
+
*
|
|
26
|
+
* 管理高敏数据的解锁状态。零业务侵入:请求函数通过 fetcher 注入,
|
|
27
|
+
* 不再依赖内部 api/configs,避免将敏感配置打包进发布产物。
|
|
28
|
+
*
|
|
29
|
+
* @param fetcher 自定义高敏数据请求函数,需返回 { ret, data } 结构且 ret === 0 视为成功
|
|
30
|
+
* @returns securityData 已解锁的高敏数据映射;requestSecurityData 请求解锁指定数据
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import http from '@/utils/request';
|
|
35
|
+
* import { useHighSecurity } from '@pnt-team/pnt-component-frontend';
|
|
36
|
+
*
|
|
37
|
+
* const Demo = () => {
|
|
38
|
+
* const { securityData, requestSecurityData } = useHighSecurity((params) =>
|
|
39
|
+
* http.post('/api/v3/business/game_info/high-security-decrypt', params).then(r => r.data)
|
|
40
|
+
* );
|
|
41
|
+
* // ...
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const useHighSecurity: (fetcher: HighSecurityFetcher) => {
|
|
46
|
+
securityData: Record<string, string>;
|
|
47
|
+
requestSecurityData: ({ gameId, param, env, pageId, }: HighSecurityRequestParams) => Promise<void>;
|
|
6
48
|
};
|
|
@@ -22,26 +22,39 @@ __export(useHighSecurity_exports, {
|
|
|
22
22
|
useHighSecurity: () => useHighSecurity
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(useHighSecurity_exports);
|
|
25
|
-
var import_api = require("../api");
|
|
26
25
|
var import_react = require("react");
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
var securityCache = /* @__PURE__ */ new Map();
|
|
27
|
+
var useHighSecurity = (fetcher) => {
|
|
28
|
+
const [securityData, setSecurityData] = (0, import_react.useState)(
|
|
29
|
+
() => {
|
|
30
|
+
const cached = {};
|
|
31
|
+
securityCache.forEach((value, key) => {
|
|
32
|
+
cached[key] = value;
|
|
33
|
+
});
|
|
34
|
+
return cached;
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
const requestSecurityData = async ({
|
|
38
|
+
gameId,
|
|
39
|
+
param,
|
|
40
|
+
env,
|
|
41
|
+
pageId
|
|
42
|
+
}) => {
|
|
43
|
+
const result = await fetcher({
|
|
44
|
+
gameId,
|
|
32
45
|
env: Number(env),
|
|
33
|
-
|
|
34
|
-
page_id: location.pathname,
|
|
46
|
+
pageId: pageId || location.pathname,
|
|
35
47
|
param
|
|
36
48
|
});
|
|
37
|
-
if (ret === 0) {
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
if (result.ret === 0 && result.data) {
|
|
50
|
+
result.data.forEach((item) => {
|
|
51
|
+
securityCache.set(item.key, item.value);
|
|
52
|
+
});
|
|
53
|
+
setSecurityData(Object.fromEntries(securityCache));
|
|
40
54
|
}
|
|
41
55
|
};
|
|
42
56
|
return {
|
|
43
57
|
securityData,
|
|
44
|
-
setSecurityData,
|
|
45
58
|
requestSecurityData
|
|
46
59
|
};
|
|
47
60
|
};
|
|
@@ -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,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// src/hooks/useOsPlatformList.ts
|
|
@@ -31,13 +21,10 @@ var useOsPlatformList_exports = {};
|
|
|
31
21
|
__export(useOsPlatformList_exports, {
|
|
32
22
|
clearOsPlatformListCache: () => clearOsPlatformListCache,
|
|
33
23
|
default: () => useOsPlatformList_default,
|
|
34
|
-
defaultOsPlatformFetcher: () => defaultOsPlatformFetcher,
|
|
35
24
|
useOsPlatformList: () => useOsPlatformList
|
|
36
25
|
});
|
|
37
26
|
module.exports = __toCommonJS(useOsPlatformList_exports);
|
|
38
27
|
var import_react = require("react");
|
|
39
|
-
var import_request = __toESM(require("../utils/request"));
|
|
40
|
-
var defaultOsPlatformFetcher = () => import_request.default.get("/api/internal/business/manage/osPlatformList");
|
|
41
28
|
var cacheMap = /* @__PURE__ */ new Map();
|
|
42
29
|
var fetchOsPlatformList = async (fetcher) => {
|
|
43
30
|
const cached = cacheMap.get(fetcher);
|
|
@@ -68,13 +55,11 @@ var clearOsPlatformListCache = (fetcher) => {
|
|
|
68
55
|
cacheMap.clear();
|
|
69
56
|
}
|
|
70
57
|
};
|
|
71
|
-
var useOsPlatformList = (fetcher
|
|
72
|
-
const [osPlatformList, setOsPlatformList] = (0, import_react.useState)(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
);
|
|
58
|
+
var useOsPlatformList = (fetcher) => {
|
|
59
|
+
const [osPlatformList, setOsPlatformList] = (0, import_react.useState)(() => {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
62
|
+
});
|
|
78
63
|
(0, import_react.useEffect)(() => {
|
|
79
64
|
var _a;
|
|
80
65
|
const cached = (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
@@ -99,6 +84,5 @@ var useOsPlatformList_default = useOsPlatformList;
|
|
|
99
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
85
|
0 && (module.exports = {
|
|
101
86
|
clearOsPlatformListCache,
|
|
102
|
-
defaultOsPlatformFetcher,
|
|
103
87
|
useOsPlatformList
|
|
104
88
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type HighSecurityFetcher } from "../../hooks/useHighSecurity";
|
|
1
2
|
import React, { FC } from 'react';
|
|
2
3
|
import './index.scss';
|
|
3
4
|
interface PntSecureBoxProps {
|
|
@@ -38,6 +39,11 @@ interface PntSecureBoxProps {
|
|
|
38
39
|
* @description 用于记录操作日志和权限验证
|
|
39
40
|
*/
|
|
40
41
|
pageId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 高敏数据请求函数
|
|
44
|
+
* @description 通过外部注入请求函数,避免组件库内部依赖敏感配置
|
|
45
|
+
*/
|
|
46
|
+
fetcher: HighSecurityFetcher;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* 高敏信息展示统一组件
|
|
@@ -50,14 +56,19 @@ interface PntSecureBoxProps {
|
|
|
50
56
|
* @param {(content: string) => React.ReactNode} props.renderDom - 自定义渲染函数
|
|
51
57
|
* @param {string} [props.viewText] - 自定义查看按钮文案
|
|
52
58
|
* @param {string} [props.pageId] - 页面 ID
|
|
59
|
+
* @param {HighSecurityFetcher} props.fetcher - 高敏数据请求函数
|
|
53
60
|
*
|
|
54
61
|
* @example
|
|
55
62
|
* ```tsx
|
|
63
|
+
* import http from '@/utils/request';
|
|
64
|
+
* import { PntSecureBox } from '@pnt-team/pnt-component-frontend';
|
|
65
|
+
*
|
|
56
66
|
* <PntSecureBox
|
|
57
67
|
* dataKey="userPhone"
|
|
58
68
|
* dataValue="138****8888"
|
|
59
69
|
* env="production"
|
|
60
70
|
* gameId={12345}
|
|
71
|
+
* fetcher={(params) => http.post('/api/v3/business/game_info/high-security-decrypt', params).then(r => r.data)}
|
|
61
72
|
* renderDom={(content) => <span>{content}</span>}
|
|
62
73
|
* viewText="查看"
|
|
63
74
|
* />
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
// src/components/PntSecureBox/index.tsx
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
useHighSecurity
|
|
4
|
+
} from "../../hooks/useHighSecurity";
|
|
3
5
|
import { isSecurityData } from "../../utils";
|
|
4
6
|
import React from "react";
|
|
5
7
|
import "./index.scss";
|
|
6
8
|
var PntSecureBox = (prop) => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
+
const {
|
|
10
|
+
dataKey,
|
|
11
|
+
dataValue,
|
|
12
|
+
env,
|
|
13
|
+
gameId,
|
|
14
|
+
renderDom,
|
|
15
|
+
viewText,
|
|
16
|
+
pageId,
|
|
17
|
+
fetcher
|
|
18
|
+
} = prop;
|
|
19
|
+
const { securityData, requestSecurityData } = useHighSecurity(fetcher);
|
|
9
20
|
return /* @__PURE__ */ React.createElement("div", { className: "pnt-secure-box" }, /* @__PURE__ */ React.createElement(React.Fragment, null, renderDom(
|
|
10
21
|
isSecurityData(dataValue) ? securityData[dataKey] || "******" : dataValue
|
|
11
22
|
), isSecurityData(dataValue) && !securityData.hasOwnProperty(dataKey) && /* @__PURE__ */ React.createElement(
|
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/** 高敏数据请求参数 */
|
|
2
|
+
export interface HighSecurityRequestParams {
|
|
3
|
+
/** 游戏 ID */
|
|
4
|
+
gameId: string | number;
|
|
5
|
+
/** 环境标识 */
|
|
6
|
+
env: string | number;
|
|
7
|
+
/** 页面 ID(不传则默认取 location.pathname) */
|
|
8
|
+
pageId?: string;
|
|
9
|
+
/** 需要解锁的参数列表 */
|
|
10
|
+
param: Array<{
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/** 高敏数据请求函数:返回 { ret, data } 结构且 ret === 0 视为成功 */
|
|
16
|
+
export type HighSecurityFetcher = (params: HighSecurityRequestParams) => Promise<{
|
|
17
|
+
ret: number;
|
|
18
|
+
data?: Array<{
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* 高敏数据解锁 Hook(L3 业务 Hook)
|
|
25
|
+
*
|
|
26
|
+
* 管理高敏数据的解锁状态。零业务侵入:请求函数通过 fetcher 注入,
|
|
27
|
+
* 不再依赖内部 api/configs,避免将敏感配置打包进发布产物。
|
|
28
|
+
*
|
|
29
|
+
* @param fetcher 自定义高敏数据请求函数,需返回 { ret, data } 结构且 ret === 0 视为成功
|
|
30
|
+
* @returns securityData 已解锁的高敏数据映射;requestSecurityData 请求解锁指定数据
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import http from '@/utils/request';
|
|
35
|
+
* import { useHighSecurity } from '@pnt-team/pnt-component-frontend';
|
|
36
|
+
*
|
|
37
|
+
* const Demo = () => {
|
|
38
|
+
* const { securityData, requestSecurityData } = useHighSecurity((params) =>
|
|
39
|
+
* http.post('/api/v3/business/game_info/high-security-decrypt', params).then(r => r.data)
|
|
40
|
+
* );
|
|
41
|
+
* // ...
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const useHighSecurity: (fetcher: HighSecurityFetcher) => {
|
|
46
|
+
securityData: Record<string, string>;
|
|
47
|
+
requestSecurityData: ({ gameId, param, env, pageId, }: HighSecurityRequestParams) => Promise<void>;
|
|
6
48
|
};
|