@pnt-team/pnt-component-frontend 0.0.72 → 0.0.74

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.
@@ -0,0 +1,13 @@
1
+ export declare const SUB_APP_PATHNAME: {
2
+ ACCOUNT: string;
3
+ SDK: string;
4
+ NOTICE: string;
5
+ CONFIGFROM: string;
6
+ CONFIGTHEME: string;
7
+ REVIEWLIST: string;
8
+ INTERNALTOOLS: string;
9
+ REPORTS: string;
10
+ };
11
+ export declare const AUDIENCE_MAPPING: {
12
+ [x: string]: string;
13
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是否是高敏信息逻辑
3
+ * @param {*} val
4
+ * @returns
5
+ */
6
+ export declare const isSecurityData: (val: string | number) => boolean;
@@ -1,10 +1,13 @@
1
- // src/api/index.ts
2
- var businessSelectList = (axios, data) => axios.post("/business/select/list?audience=/player-network", data);
3
- var businessGameInfoHighSecurityDecrypt = (axios, data) => axios.post(
4
- "/v3/business/game_info/high-security-decrypt?audience=/laas-pnt",
5
- data
6
- );
7
- export {
8
- businessGameInfoHighSecurityDecrypt,
9
- businessSelectList
10
- };
1
+ /**
2
+ * 业务下拉选择列表
3
+ * @param http 由 PntProvider 注入的 axios 实例
4
+ * @param data 请求参数
5
+ */
6
+ export const businessSelectList = (axios, data) => axios.post('/business/select/list?audience=/player-network', data);
7
+
8
+ /**
9
+ * 高敏信息解锁
10
+ * @param http 由 PntProvider 注入的 axios 实例
11
+ * @param data 请求参数
12
+ */
13
+ export const businessGameInfoHighSecurityDecrypt = (axios, data) => axios.post('/v3/business/game_info/high-security-decrypt?audience=/laas-pnt', data);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,26 +1,71 @@
1
- // src/components/PntBusinessSelect/index.tsx
2
1
  import { businessSelectList } from "../../api";
3
2
  import { usePntConfig } from "../../config";
4
- import {
5
- useCallback,
6
- useEffect,
7
- useMemo,
8
- useRef,
9
- useState
10
- } from "react";
11
- import { Loading, Select, Tooltip } from "tdesign-react";
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { Loading, Select, Tooltip } from 'tdesign-react';
12
5
  import "./index.scss";
13
- import { jsx } from "react/jsx-runtime";
14
- var PntBusinessSelect = (props) => {
6
+
7
+ // ==========================================
8
+ // 类型定义
9
+ // ==========================================
10
+
11
+ /** 下拉场景 */
12
+
13
+ /** 标签格式 */
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ /**
16
+ * 业务选择器组件
17
+ * @description 统一业务下拉选择器,内置对接后端通用接口 `/api/business/select/list`,
18
+ * 支持远程搜索、滚动分页加载、多选、场景化禁用(合规场景 creatable 字段)。
19
+ *
20
+ * @param {PntBusinessSelectProps} props - 组件属性
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * import { PntBusinessSelect } from '@pnt-team/pnt-component-frontend';
25
+ *
26
+ * // 最简用法
27
+ * <PntBusinessSelect
28
+ * value={gameId}
29
+ * onChange={(v) => setGameId(v as string)}
30
+ * />
31
+ *
32
+ * // SDK 定制场景 + 名称带 ID
33
+ * <PntBusinessSelect
34
+ * scene="sdk"
35
+ * labelFormat="name_id"
36
+ * value={gameId}
37
+ * onChange={(v) => setGameId(v as string)}
38
+ * />
39
+ *
40
+ * // 合规年龄场景(自动禁用 creatable=false 的业务)
41
+ * <PntBusinessSelect
42
+ * scene="compliance_age"
43
+ * value={gameId}
44
+ * onChange={(v) => setGameId(v as string)}
45
+ * />
46
+ *
47
+ * // 多选 + 状态过滤
48
+ * <PntBusinessSelect
49
+ * multiple
50
+ * statuses={[3, 4]}
51
+ * labelFormat="name_id"
52
+ * value={gameIds}
53
+ * onChange={(v) => setGameIds(v as string[])}
54
+ * />
55
+ * ```
56
+ *
57
+ * @returns {ReactElement} 业务选择器组件
58
+ */
59
+ const PntBusinessSelect = props => {
15
60
  const {
16
61
  value,
17
62
  onChange,
18
63
  multiple = false,
19
- scene = "default",
64
+ scene = 'default',
20
65
  statuses,
21
66
  businessTypes,
22
67
  businessAccessMethod,
23
- labelFormat = "name",
68
+ labelFormat = 'name',
24
69
  labelField,
25
70
  optionLabel,
26
71
  pagination = true,
@@ -37,152 +82,149 @@ var PntBusinessSelect = (props) => {
37
82
  fields,
38
83
  optionDisabled,
39
84
  optionTooltip,
40
- tooltipPlacement = "top",
85
+ tooltipPlacement = 'top',
41
86
  className,
42
87
  style
43
88
  } = props;
44
- const { http } = usePntConfig();
45
- const requestFn = useCallback(
46
- (params) => businessSelectList(http, params),
47
- [http]
48
- );
49
- const [options, setOptions] = useState(
50
- []
51
- );
89
+
90
+ // ---- 内置请求函数(通过 PntProvider 注入的 http 实例) ----
91
+ const {
92
+ http
93
+ } = usePntConfig();
94
+ const requestFn = useCallback(params => businessSelectList(http, params), [http]);
95
+
96
+ // ---- 状态 ----
97
+ const [options, setOptions] = useState([]);
52
98
  const [loading, setLoading] = useState(false);
53
- const [keyword, setKeyword] = useState("");
99
+ const [keyword, setKeyword] = useState('');
54
100
  const [pageNum, setPageNum] = useState(1);
55
101
  const [total, setTotal] = useState(0);
102
+
103
+ // ---- Refs ----
56
104
  const debounceRef = useRef();
57
105
  const loadingRef = useRef(false);
58
- const selectedItemsRef = useRef(/* @__PURE__ */ new Map());
59
- const buildParams = useCallback(
60
- (kw, page) => ({
61
- keyword: kw || void 0,
62
- pageNum: pagination ? page : 1,
63
- pageSize: pagination ? pageSize : 0,
64
- scene,
65
- statuses,
66
- business_types: businessTypes,
67
- business_access_method: businessAccessMethod,
68
- fields
69
- }),
70
- [
71
- scene,
72
- statuses,
73
- businessTypes,
74
- businessAccessMethod,
75
- pageSize,
76
- fields,
77
- pagination
78
- ]
79
- );
80
- const fetchData = useCallback(
81
- async (kw, page, append) => {
82
- var _a;
83
- if (loadingRef.current)
84
- return;
85
- loadingRef.current = true;
86
- setLoading(true);
87
- try {
88
- const res = await requestFn(buildParams(kw, page));
89
- if (res.code === 0 && res.data) {
90
- const newList = res.data.list || [];
91
- setOptions((prev) => append ? [...prev, ...newList] : newList);
92
- setTotal(((_a = res.data.pagination) == null ? void 0 : _a.total) || 0);
93
- setPageNum(page);
94
- }
95
- } finally {
96
- loadingRef.current = false;
97
- setLoading(false);
106
+ /** 已选中项的完整数据缓存,确保搜索后选项仍能展示 label */
107
+ const selectedItemsRef = useRef(new Map());
108
+
109
+ // ---- 构建请求参数 ----
110
+ const buildParams = useCallback((kw, page) => ({
111
+ keyword: kw || undefined,
112
+ pageNum: pagination ? page : 1,
113
+ pageSize: pagination ? pageSize : 0,
114
+ scene,
115
+ statuses,
116
+ business_types: businessTypes,
117
+ business_access_method: businessAccessMethod,
118
+ fields
119
+ }), [scene, statuses, businessTypes, businessAccessMethod, pageSize, fields, pagination]);
120
+
121
+ // ---- 获取数据 ----
122
+ const fetchData = useCallback(async (kw, page, append) => {
123
+ if (loadingRef.current) return;
124
+ loadingRef.current = true;
125
+ setLoading(true);
126
+ try {
127
+ const res = await requestFn(buildParams(kw, page));
128
+ // 适配 commonEesType:code === 0 视为成功
129
+ if (res.code === 0 && res.data) {
130
+ const newList = res.data.list || [];
131
+ setOptions(prev => append ? [...prev, ...newList] : newList);
132
+ setTotal(res.data.pagination?.total || 0);
133
+ setPageNum(page);
98
134
  }
99
- },
100
- [requestFn, buildParams]
101
- );
102
- const handleSearch = useCallback(
103
- (val) => {
104
- setKeyword(val);
105
- if (debounceRef.current)
106
- clearTimeout(debounceRef.current);
107
- debounceRef.current = setTimeout(() => {
108
- fetchData(val, 1, false);
109
- }, searchDebounce);
110
- },
111
- [fetchData, searchDebounce]
112
- );
135
+ } finally {
136
+ loadingRef.current = false;
137
+ setLoading(false);
138
+ }
139
+ }, [requestFn, buildParams]);
140
+
141
+ // ---- 远程搜索(防抖) ----
142
+ const handleSearch = useCallback(val => {
143
+ setKeyword(val);
144
+ if (debounceRef.current) clearTimeout(debounceRef.current);
145
+ debounceRef.current = setTimeout(() => {
146
+ fetchData(val, 1, false);
147
+ }, searchDebounce);
148
+ }, [fetchData, searchDebounce]);
149
+
150
+ // ---- 滚动触底加载下一页 ----
113
151
  const handleScrollToBottom = useCallback(() => {
114
152
  if (!loadingRef.current && options.length < total) {
115
153
  fetchData(keyword, pageNum + 1, true);
116
154
  }
117
155
  }, [options.length, total, keyword, pageNum, fetchData]);
118
- const handlePopupVisibleChange = useCallback(
119
- (visible) => {
120
- if (!visible && keyword) {
121
- setKeyword("");
122
- fetchData("", 1, false);
123
- }
124
- },
125
- [keyword, fetchData]
126
- );
156
+
157
+ // ---- 弹窗关闭时重置搜索 ----
158
+ const handlePopupVisibleChange = useCallback(visible => {
159
+ if (!visible && keyword) {
160
+ setKeyword('');
161
+ fetchData('', 1, false);
162
+ }
163
+ }, [keyword, fetchData]);
164
+
165
+ // ---- 初始加载 + 筛选条件变化时重新加载 ----
127
166
  useEffect(() => {
128
- fetchData("", 1, false);
167
+ fetchData('', 1, false);
129
168
  }, [fetchData]);
169
+
170
+ // ---- 缓存已选中项(确保搜索后仍能展示 label) ----
130
171
  useEffect(() => {
131
172
  const selectedValues = Array.isArray(value) ? value : value ? [value] : [];
132
- options.forEach((item) => {
173
+ options.forEach(item => {
133
174
  if (item.game_id && selectedValues.includes(item.game_id)) {
134
175
  selectedItemsRef.current.set(item.game_id, item);
135
176
  }
136
177
  });
137
178
  }, [options, value]);
179
+
180
+ // ---- 组件卸载时清理防抖 ----
138
181
  useEffect(() => {
139
182
  return () => {
140
- if (debounceRef.current)
141
- clearTimeout(debounceRef.current);
183
+ if (debounceRef.current) clearTimeout(debounceRef.current);
142
184
  };
143
185
  }, []);
144
- const formatLabel = useCallback(
145
- (item) => {
146
- if (optionLabel)
147
- return optionLabel(item);
148
- if (labelField) {
149
- return item[labelField] || item.name || "";
150
- }
151
- const name = item.name || "";
152
- const nameEn = item.name_en || "";
153
- const gameId = item.game_id || "";
154
- switch (labelFormat) {
155
- case "name_en":
156
- return nameEn || name;
157
- case "name_id":
158
- return `${name}(${gameId})`;
159
- case "name_en_id":
160
- return `${nameEn}(${gameId})`;
161
- default:
162
- return name;
163
- }
164
- },
165
- [labelFormat, labelField, optionLabel]
166
- );
167
- const isOptionDisabled = useCallback(
168
- (item) => {
169
- if (scene === "compliance_age" || scene === "custom_region") {
170
- if (item.creatable === false)
171
- return true;
172
- }
173
- return optionDisabled ? optionDisabled(item) : false;
174
- },
175
- [scene, optionDisabled]
176
- );
177
- const getOptionTooltip = useCallback(
178
- (item) => {
179
- return optionTooltip ? optionTooltip(item) : "";
180
- },
181
- [optionTooltip]
182
- );
186
+
187
+ // ---- 格式化标签 ----
188
+ const formatLabel = useCallback(item => {
189
+ // 优先级:optionLabel > labelField > labelFormat
190
+ if (optionLabel) return optionLabel(item);
191
+ if (labelField) {
192
+ return item[labelField] || item.name || '';
193
+ }
194
+ const name = item.name || '';
195
+ const nameEn = item.name_en || '';
196
+ const gameId = item.game_id || '';
197
+ switch (labelFormat) {
198
+ case 'name_en':
199
+ return nameEn || name;
200
+ case 'name_id':
201
+ return `${name}(${gameId})`;
202
+ case 'name_en_id':
203
+ return `${nameEn}(${gameId})`;
204
+ default:
205
+ return name;
206
+ }
207
+ }, [labelFormat, labelField, optionLabel]);
208
+
209
+ // ---- 判断选项是否禁用(合规场景 creatable + 自定义 optionDisabled 叠加) ----
210
+ const isOptionDisabled = useCallback(item => {
211
+ if (scene === 'compliance_age' || scene === 'custom_region') {
212
+ if (item.creatable === false) return true;
213
+ }
214
+ return optionDisabled ? optionDisabled(item) : false;
215
+ }, [scene, optionDisabled]);
216
+
217
+ // ---- 计算选项 tooltip 内容 ----
218
+ const getOptionTooltip = useCallback(item => {
219
+ return optionTooltip ? optionTooltip(item) : '';
220
+ }, [optionTooltip]);
221
+
222
+ // ---- 构建最终选项(当前页 + 已选中项补充) ----
183
223
  const selectOptions = useMemo(() => {
184
- const map = /* @__PURE__ */ new Map();
185
- options.forEach((item) => {
224
+ const map = new Map();
225
+
226
+ // 当前页选项
227
+ options.forEach(item => {
186
228
  if (item.game_id) {
187
229
  map.set(item.game_id, {
188
230
  label: formatLabel(item),
@@ -195,8 +237,10 @@ var PntBusinessSelect = (props) => {
195
237
  });
196
238
  }
197
239
  });
240
+
241
+ // 已选中项(搜索结果不含时补充,确保 label 始终可展示)
198
242
  const selectedValues = Array.isArray(value) ? value : value ? [value] : [];
199
- selectedValues.forEach((id) => {
243
+ selectedValues.forEach(id => {
200
244
  if (!map.has(id)) {
201
245
  const item = selectedItemsRef.current.get(id);
202
246
  if (item) {
@@ -210,75 +254,86 @@ var PntBusinessSelect = (props) => {
210
254
  rawItem: item
211
255
  });
212
256
  } else {
213
- map.set(id, { label: id, value: id, disabled: false });
257
+ // 降级:无完整数据时显示原始 ID
258
+ map.set(id, {
259
+ label: id,
260
+ value: id,
261
+ disabled: false
262
+ });
214
263
  }
215
264
  }
216
265
  });
217
266
  return Array.from(map.values());
218
267
  }, [options, value, formatLabel, isOptionDisabled]);
219
- const localFilter = useCallback(
220
- (filterWord, option) => {
221
- if (!filterWord)
222
- return true;
223
- const kw = filterWord.toLowerCase();
224
- const opt = option;
225
- const item = opt == null ? void 0 : opt.rawItem;
226
- if (item) {
227
- return Object.values(item).some(
228
- (v) => typeof v === "string" && v.toLowerCase().includes(kw)
229
- );
230
- }
231
- return ((opt == null ? void 0 : opt.name) || "").toLowerCase().includes(kw) || ((opt == null ? void 0 : opt.name_en) || "").toLowerCase().includes(kw) || ((opt == null ? void 0 : opt.game_id) || "").includes(kw);
232
- },
233
- []
234
- );
235
- const { Option } = Select;
268
+
269
+ // ---- 本地过滤(与后端 keyword 逻辑一致:name / name_en / game_id) ----
270
+ const localFilter = useCallback((filterWord, option) => {
271
+ if (!filterWord) return true;
272
+ const kw = filterWord.toLowerCase();
273
+ const opt = option;
274
+ // 优先按 rawItem 的所有字符串字段匹配(含 labelField 指定字段)
275
+ const item = opt?.rawItem;
276
+ if (item) {
277
+ return Object.values(item).some(v => typeof v === 'string' && v.toLowerCase().includes(kw));
278
+ }
279
+ return (opt?.name || '').toLowerCase().includes(kw) || (opt?.name_en || '').toLowerCase().includes(kw) || (opt?.game_id || '').includes(kw);
280
+ }, []);
281
+ const {
282
+ Option
283
+ } = Select;
284
+
285
+ // 是否启用 tooltip(仅当 optionTooltip 传入时生效)
236
286
  const hasTooltip = !!optionTooltip;
287
+
288
+ // 一次性加载模式:仅本地过滤,不触发远程搜索;不分页时禁用滚动触底
237
289
  const enableRemoteSearch = filterable && pagination;
238
290
  const enableScrollBottom = pagination;
239
- return /* @__PURE__ */ jsx(
240
- Select,
241
- {
242
- value,
243
- onChange,
244
- filterable,
245
- filter: filterable ? localFilter : void 0,
246
- onSearch: enableRemoteSearch ? handleSearch : void 0,
247
- loading: loading && options.length === 0,
248
- multiple,
249
- max,
250
- clearable,
251
- disabled,
252
- placeholder,
253
- minCollapsedNum,
254
- collapsedItems,
255
- onPopupVisibleChange: handlePopupVisibleChange,
256
- panelBottomContent: options.length > 0 && loading ? /* @__PURE__ */ jsx(Loading, { loading: true, size: "small" }) : null,
257
- popupProps: {
258
- ...popupProps,
259
- onScrollToBottom: enableScrollBottom ? handleScrollToBottom : void 0
260
- },
261
- className: className ? `pnt-business-select ${className}` : "pnt-business-select",
262
- style,
263
- children: selectOptions.map((opt) => {
264
- const item = opt.rawItem;
265
- const tip = hasTooltip && item ? getOptionTooltip(item) : "";
266
- const labelText = typeof opt.label === "string" ? opt.label : String(opt.label ?? "");
267
- return /* @__PURE__ */ jsx(
268
- Option,
269
- {
270
- value: opt.value,
271
- label: labelText,
272
- disabled: opt.disabled,
273
- children: tip ? /* @__PURE__ */ jsx(Tooltip, { content: tip, placement: tooltipPlacement, children: /* @__PURE__ */ jsx("span", { className: "pnt-business-select-option-label", children: opt.label }) }) : opt.label
274
- },
275
- opt.value
276
- );
277
- })
278
- }
279
- );
280
- };
281
- var PntBusinessSelect_default = PntBusinessSelect;
282
- export {
283
- PntBusinessSelect_default as default
291
+ return /*#__PURE__*/_jsx(Select, {
292
+ value: value,
293
+ onChange: onChange,
294
+ filterable: filterable,
295
+ filter: filterable ? localFilter : undefined,
296
+ onSearch: enableRemoteSearch ? handleSearch : undefined,
297
+ loading: loading && options.length === 0,
298
+ multiple: multiple,
299
+ max: max,
300
+ clearable: clearable,
301
+ disabled: disabled,
302
+ placeholder: placeholder,
303
+ minCollapsedNum: minCollapsedNum,
304
+ collapsedItems: collapsedItems,
305
+ onPopupVisibleChange: handlePopupVisibleChange,
306
+ panelBottomContent: options.length > 0 && loading ? /*#__PURE__*/_jsx(Loading, {
307
+ loading: true,
308
+ size: "small"
309
+ }) : null,
310
+ popupProps: {
311
+ ...popupProps,
312
+ onScrollToBottom: enableScrollBottom ? handleScrollToBottom : undefined
313
+ },
314
+ className: className ? `pnt-business-select ${className}` : 'pnt-business-select',
315
+ style: style,
316
+ children: selectOptions.map(opt => {
317
+ const item = opt.rawItem;
318
+ const tip = hasTooltip && item ? getOptionTooltip(item) : '';
319
+ // label 仅用纯文本字符串(用于 tag 显示与过滤匹配),复杂渲染走 children
320
+ const labelText = typeof opt.label === 'string' ? opt.label : String(opt.label ?? '');
321
+ // Tooltip 必须放在 Option 内部:Select 通过直接子节点识别 Option,
322
+ // 外层包裹会破坏选项注册;且禁用项的 hover 事件由内部元素接收才稳定
323
+ return /*#__PURE__*/_jsx(Option, {
324
+ value: opt.value,
325
+ label: labelText,
326
+ disabled: opt.disabled,
327
+ children: tip ? /*#__PURE__*/_jsx(Tooltip, {
328
+ content: tip,
329
+ placement: tooltipPlacement,
330
+ children: /*#__PURE__*/_jsx("span", {
331
+ className: "pnt-business-select-option-label",
332
+ children: opt.label
333
+ })
334
+ }) : opt.label
335
+ }, opt.value);
336
+ })
337
+ });
284
338
  };
339
+ export default PntBusinessSelect;