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