重构代码, 优化加载js逻辑
This commit is contained in:
parent
a480918c29
commit
eb1a7c4414
@ -18,7 +18,7 @@ export class AppleClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async initAppleClient() {
|
async initAppleClient() {
|
||||||
await loadSingleScript([scripts[0]]);
|
await loadScripts(scripts.map((script) => [script]));
|
||||||
this.initClient();
|
this.initClient();
|
||||||
}
|
}
|
||||||
async login(funid) {
|
async login(funid) {
|
||||||
|
@ -24,7 +24,7 @@ export class GoogleClient {
|
|||||||
console.log('google client init success');
|
console.log('google client init success');
|
||||||
}
|
}
|
||||||
async initGoolgeClient() {
|
async initGoolgeClient() {
|
||||||
await Promise.all([loadSingleScript([scripts[0]]), loadSingleScript([scripts[1]])]);
|
await loadScripts(scripts.map((script) => [script]));
|
||||||
await this.initGApi();
|
await this.initGApi();
|
||||||
this.initTokenClient(SCOPES);
|
this.initTokenClient(SCOPES);
|
||||||
}
|
}
|
||||||
|
154
index.html
154
index.html
@ -1,27 +1,27 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="renderer" content="webkit">
|
<meta name="renderer" content="webkit">
|
||||||
<title>game page</title>
|
<title>game page</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
<meta http-equiv="Expires" content="0">
|
<meta http-equiv="Expires" content="0">
|
||||||
<meta http-equiv="Pragma" content="no-cache">
|
<meta http-equiv="Pragma" content="no-cache">
|
||||||
<meta http-equiv="Cache-control" content="no-cache">
|
<meta http-equiv="Cache-control" content="no-cache">
|
||||||
<meta http-equiv="Cache" content="no-cache">
|
<meta http-equiv="Cache" content="no-cache">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, minimal-ui" />
|
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, minimal-ui" />
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="full-screen" content="true" />
|
<meta name="full-screen" content="true" />
|
||||||
<meta name="screen-orientation" content="portrait" />
|
<meta name="screen-orientation" content="portrait" />
|
||||||
<meta name="x5-fullscreen" content="true" />
|
<meta name="x5-fullscreen" content="true" />
|
||||||
<meta name="360-fullscreen" content="true" />
|
<meta name="360-fullscreen" content="true" />
|
||||||
<meta name="apple-mobile-web-app-title" content="WJTX">
|
<meta name="apple-mobile-web-app-title" content="WJTX">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
<style>
|
<style>
|
||||||
body{background-color:#FFFFFF;padding: 20px;}
|
body{background-color:#FFFFFF;padding: 20px;}
|
||||||
button{
|
button{
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
}
|
}
|
||||||
.app{
|
.app{
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -35,63 +35,65 @@
|
|||||||
margin: 10px;
|
margin: 10px;
|
||||||
max-height: 50px;
|
max-height: 50px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class='app' id='app'>
|
<div class='app' id='app'>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
/**
|
/**
|
||||||
* 加载外部js
|
* 加载外部js
|
||||||
*/
|
*/
|
||||||
var loadSingleScript = function (sub) {
|
var loadSingleScript = function (sub) {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let src = sub[0];
|
|
||||||
console.log(`>> begin load script: ${src}`);
|
|
||||||
var s = document.createElement('script');
|
|
||||||
s.async = true;
|
|
||||||
if (sub[1] == 1)s.type = 'module';
|
|
||||||
// s.src = src + (src.indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
|
||||||
s.src =src;
|
|
||||||
s.addEventListener('load', function () {
|
|
||||||
console.log(`<< finish load script: ${src}`);
|
|
||||||
s.parentNode.removeChild(s);
|
|
||||||
s.removeEventListener('load', arguments.callee, false);
|
|
||||||
resolve && resolve();
|
|
||||||
}, false);
|
|
||||||
document.body.appendChild(s);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
var scripts = [
|
|
||||||
['assets/scripts/libs/jcwallet.js'],
|
|
||||||
['assets/scripts/libs/main.js'],
|
|
||||||
['assets/scripts/libs/utils.js'],
|
|
||||||
['assets/scripts/libs/native_bridge.js', 1],
|
|
||||||
['assets/scripts/libs/main_native_inject.js'],
|
|
||||||
['assets/scripts/run_sample.js'],
|
|
||||||
]
|
|
||||||
|
|
||||||
var loadScripts = async function (list, callback) {
|
|
||||||
var loaded = 0;
|
|
||||||
var loadNext = function () {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// list[loaded][0] = list[loaded][0] + (list[loaded][0].indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
let src = sub[0];
|
||||||
loadSingleScript(list[loaded]).then(() => {
|
console.log(`>> begin load script: ${src}`);
|
||||||
loaded++;
|
var s = document.createElement('script');
|
||||||
if (loaded >= list.length) {
|
s.async = true;
|
||||||
resolve();
|
if (sub[1] == 1)s.type = 'module';
|
||||||
} else {
|
// s.src = src + (src.indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
||||||
return loadNext();
|
s.src =src;
|
||||||
}
|
s.addEventListener('load', function () {
|
||||||
})
|
console.log(`<< finish load script: ${src}`);
|
||||||
|
s.parentNode.removeChild(s);
|
||||||
|
s.removeEventListener('load', arguments.callee, false);
|
||||||
|
resolve && resolve();
|
||||||
|
}, false);
|
||||||
|
document.body.appendChild(s);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
loadNext();
|
var scripts = [
|
||||||
};
|
['assets/scripts/libs/jcwallet.js'],
|
||||||
loadScripts(scripts, ()=> {})
|
['assets/scripts/libs/main.js'],
|
||||||
</script>
|
['assets/scripts/libs/utils.js'],
|
||||||
</body>
|
['assets/scripts/libs/native_bridge.js', 1],
|
||||||
|
['assets/scripts/libs/main_native_inject.js'],
|
||||||
|
['assets/scripts/run_sample.js'],
|
||||||
|
]
|
||||||
|
|
||||||
|
var loadScripts = function (list, refresh = false) {
|
||||||
|
var loaded = 0;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var loadNext = function () {
|
||||||
|
if (refresh) {
|
||||||
|
list[loaded][0] = list[loaded][0] + (list[loaded][0].indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
||||||
|
}
|
||||||
|
loadSingleScript(list[loaded]).then(() => {
|
||||||
|
loaded++;
|
||||||
|
if (loaded >= list.length) {
|
||||||
|
resolve && resolve();
|
||||||
|
} else {
|
||||||
|
return loadNext();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
loadNext();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
loadScripts(scripts);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user