@fe-free/core 2.3.2 → 2.3.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: CoreApp
8
+ - @fe-free/tool@2.3.3
9
+
3
10
  ## 2.3.2
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "remark-gfm": "^4.0.1",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.3.2"
44
+ "@fe-free/tool": "2.3.3"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -7,6 +7,64 @@ import { BrowserRouter as Router, useNavigate } from 'react-router-dom';
7
7
  import { routeTool } from '../route';
8
8
  import { customValueTypeMap } from '../value_type_map';
9
9
 
10
+ function CheckUpdate({ basename }: { basename: string }) {
11
+ const { modal } = App.useApp();
12
+
13
+ useEffect(() => {
14
+ const mainScript = document.querySelector('[data-name="mainScript"]');
15
+ if (!mainScript) {
16
+ console.log('没找到 [data-name="mainScript"],不启用更新提醒');
17
+ return;
18
+ }
19
+
20
+ async function getMainScriptSrc() {
21
+ const res = await fetch(basename);
22
+ const html = await res.text();
23
+ const parser = new DOMParser();
24
+ const doc = parser.parseFromString(html, 'text/html');
25
+ const nextMainScript = doc.querySelector('[data-name="mainScript"]');
26
+ return nextMainScript?.getAttribute('src');
27
+ }
28
+
29
+ let ing = false;
30
+ function confirm() {
31
+ // 避免重复弹窗
32
+ if (ing) {
33
+ return;
34
+ }
35
+
36
+ modal.confirm({
37
+ title: '发现新版本',
38
+ content: '请及时刷新页面更新,以避免影响使用',
39
+ okText: '刷新',
40
+ cancelText: '稍后更新',
41
+ onOk: () => {
42
+ window.location.reload();
43
+ },
44
+ onCancel: () => {
45
+ ing = false;
46
+ },
47
+ });
48
+ ing = true;
49
+ }
50
+
51
+ const src = mainScript.getAttribute('src');
52
+ const timer = setInterval(async () => {
53
+ const nextSrc = await getMainScriptSrc();
54
+ if (nextSrc !== src) {
55
+ confirm();
56
+ return;
57
+ }
58
+ }, 1000 * 60);
59
+
60
+ return () => {
61
+ clearInterval(timer);
62
+ };
63
+ }, []);
64
+
65
+ return null;
66
+ }
67
+
10
68
  function SetRouteTool({ basename }: { basename: string }) {
11
69
  const navigate = useNavigate();
12
70
 
@@ -23,6 +81,7 @@ function SetRouteTool({ basename }: { basename: string }) {
23
81
  function CoreApp(props: {
24
82
  basename: string;
25
83
  name?: string;
84
+ enableCheckUpdate?: boolean;
26
85
  proConfigProviderProps?: Omit<React.ComponentProps<typeof ProConfigProvider>, 'children'>;
27
86
  configProviderProps?: Omit<React.ComponentProps<typeof ConfigProvider>, 'children'>;
28
87
  appProps?: Omit<React.ComponentProps<typeof App>, 'children'>;
@@ -32,6 +91,7 @@ function CoreApp(props: {
32
91
  const {
33
92
  basename,
34
93
  name,
94
+ enableCheckUpdate,
35
95
  children,
36
96
  proConfigProviderProps,
37
97
  configProviderProps,
@@ -59,6 +119,7 @@ function CoreApp(props: {
59
119
  <App {...appProps}>
60
120
  <Router {...routerProps} basename={basename}>
61
121
  <SetRouteTool basename={basename} />
122
+ {enableCheckUpdate && <CheckUpdate basename={basename} />}
62
123
  {children}
63
124
  </Router>
64
125
  </App>