@pnt-team/pnt-component-frontend 0.0.38 → 0.0.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/lib/cjs/components/PntGeneralLayout/index.d.ts +82 -0
- package/lib/cjs/components/PntGeneralLayout/index.js +74 -0
- package/lib/cjs/components/PntGeneralLayout/index.scss +90 -0
- package/lib/cjs/components/PntImagePreview/index.js +37 -30
- package/lib/cjs/components/PntSecureBox/index.js +25 -32
- package/lib/cjs/global.css +2 -0
- package/lib/cjs/hooks/useHighSecurity.d.ts +2 -20
- package/lib/cjs/index.d.ts +1 -8
- package/lib/cjs/index.js +5 -17
- package/lib/esm/components/PntGeneralLayout/index.d.ts +82 -0
- package/lib/esm/components/PntGeneralLayout/index.js +54 -0
- package/lib/esm/components/PntGeneralLayout/index.scss +90 -0
- package/lib/esm/components/PntImagePreview/index.js +37 -30
- package/lib/esm/components/PntSecureBox/index.js +25 -22
- package/lib/esm/global.css +2 -0
- package/lib/esm/hooks/useHighSecurity.d.ts +2 -20
- package/lib/esm/index.d.ts +1 -8
- package/lib/esm/index.js +6 -14
- package/lib/umd/pnt-component-frontend.min.css +1 -1
- package/lib/umd/pnt-component-frontend.min.js +1 -1
- package/package.json +16 -4
- package/lib/cjs/components/PntCopyData/index.d.ts +0 -91
- package/lib/cjs/components/PntCopyData/index.js +0 -81
- package/lib/cjs/components/PntCopyData/index.scss +0 -5
- package/lib/cjs/hooks/useBtnPermission.d.ts +0 -67
- package/lib/cjs/hooks/useBtnPermission.js +0 -57
- package/lib/cjs/hooks/useOsPlatformList.d.ts +0 -66
- package/lib/cjs/hooks/useOsPlatformList.js +0 -88
- package/lib/cjs/hooks/usePagination.d.ts +0 -72
- package/lib/cjs/hooks/usePagination.js +0 -71
- package/lib/cjs/utils/request.d.ts +0 -8
- package/lib/cjs/utils/request.js +0 -82
- package/lib/esm/components/PntCopyData/index.d.ts +0 -91
- package/lib/esm/components/PntCopyData/index.js +0 -51
- package/lib/esm/components/PntCopyData/index.scss +0 -5
- package/lib/esm/hooks/useBtnPermission.d.ts +0 -67
- package/lib/esm/hooks/useBtnPermission.js +0 -31
- package/lib/esm/hooks/useOsPlatformList.d.ts +0 -66
- package/lib/esm/hooks/useOsPlatformList.js +0 -63
- package/lib/esm/hooks/usePagination.d.ts +0 -72
- package/lib/esm/hooks/usePagination.js +0 -47
- package/lib/esm/utils/request.d.ts +0 -8
- package/lib/esm/utils/request.js +0 -52
package/lib/cjs/utils/request.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/utils/request.ts
|
|
30
|
-
var request_exports = {};
|
|
31
|
-
__export(request_exports, {
|
|
32
|
-
default: () => request_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(request_exports);
|
|
35
|
-
var import_axios = __toESM(require("axios"));
|
|
36
|
-
var import_host = __toESM(require("../configs/host"));
|
|
37
|
-
var import_token = __toESM(require("../configs/token"));
|
|
38
|
-
var import_const = require("./const");
|
|
39
|
-
var env = process.env.MODE || "development";
|
|
40
|
-
var API_HOST = import_host.default[env].API;
|
|
41
|
-
var http = import_axios.default.create({
|
|
42
|
-
baseURL: API_HOST,
|
|
43
|
-
timeout: 100 * 1e3,
|
|
44
|
-
withCredentials: true
|
|
45
|
-
});
|
|
46
|
-
http.interceptors.request.use(
|
|
47
|
-
(config) => {
|
|
48
|
-
var _a;
|
|
49
|
-
const conf = { ...config };
|
|
50
|
-
const matchPath = Object.values(import_const.SUB_APP_PATHNAME).filter(
|
|
51
|
-
(path) => window.location.pathname.includes(path)
|
|
52
|
-
)[0] || "";
|
|
53
|
-
if (process.env.NODE_ENV === "development") {
|
|
54
|
-
conf.baseURL = matchPath ? "/subapi" : conf.baseURL;
|
|
55
|
-
conf.headers["X-Service-Type"] = ((_a = conf.headers) == null ? void 0 : _a["x-service-type"]) || "11";
|
|
56
|
-
conf.headers["X-User-Id"] = "us-104fe9b46fdf4534be663ec9eaa9ea2e";
|
|
57
|
-
conf.headers["X-User-Name"] = "v_bwweiwang";
|
|
58
|
-
conf.headers.authorization = import_token.default;
|
|
59
|
-
} else {
|
|
60
|
-
conf.baseURL = "/";
|
|
61
|
-
}
|
|
62
|
-
if (!conf.url.includes("audience=")) {
|
|
63
|
-
conf.url = `${conf.url}?audience=${matchPath ? import_const.AUDIENCE_MAPPING[matchPath] : "/player-network"}`;
|
|
64
|
-
}
|
|
65
|
-
return conf;
|
|
66
|
-
},
|
|
67
|
-
(err) => Promise.reject(err)
|
|
68
|
-
);
|
|
69
|
-
http.interceptors.response.use(
|
|
70
|
-
(response) => {
|
|
71
|
-
if (response.status === 200) {
|
|
72
|
-
const { data } = response;
|
|
73
|
-
if (data.code === 0) {
|
|
74
|
-
return Promise.resolve(data);
|
|
75
|
-
}
|
|
76
|
-
return Promise.resolve(data);
|
|
77
|
-
}
|
|
78
|
-
return Promise.reject(response == null ? void 0 : response.data);
|
|
79
|
-
},
|
|
80
|
-
(e) => Promise.reject(e)
|
|
81
|
-
);
|
|
82
|
-
var request_default = http;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent, ReactNode } from 'react';
|
|
2
|
-
import { PopupPlacement } from 'tdesign-react';
|
|
3
|
-
import './index.scss';
|
|
4
|
-
/**
|
|
5
|
-
* 复制触发元素的渲染属性
|
|
6
|
-
* @description 由组件内部构造,需绑定到触发元素上
|
|
7
|
-
*/
|
|
8
|
-
interface CopyTriggerProps {
|
|
9
|
-
/**
|
|
10
|
-
* 触发复制
|
|
11
|
-
* @description 绑定到触发元素的点击事件,点击后执行复制逻辑
|
|
12
|
-
*/
|
|
13
|
-
onClick: () => void;
|
|
14
|
-
/**
|
|
15
|
-
* 鼠标移出回调
|
|
16
|
-
* @description 绑定到触发元素的 mouseleave 事件,用于延迟关闭提示气泡
|
|
17
|
-
*/
|
|
18
|
-
onMouseLeave: () => void;
|
|
19
|
-
}
|
|
20
|
-
interface PntCopyDataProps {
|
|
21
|
-
/**
|
|
22
|
-
* 自定义类名
|
|
23
|
-
* @description 用于添加额外的样式类名到 Popup 弹层根元素
|
|
24
|
-
*/
|
|
25
|
-
className?: string;
|
|
26
|
-
/**
|
|
27
|
-
* 需要复制的数据
|
|
28
|
-
* @description 支持直接传入字符串,或传入异步函数返回字符串(如需请求接口获取)
|
|
29
|
-
*/
|
|
30
|
-
data: string | (() => Promise<string>);
|
|
31
|
-
/**
|
|
32
|
-
* Popup 弹出位置
|
|
33
|
-
* @description 提示气泡弹出的方位,如 top / bottom / left / right 等,默认值由 tdesign Popup 决定
|
|
34
|
-
*/
|
|
35
|
-
placement?: PopupPlacement;
|
|
36
|
-
/**
|
|
37
|
-
* 提示内容渲染函数
|
|
38
|
-
* @description 根据复制状态渲染气泡提示内容
|
|
39
|
-
* @param isCopy - 是否复制成功
|
|
40
|
-
* @param isFail - 是否复制失败
|
|
41
|
-
*/
|
|
42
|
-
tips: (isCopy: boolean, isFail: boolean) => ReactNode;
|
|
43
|
-
/**
|
|
44
|
-
* 触发元素渲染函数
|
|
45
|
-
* @description 渲染点击触发复制的元素,入参为需要绑定到触发元素的事件回调
|
|
46
|
-
*/
|
|
47
|
-
contentFn: (props: CopyTriggerProps) => ReactNode;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* 数据复制组件
|
|
51
|
-
* @description 点击触发元素后将数据复制到剪贴板,并通过 Popup 气泡提示复制结果。
|
|
52
|
-
* 优先使用 navigator.clipboard 写入剪贴板,非安全上下文自动降级为
|
|
53
|
-
* document.execCommand('copy') 兜底,无额外第三方依赖。
|
|
54
|
-
* 注意:本组件为受控可见的 Popup,触发元素的鼠标移出后约 200ms 自动关闭提示
|
|
55
|
-
* @param {PntCopyDataProps} props - 组件属性
|
|
56
|
-
* @param {string} [props.className] - 自定义类名
|
|
57
|
-
* @param {string | (() => Promise<string>)} props.data - 需要复制的数据,支持字符串或异步函数
|
|
58
|
-
* @param {PopupPlacement} [props.placement] - Popup 弹出位置
|
|
59
|
-
* @param {function} props.tips - 提示内容渲染函数 (isCopy, isFail) => ReactNode
|
|
60
|
-
* @param {function} props.contentFn - 触发元素渲染函数,入参为 { onClick, onMouseLeave }
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```tsx
|
|
64
|
-
* // 基础用法
|
|
65
|
-
* <PntCopyData
|
|
66
|
-
* data="这是一段需要复制的文本"
|
|
67
|
-
* tips={(isCopy, isFail) => (isFail ? '复制失败' : '复制成功')}
|
|
68
|
-
* contentFn={({ onClick, onMouseLeave }) => (
|
|
69
|
-
* <Button onClick={onClick} onMouseLeave={onMouseLeave}>
|
|
70
|
-
* 复制
|
|
71
|
-
* </Button>
|
|
72
|
-
* )}
|
|
73
|
-
* />
|
|
74
|
-
*
|
|
75
|
-
* // 异步获取数据(如从接口获取密码)
|
|
76
|
-
* <PntCopyData
|
|
77
|
-
* data={async () => await fetchSecret()}
|
|
78
|
-
* placement="top"
|
|
79
|
-
* tips={(isCopy, isFail) => (isFail ? '获取失败' : '已复制到剪贴板')}
|
|
80
|
-
* contentFn={({ onClick, onMouseLeave }) => (
|
|
81
|
-
* <Link onClick={onClick} onMouseLeave={onMouseLeave}>
|
|
82
|
-
* 查看密码
|
|
83
|
-
* </Link>
|
|
84
|
-
* )}
|
|
85
|
-
* />
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @returns {ReactElement} 数据复制组件
|
|
89
|
-
*/
|
|
90
|
-
declare const PntCopyData: FunctionComponent<PntCopyDataProps>;
|
|
91
|
-
export default PntCopyData;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// src/components/PntCopyData/index.tsx
|
|
2
|
-
import React, { useState } from "react";
|
|
3
|
-
import { Popup } from "tdesign-react";
|
|
4
|
-
import "./index.scss";
|
|
5
|
-
var PntCopyData = (props) => {
|
|
6
|
-
const { data, className, contentFn, placement, tips } = props;
|
|
7
|
-
const [isCopy, setIsCopy] = useState(false);
|
|
8
|
-
const [isFail, setIsFail] = useState(false);
|
|
9
|
-
const copyDataToClipboard = async () => {
|
|
10
|
-
const text = typeof data === "string" ? data : await data();
|
|
11
|
-
if (!text) {
|
|
12
|
-
return setIsFail(true);
|
|
13
|
-
}
|
|
14
|
-
if (navigator.clipboard && window.isSecureContext) {
|
|
15
|
-
navigator.clipboard.writeText(text);
|
|
16
|
-
setIsCopy(true);
|
|
17
|
-
} else {
|
|
18
|
-
const textArea = document.createElement("textarea");
|
|
19
|
-
textArea.value = text;
|
|
20
|
-
document.body.appendChild(textArea);
|
|
21
|
-
textArea.focus();
|
|
22
|
-
textArea.select();
|
|
23
|
-
document.execCommand("copy") && setIsCopy(true);
|
|
24
|
-
textArea.remove();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
return /* @__PURE__ */ React.createElement(
|
|
28
|
-
Popup,
|
|
29
|
-
{
|
|
30
|
-
overlayClassName: `pnt-copy-data-popup${className ? " " + className : ""}`,
|
|
31
|
-
placement,
|
|
32
|
-
content: tips(isCopy, isFail),
|
|
33
|
-
visible: isCopy || isFail
|
|
34
|
-
},
|
|
35
|
-
contentFn({
|
|
36
|
-
onClick: () => {
|
|
37
|
-
copyDataToClipboard();
|
|
38
|
-
},
|
|
39
|
-
onMouseLeave: () => {
|
|
40
|
-
setTimeout(() => {
|
|
41
|
-
setIsCopy(false);
|
|
42
|
-
setIsFail(false);
|
|
43
|
-
}, 200);
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
var PntCopyData_default = PntCopyData;
|
|
49
|
-
export {
|
|
50
|
-
PntCopyData_default as default
|
|
51
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/** 按钮权限值:1 有权限,-1 隐藏,-2 禁用 */
|
|
2
|
-
export type BtnPermissionValue = number;
|
|
3
|
-
/** 按钮权限映射:外层 key 为业务类型(全局为 'global' / 演示游戏为 '0' / 业务为具体 gameId / 兜底为 'no_permission_manner'),内层 key 为按钮标识符 */
|
|
4
|
-
export type BtnPermissionMap = Record<string, Record<string, BtnPermissionValue>>;
|
|
5
|
-
/** 演示游戏信息(来自用户信息,用于演示游戏判定) */
|
|
6
|
-
export interface DemoGameInfo {
|
|
7
|
-
id: number | string;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
/** 当前服务信息(与 demoGame 比对判断是否演示游戏) */
|
|
11
|
-
export interface ServiceInfo {
|
|
12
|
-
serviceType?: number | string;
|
|
13
|
-
serviceName?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface UseBtnPermissionOptions {
|
|
16
|
-
/**
|
|
17
|
-
* 按钮权限映射(原从全局 store 注入,现改为入参注入)。
|
|
18
|
-
* 未传或取不到值时按有权限(1)处理。
|
|
19
|
-
*/
|
|
20
|
-
permissions?: BtnPermissionMap;
|
|
21
|
-
/** 演示游戏信息;与 serviceInfo 同时传入才启用演示游戏判定 */
|
|
22
|
-
demoGame?: DemoGameInfo;
|
|
23
|
-
/** 当前服务信息 */
|
|
24
|
-
serviceInfo?: ServiceInfo;
|
|
25
|
-
}
|
|
26
|
-
/** 演示游戏在权限映射中的业务类型 key */
|
|
27
|
-
export declare const DEMO_GAME_TYPE_KEY = "0";
|
|
28
|
-
/** 无权限兜底配置的业务类型 key */
|
|
29
|
-
export declare const NO_PERMISSION_MANNER_KEY = "no_permission_manner";
|
|
30
|
-
/**
|
|
31
|
-
* 按钮权限 Hook(L3 业务 Hook)
|
|
32
|
-
*
|
|
33
|
-
* 融合 account-business-frontend 与 pnt-internal-tools-frontend 两版实现:
|
|
34
|
-
* - getBtnPermission(type, key):获取按钮处理方式,1 有权限 / -1 隐藏 / -2 禁用,
|
|
35
|
-
* 取不到值时依次回退到 no_permission_manner 兜底配置、defaultValue(默认 1);
|
|
36
|
-
* - 演示游戏(当前服务命中 demoGame)时固定使用 key '0' 的权限配置(account 版行为);
|
|
37
|
-
* - 零业务侵入:权限列表与演示游戏信息均通过入参注入,不再依赖 redux / umi / dva。
|
|
38
|
-
*
|
|
39
|
-
* @param options.permissions 按钮权限映射
|
|
40
|
-
* @param options.demoGame 演示游戏信息
|
|
41
|
-
* @param options.serviceInfo 当前服务信息
|
|
42
|
-
* @returns btnPermission 权限映射原文;isDemoGame 是否为演示游戏;getBtnPermission 获取按钮权限
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```tsx
|
|
46
|
-
* import { useBtnPermission } from '@pnt/business-components';
|
|
47
|
-
*
|
|
48
|
-
* const Demo = ({ btnPermission, userInfo }) => {
|
|
49
|
-
* const { isDemoGame, getBtnPermission } = useBtnPermission({
|
|
50
|
-
* permissions: btnPermission, // 例如 { global: { create: 1 }, no_permission_manner: { create: -2 } }
|
|
51
|
-
* demoGame: userInfo?.demoGame, // 例如 { id: 11, name: 'DemoGame' }
|
|
52
|
-
* serviceInfo: { serviceType: userInfo?.serviceType, serviceName: userInfo?.serviceName },
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* const createPerm = getBtnPermission('global', 'create'); // 1 | -1 | -2
|
|
56
|
-
*
|
|
57
|
-
* if (createPerm === -1) return null; // 隐藏
|
|
58
|
-
* return <Button disabled={createPerm === -2}>新建{isDemoGame ? '(演示)' : ''}</Button>;
|
|
59
|
-
* };
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare const useBtnPermission: (options?: UseBtnPermissionOptions) => {
|
|
63
|
-
btnPermission: BtnPermissionMap | undefined;
|
|
64
|
-
isDemoGame: boolean;
|
|
65
|
-
getBtnPermission: (type: string, key: string, defaultValue?: BtnPermissionValue) => BtnPermissionValue;
|
|
66
|
-
};
|
|
67
|
-
export default useBtnPermission;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// src/hooks/useBtnPermission.ts
|
|
2
|
-
import { useCallback, useMemo } from "react";
|
|
3
|
-
var DEMO_GAME_TYPE_KEY = "0";
|
|
4
|
-
var NO_PERMISSION_MANNER_KEY = "no_permission_manner";
|
|
5
|
-
var useBtnPermission = (options = {}) => {
|
|
6
|
-
const { permissions, demoGame, serviceInfo } = options;
|
|
7
|
-
const isDemoGame = useMemo(() => {
|
|
8
|
-
if (!demoGame || !serviceInfo)
|
|
9
|
-
return false;
|
|
10
|
-
return serviceInfo.serviceType === demoGame.id && serviceInfo.serviceName === demoGame.name;
|
|
11
|
-
}, [demoGame, serviceInfo]);
|
|
12
|
-
const getBtnPermission = useCallback(
|
|
13
|
-
(type, key, defaultValue = 1) => {
|
|
14
|
-
var _a, _b;
|
|
15
|
-
return ((_a = permissions == null ? void 0 : permissions[isDemoGame ? DEMO_GAME_TYPE_KEY : type]) == null ? void 0 : _a[key]) ?? ((_b = permissions == null ? void 0 : permissions[NO_PERMISSION_MANNER_KEY]) == null ? void 0 : _b[key]) ?? defaultValue ?? 1;
|
|
16
|
-
},
|
|
17
|
-
[permissions, isDemoGame]
|
|
18
|
-
);
|
|
19
|
-
return {
|
|
20
|
-
btnPermission: permissions,
|
|
21
|
-
isDemoGame,
|
|
22
|
-
getBtnPermission
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
var useBtnPermission_default = useBtnPermission;
|
|
26
|
-
export {
|
|
27
|
-
DEMO_GAME_TYPE_KEY,
|
|
28
|
-
NO_PERMISSION_MANNER_KEY,
|
|
29
|
-
useBtnPermission_default as default,
|
|
30
|
-
useBtnPermission
|
|
31
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/** OS 平台数据类型定义 */
|
|
2
|
-
export interface OsItem {
|
|
3
|
-
id: number;
|
|
4
|
-
os_name: string;
|
|
5
|
-
sdk_name: string;
|
|
6
|
-
status: number;
|
|
7
|
-
platform_id: number;
|
|
8
|
-
}
|
|
9
|
-
export interface PlatformItem {
|
|
10
|
-
id: number;
|
|
11
|
-
platform_name_zh: string;
|
|
12
|
-
platform_name_en: string;
|
|
13
|
-
status: number;
|
|
14
|
-
}
|
|
15
|
-
export interface OsPlatformData {
|
|
16
|
-
os_list: OsItem[];
|
|
17
|
-
platform_list: PlatformItem[];
|
|
18
|
-
}
|
|
19
|
-
/** OS/平台列表请求函数:返回 { code, msg, data } 结构且 code === 0 视为成功 */
|
|
20
|
-
export type OsPlatformFetcher = () => Promise<{
|
|
21
|
-
code: number;
|
|
22
|
-
msg: string;
|
|
23
|
-
data: OsPlatformData;
|
|
24
|
-
}>;
|
|
25
|
-
/**
|
|
26
|
-
* 清除缓存(用于极少数需要强制刷新的场景,如后台更新了平台列表后)。
|
|
27
|
-
* @param fetcher 指定要清除的 fetcher;不传则清除全部缓存
|
|
28
|
-
*/
|
|
29
|
-
export declare const clearOsPlatformListCache: (fetcher?: OsPlatformFetcher) => void;
|
|
30
|
-
/**
|
|
31
|
-
* OS/平台列表 Hook(L3 业务 Hook)
|
|
32
|
-
*
|
|
33
|
-
* 拉取 OS 与平台枚举数据并做模块级缓存,整个会话只请求一次;
|
|
34
|
-
* 并发调用共享同一个进行中的请求。
|
|
35
|
-
*
|
|
36
|
-
* 零业务侵入:数据接口通过 fetcher 注入,不再依赖内部 request/configs,
|
|
37
|
-
* 避免将敏感配置打包进发布产物。
|
|
38
|
-
*
|
|
39
|
-
* @param fetcher 自定义请求函数,需返回 { code, msg, data } 结构且 code === 0 视为成功
|
|
40
|
-
* @returns osPlatformList OS/平台数据,请求完成或命中缓存前为 undefined
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* import http from '@/utils/request';
|
|
45
|
-
* import { useOsPlatformList } from '@pnt-team/pnt-component-frontend';
|
|
46
|
-
*
|
|
47
|
-
* const Demo = () => {
|
|
48
|
-
* const { osPlatformList } = useOsPlatformList(() =>
|
|
49
|
-
* http.get('/api/internal/business/manage/osPlatformList').then(r => r.data)
|
|
50
|
-
* );
|
|
51
|
-
*
|
|
52
|
-
* return (
|
|
53
|
-
* <Select
|
|
54
|
-
* options={osPlatformList?.platform_list.map((p) => ({
|
|
55
|
-
* label: p.platform_name_zh,
|
|
56
|
-
* value: p.id,
|
|
57
|
-
* }))}
|
|
58
|
-
* />
|
|
59
|
-
* );
|
|
60
|
-
* };
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare const useOsPlatformList: (fetcher: OsPlatformFetcher) => {
|
|
64
|
-
osPlatformList: OsPlatformData | undefined;
|
|
65
|
-
};
|
|
66
|
-
export default useOsPlatformList;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// src/hooks/useOsPlatformList.ts
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
var cacheMap = /* @__PURE__ */ new Map();
|
|
4
|
-
var fetchOsPlatformList = async (fetcher) => {
|
|
5
|
-
const cached = cacheMap.get(fetcher);
|
|
6
|
-
if (cached == null ? void 0 : cached.data)
|
|
7
|
-
return cached.data;
|
|
8
|
-
if (cached == null ? void 0 : cached.pending)
|
|
9
|
-
return cached.pending;
|
|
10
|
-
const pending = (async () => {
|
|
11
|
-
try {
|
|
12
|
-
const res = await fetcher();
|
|
13
|
-
if (res.code === 0) {
|
|
14
|
-
cacheMap.set(fetcher, { data: res.data });
|
|
15
|
-
return res.data;
|
|
16
|
-
}
|
|
17
|
-
return void 0;
|
|
18
|
-
} finally {
|
|
19
|
-
const entry = cacheMap.get(fetcher);
|
|
20
|
-
cacheMap.set(fetcher, { data: entry == null ? void 0 : entry.data });
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
cacheMap.set(fetcher, { data: cached == null ? void 0 : cached.data, pending });
|
|
24
|
-
return pending;
|
|
25
|
-
};
|
|
26
|
-
var clearOsPlatformListCache = (fetcher) => {
|
|
27
|
-
if (fetcher) {
|
|
28
|
-
cacheMap.delete(fetcher);
|
|
29
|
-
} else {
|
|
30
|
-
cacheMap.clear();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var useOsPlatformList = (fetcher) => {
|
|
34
|
-
const [osPlatformList, setOsPlatformList] = useState(() => {
|
|
35
|
-
var _a;
|
|
36
|
-
return (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
37
|
-
});
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
var _a;
|
|
40
|
-
const cached = (_a = cacheMap.get(fetcher)) == null ? void 0 : _a.data;
|
|
41
|
-
if (cached) {
|
|
42
|
-
setOsPlatformList(cached);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
let mounted = true;
|
|
46
|
-
fetchOsPlatformList(fetcher).then((data) => {
|
|
47
|
-
if (mounted && data)
|
|
48
|
-
setOsPlatformList(data);
|
|
49
|
-
});
|
|
50
|
-
return () => {
|
|
51
|
-
mounted = false;
|
|
52
|
-
};
|
|
53
|
-
}, [fetcher]);
|
|
54
|
-
return {
|
|
55
|
-
osPlatformList
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
var useOsPlatformList_default = useOsPlatformList;
|
|
59
|
-
export {
|
|
60
|
-
clearOsPlatformListCache,
|
|
61
|
-
useOsPlatformList_default as default,
|
|
62
|
-
useOsPlatformList
|
|
63
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { PaginationProps } from 'tdesign-react';
|
|
3
|
-
/** 分页内部状态 */
|
|
4
|
-
export interface PaginationData {
|
|
5
|
-
/** 当前页码(从 1 开始) */
|
|
6
|
-
currentPage: number;
|
|
7
|
-
/** 数据总条数 */
|
|
8
|
-
totalCount: number;
|
|
9
|
-
/** 总页数 */
|
|
10
|
-
totalPage: number;
|
|
11
|
-
/** 每页条数 */
|
|
12
|
-
pageSize: number;
|
|
13
|
-
}
|
|
14
|
-
/** 分页变化时回传给外部请求的参数 */
|
|
15
|
-
export interface PaginationRequestParams {
|
|
16
|
-
/** 页码(从 1 开始) */
|
|
17
|
-
pageNumber: number;
|
|
18
|
-
/** 每页条数 */
|
|
19
|
-
pageSize: number;
|
|
20
|
-
}
|
|
21
|
-
/** 分页变化回调 */
|
|
22
|
-
export type OnPaginationRequest = (params: PaginationRequestParams) => void;
|
|
23
|
-
/**
|
|
24
|
-
* 分页 Hook(L3 业务 Hook)
|
|
25
|
-
*
|
|
26
|
-
* 维护分页状态,并在页码 / 每页条数变化时通过 onPaginationRequest 回调通知外部发起请求。
|
|
27
|
-
* 请求完成后由外部调用 setPaginationData 回写最新分页数据。
|
|
28
|
-
*
|
|
29
|
-
* 特性:
|
|
30
|
-
* - totalCount 为 0 时 paginationProps 返回 undefined,可直接透传给 tdesign-react 的 Pagination 组件(不渲染分页器);
|
|
31
|
-
* - 切换每页条数时自动回到第 1 页;
|
|
32
|
-
* - 返回的 paginationProps 可直接展开到 <Pagination {...paginationProps} />。
|
|
33
|
-
*
|
|
34
|
-
* @param onPaginationRequest 页码或每页条数变化时的回调,外部在此发起列表请求
|
|
35
|
-
* @returns paginationData 分页数据;setPaginationData 回写分页数据;paginationProps tdesign-react Pagination 组件属性(totalCount 为 0 时为 undefined)
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```tsx
|
|
39
|
-
* import { Pagination } from 'tdesign-react';
|
|
40
|
-
* import { usePagination } from '@pnt/business-components';
|
|
41
|
-
*
|
|
42
|
-
* const Demo = () => {
|
|
43
|
-
* const [list, setList] = useState<Item[]>([]);
|
|
44
|
-
* const { paginationData, setPaginationData, paginationProps } = usePagination(
|
|
45
|
-
* async ({ pageNumber, pageSize }) => {
|
|
46
|
-
* const res = await fetchList({ page: pageNumber, size: pageSize });
|
|
47
|
-
* setList(res.data.list);
|
|
48
|
-
* setPaginationData((prev) => ({
|
|
49
|
-
* ...prev,
|
|
50
|
-
* currentPage: pageNumber,
|
|
51
|
-
* pageSize,
|
|
52
|
-
* totalCount: res.data.total,
|
|
53
|
-
* totalPage: Math.ceil(res.data.total / pageSize),
|
|
54
|
-
* }));
|
|
55
|
-
* },
|
|
56
|
-
* );
|
|
57
|
-
*
|
|
58
|
-
* return (
|
|
59
|
-
* <>
|
|
60
|
-
* <Table data={list} />
|
|
61
|
-
* {paginationProps && <Pagination {...paginationProps} />}
|
|
62
|
-
* </>
|
|
63
|
-
* );
|
|
64
|
-
* };
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare const usePagination: (onPaginationRequest: OnPaginationRequest) => {
|
|
68
|
-
paginationData: PaginationData;
|
|
69
|
-
setPaginationData: import("react").Dispatch<import("react").SetStateAction<PaginationData>>;
|
|
70
|
-
paginationProps: PaginationProps | undefined;
|
|
71
|
-
};
|
|
72
|
-
export default usePagination;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// src/hooks/usePagination.ts
|
|
2
|
-
import { useCallback, useMemo, useState } from "react";
|
|
3
|
-
var usePagination = (onPaginationRequest) => {
|
|
4
|
-
const [paginationData, setPaginationData] = useState({
|
|
5
|
-
currentPage: 1,
|
|
6
|
-
totalCount: 0,
|
|
7
|
-
totalPage: 0,
|
|
8
|
-
pageSize: 10
|
|
9
|
-
});
|
|
10
|
-
const handleCurrentChange = useCallback(
|
|
11
|
-
(current, pageInfo) => {
|
|
12
|
-
onPaginationRequest({
|
|
13
|
-
pageNumber: current,
|
|
14
|
-
pageSize: pageInfo.pageSize
|
|
15
|
-
});
|
|
16
|
-
},
|
|
17
|
-
[onPaginationRequest]
|
|
18
|
-
);
|
|
19
|
-
const handlePageSizeChange = useCallback(
|
|
20
|
-
(pageSize) => {
|
|
21
|
-
onPaginationRequest({ pageNumber: 1, pageSize });
|
|
22
|
-
},
|
|
23
|
-
[onPaginationRequest]
|
|
24
|
-
);
|
|
25
|
-
const paginationProps = useMemo(() => {
|
|
26
|
-
if (paginationData.totalCount === 0)
|
|
27
|
-
return void 0;
|
|
28
|
-
return {
|
|
29
|
-
pageSizeOptions: [10, 20, 30, 50, 100],
|
|
30
|
-
pageSize: paginationData.pageSize,
|
|
31
|
-
current: paginationData.currentPage,
|
|
32
|
-
total: paginationData.totalCount,
|
|
33
|
-
onCurrentChange: handleCurrentChange,
|
|
34
|
-
onPageSizeChange: handlePageSizeChange
|
|
35
|
-
};
|
|
36
|
-
}, [paginationData, handleCurrentChange, handlePageSizeChange]);
|
|
37
|
-
return {
|
|
38
|
-
paginationData,
|
|
39
|
-
setPaginationData,
|
|
40
|
-
paginationProps
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
var usePagination_default = usePagination;
|
|
44
|
-
export {
|
|
45
|
-
usePagination_default as default,
|
|
46
|
-
usePagination
|
|
47
|
-
};
|
package/lib/esm/utils/request.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// src/utils/request.ts
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import host from "../configs/host";
|
|
4
|
-
import TOKEN from "../configs/token";
|
|
5
|
-
import { AUDIENCE_MAPPING, SUB_APP_PATHNAME } from "./const";
|
|
6
|
-
var env = process.env.MODE || "development";
|
|
7
|
-
var API_HOST = host[env].API;
|
|
8
|
-
var http = axios.create({
|
|
9
|
-
baseURL: API_HOST,
|
|
10
|
-
timeout: 100 * 1e3,
|
|
11
|
-
withCredentials: true
|
|
12
|
-
});
|
|
13
|
-
http.interceptors.request.use(
|
|
14
|
-
(config) => {
|
|
15
|
-
var _a;
|
|
16
|
-
const conf = { ...config };
|
|
17
|
-
const matchPath = Object.values(SUB_APP_PATHNAME).filter(
|
|
18
|
-
(path) => window.location.pathname.includes(path)
|
|
19
|
-
)[0] || "";
|
|
20
|
-
if (true) {
|
|
21
|
-
conf.baseURL = matchPath ? "/subapi" : conf.baseURL;
|
|
22
|
-
conf.headers["X-Service-Type"] = ((_a = conf.headers) == null ? void 0 : _a["x-service-type"]) || "11";
|
|
23
|
-
conf.headers["X-User-Id"] = "us-104fe9b46fdf4534be663ec9eaa9ea2e";
|
|
24
|
-
conf.headers["X-User-Name"] = "v_bwweiwang";
|
|
25
|
-
conf.headers.authorization = TOKEN;
|
|
26
|
-
} else {
|
|
27
|
-
conf.baseURL = "/";
|
|
28
|
-
}
|
|
29
|
-
if (!conf.url.includes("audience=")) {
|
|
30
|
-
conf.url = `${conf.url}?audience=${matchPath ? AUDIENCE_MAPPING[matchPath] : "/player-network"}`;
|
|
31
|
-
}
|
|
32
|
-
return conf;
|
|
33
|
-
},
|
|
34
|
-
(err) => Promise.reject(err)
|
|
35
|
-
);
|
|
36
|
-
http.interceptors.response.use(
|
|
37
|
-
(response) => {
|
|
38
|
-
if (response.status === 200) {
|
|
39
|
-
const { data } = response;
|
|
40
|
-
if (data.code === 0) {
|
|
41
|
-
return Promise.resolve(data);
|
|
42
|
-
}
|
|
43
|
-
return Promise.resolve(data);
|
|
44
|
-
}
|
|
45
|
-
return Promise.reject(response == null ? void 0 : response.data);
|
|
46
|
-
},
|
|
47
|
-
(e) => Promise.reject(e)
|
|
48
|
-
);
|
|
49
|
-
var request_default = http;
|
|
50
|
-
export {
|
|
51
|
-
request_default as default
|
|
52
|
-
};
|