@vtj/h5 0.9.16
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/LICENSE +21 -0
- package/package.json +42 -0
- package/src/index.scss +1 -0
- package/src/index.ts +3 -0
- package/src/modules.ts +14 -0
- package/src/renderer.ts +23 -0
- package/src/utils/auto-update.ts +69 -0
- package/src/utils/index.ts +1 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 陈华春
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"name": "@vtj/h5",
|
3
|
+
"private": false,
|
4
|
+
"version": "0.9.16",
|
5
|
+
"type": "module",
|
6
|
+
"sideEffects": false,
|
7
|
+
"dependencies": {
|
8
|
+
"vant": "~4.9.10",
|
9
|
+
"@vtj/core": "~0.9.16",
|
10
|
+
"@vtj/icons": "~0.9.16",
|
11
|
+
"@vtj/renderer": "~0.9.16",
|
12
|
+
"@vtj/utils": "~0.9.16"
|
13
|
+
},
|
14
|
+
"devDependencies": {
|
15
|
+
"@vtj/cli": "~0.9.6"
|
16
|
+
},
|
17
|
+
"exports": {
|
18
|
+
"./src/index.scss": "./src/index.scss",
|
19
|
+
".": {
|
20
|
+
"types": "./src/index.ts",
|
21
|
+
"import": "./src/index.ts",
|
22
|
+
"require": "./src/index.ts"
|
23
|
+
},
|
24
|
+
"./*": [
|
25
|
+
"./*"
|
26
|
+
]
|
27
|
+
},
|
28
|
+
"main": "./src/index.ts",
|
29
|
+
"module": "./src/index.ts",
|
30
|
+
"types": "./src/index.ts",
|
31
|
+
"files": [
|
32
|
+
"src"
|
33
|
+
],
|
34
|
+
"gitHead": "d03843144f07c2d98c1e0c72c8c6eb1117c01722",
|
35
|
+
"publishConfig": {
|
36
|
+
"access": "public"
|
37
|
+
},
|
38
|
+
"scripts": {
|
39
|
+
"check": "vue-tsc --noEmit",
|
40
|
+
"build": "npm run check"
|
41
|
+
}
|
42
|
+
}
|
package/src/index.scss
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
@use "vant/lib/index.css";
|
package/src/index.ts
ADDED
package/src/modules.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { ContextMode } from './renderer';
|
2
|
+
|
3
|
+
|
4
|
+
export function createModules(mode: ContextMode = ContextMode.Runtime) {
|
5
|
+
if (mode === ContextMode.Runtime || process.env.NODE_ENV === 'development') {
|
6
|
+
return import.meta.glob([
|
7
|
+
'/.vtj/projects/*.json',
|
8
|
+
'/.vtj/files/*.json',
|
9
|
+
'/.vtj/vue/*.vue'
|
10
|
+
]);
|
11
|
+
} else {
|
12
|
+
return import.meta.glob(['/.vtj/projects/*.json', '/.vtj/vue/*.vue']);
|
13
|
+
}
|
14
|
+
}
|
package/src/renderer.ts
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
import { createAdapter } from '@vtj/renderer';
|
2
|
+
|
3
|
+
import { showNotify, showLoadingToast } from 'vant';
|
4
|
+
|
5
|
+
export function loading() {
|
6
|
+
return showLoadingToast({
|
7
|
+
message: '加载中...',
|
8
|
+
forbidClick: true
|
9
|
+
});
|
10
|
+
}
|
11
|
+
|
12
|
+
export function notify(
|
13
|
+
message: string,
|
14
|
+
title: string = '',
|
15
|
+
type: 'primary' | 'warning' | 'danger' | 'success' = 'warning'
|
16
|
+
) {
|
17
|
+
const msg = title ? `[${title}]${message}` : message;
|
18
|
+
showNotify({ type, message: msg });
|
19
|
+
}
|
20
|
+
|
21
|
+
export * from '@vtj/renderer';
|
22
|
+
|
23
|
+
export const adapter = createAdapter({ loading, notify });
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { showConfirmDialog } from 'vant';
|
2
|
+
|
3
|
+
let lastSrcs: string[];
|
4
|
+
|
5
|
+
const scriptReg = /\<script.*src=["'](?<src>[^"']+)/gm;
|
6
|
+
|
7
|
+
let duration = 10000;
|
8
|
+
|
9
|
+
async function extractNewScripts() {
|
10
|
+
const html = await fetch('?t=' + Date.now()).then((resp) => resp.text());
|
11
|
+
scriptReg.lastIndex = 0;
|
12
|
+
let result = [];
|
13
|
+
let match;
|
14
|
+
while ((match = scriptReg.exec(html))) {
|
15
|
+
if (match.groups?.src) {
|
16
|
+
result.push(match.groups.src);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
}
|
21
|
+
|
22
|
+
async function needUpdate() {
|
23
|
+
const newScripts = await extractNewScripts();
|
24
|
+
if (!lastSrcs) {
|
25
|
+
lastSrcs = newScripts;
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
let result = false;
|
29
|
+
if (lastSrcs.length !== newScripts.length) {
|
30
|
+
result = true;
|
31
|
+
}
|
32
|
+
for (let i = 0; i < lastSrcs.length; i++) {
|
33
|
+
if (lastSrcs[i] !== newScripts[i]) {
|
34
|
+
result = true;
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
lastSrcs = newScripts;
|
39
|
+
return result;
|
40
|
+
}
|
41
|
+
|
42
|
+
async function refresh() {
|
43
|
+
const ret = await showConfirmDialog({
|
44
|
+
title: '系统更新',
|
45
|
+
message:
|
46
|
+
'系统发现新版本,请确认是否需要更新。如果确定,系统将会重新登录,请注意存档。'
|
47
|
+
})
|
48
|
+
.then(() => true)
|
49
|
+
.catch(() => false);
|
50
|
+
|
51
|
+
if (ret) {
|
52
|
+
const win = top || window;
|
53
|
+
win.location.reload();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
function autoRefresh() {
|
58
|
+
setTimeout(async () => {
|
59
|
+
const willUpdate = await needUpdate();
|
60
|
+
if (willUpdate) {
|
61
|
+
await refresh();
|
62
|
+
}
|
63
|
+
autoRefresh();
|
64
|
+
}, duration);
|
65
|
+
}
|
66
|
+
|
67
|
+
export function autoUpdate() {
|
68
|
+
autoRefresh();
|
69
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './auto-update';
|