@zw-team/react-lib 1.0.5-beta.1 → 1.0.5-beta.2

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.
@@ -3,7 +3,7 @@ import { ConfigProvider } from "antd";
3
3
  import js_cookie from "js-cookie";
4
4
  import { useCallback, useEffect, useState } from "react";
5
5
  import { initProdEnvWarning } from "../../utils/advisory.js";
6
- import { loadIconMock, loadSvg } from "../../utils/svgIcon/index.js";
6
+ import { loadIcon, loadSvg } from "../../utils/svgIcon/index.js";
7
7
  import AccessReport from "../AccessReport/index.js";
8
8
  import { ConfigContext, defaultConfig } from "./ConfigContext.js";
9
9
  const ConfigProvider_ConfigProvider_ConfigProvider = ({ children, antdConfig, ...restProps })=>{
@@ -34,12 +34,12 @@ const ConfigProvider_ConfigProvider_ConfigProvider = ({ children, antdConfig, ..
34
34
  js_cookie.set('$BiSystem', contextValue.system);
35
35
  initProdEnvWarning(contextValue.env || 'production');
36
36
  loadSvg(contextValue.system, contextValue.env || 'production', contextValue.mainOrigin);
37
- if (contextValue.needIcon) loadIconMock(contextValue.env || 'production', (data)=>{
37
+ if (contextValue.needIcon) loadIcon(contextValue.env || 'production', (data)=>{
38
38
  updateConfig({
39
39
  iconList: data.data,
40
40
  iconInit: true
41
41
  });
42
- });
42
+ }, contextValue.mainOrigin);
43
43
  };
44
44
  useEffect(()=>{
45
45
  install();
@@ -13,8 +13,9 @@ export interface IconInfoResponse {
13
13
  export interface IconListResponse {
14
14
  status_code: number;
15
15
  data: {
16
+ data: Record<string, unknown>;
16
17
  link: string;
17
- [key: string]: any;
18
+ [key: string]: unknown;
18
19
  };
19
20
  }
20
21
  /**
@@ -44,4 +45,4 @@ export declare function loadIcon(env: string, callback: LoadIconCallback, mainOr
44
45
  * @param env 环境参数
45
46
  * @param callback 加载完成回调函数
46
47
  */
47
- export declare function loadIconMock(env: string, callback: LoadIconCallback): void;
48
+ export declare function loadIconMock(_env: string, callback: LoadIconCallback): void;
@@ -1,4 +1,8 @@
1
1
  import request from "../request/index.js";
2
+ const DEFAULT_ICONPARK_URL = 'https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/svg_27771_3.b32c3fc4f408b5328f0e67954786ee1f.js';
3
+ const svgLoadCache = new Map();
4
+ const iconListLoadCache = new Map();
5
+ const scriptLoadCache = new Set();
2
6
  function getIconUrl(character, env, mainOrigin) {
3
7
  return request({
4
8
  env,
@@ -18,21 +22,43 @@ function getIconList(env, mainOrigin) {
18
22
  mainOrigin
19
23
  });
20
24
  }
25
+ function getSvgCacheKey(character, env, mainOrigin) {
26
+ return [
27
+ character,
28
+ env,
29
+ mainOrigin || ''
30
+ ].join('|');
31
+ }
32
+ function getIconListCacheKey(env, mainOrigin) {
33
+ return [
34
+ env,
35
+ mainOrigin || ''
36
+ ].join('|');
37
+ }
21
38
  function loadScript(url) {
39
+ if (!url || scriptLoadCache.has(url)) return;
40
+ scriptLoadCache.add(url);
22
41
  const script = document.createElement("script");
23
42
  script.src = url;
24
43
  document.head.appendChild(script);
25
44
  }
26
45
  function loadSvg(character, env, mainOrigin) {
27
- getIconUrl(character, env, mainOrigin).then((res)=>{
28
- loadScript('https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/svg_27771_3.b32c3fc4f408b5328f0e67954786ee1f.js');
46
+ if (!character) return;
47
+ const cacheKey = getSvgCacheKey(character, env, mainOrigin);
48
+ const pending = svgLoadCache.get(cacheKey) || getIconUrl(character, env, mainOrigin);
49
+ svgLoadCache.set(cacheKey, pending);
50
+ pending.then((res)=>{
51
+ loadScript(DEFAULT_ICONPARK_URL);
29
52
  if (1 === res.status_code && res.data.icon_url) setTimeout(()=>{
30
53
  loadScript(res.data.icon_url);
31
54
  });
32
55
  });
33
56
  }
34
57
  function loadIcon(env, callback, mainOrigin) {
35
- getIconList(env, mainOrigin).then((res)=>{
58
+ const cacheKey = getIconListCacheKey(env, mainOrigin);
59
+ const pending = iconListLoadCache.get(cacheKey) || getIconList(env, mainOrigin);
60
+ iconListLoadCache.set(cacheKey, pending);
61
+ pending.then((res)=>{
36
62
  if (1 === res.status_code) {
37
63
  callback(res.data);
38
64
  setTimeout(()=>{
@@ -41,7 +67,7 @@ function loadIcon(env, callback, mainOrigin) {
41
67
  }
42
68
  });
43
69
  }
44
- function loadIconMock(env, callback) {
70
+ function loadIconMock(_env, callback) {
45
71
  const res = {
46
72
  data: {
47
73
  data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zw-team/react-lib",
3
- "version": "1.0.5-beta.1",
3
+ "version": "1.0.5-beta.2",
4
4
  "description": "zw-team 业务组件库,基于 React + Ant Design,提供通用组件、Hooks 与工具函数",
5
5
  "keywords": [
6
6
  "react",