重构代码, 优化加载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);
|
||||||
}
|
}
|
||||||
|
28
index.html
28
index.html
@ -1,5 +1,5 @@
|
|||||||
<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>
|
||||||
@ -18,10 +18,10 @@
|
|||||||
<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%;
|
||||||
@ -37,8 +37,8 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class='app' id='app'>
|
<div class='app' id='app'>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -73,25 +73,27 @@
|
|||||||
['assets/scripts/run_sample.js'],
|
['assets/scripts/run_sample.js'],
|
||||||
]
|
]
|
||||||
|
|
||||||
var loadScripts = async function (list, callback) {
|
var loadScripts = function (list, refresh = false) {
|
||||||
var loaded = 0;
|
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();
|
var loadNext = function () {
|
||||||
|
if (refresh) {
|
||||||
|
list[loaded][0] = list[loaded][0] + (list[loaded][0].indexOf("?") == -1 ? "?" : "&") + "t=" + Date.now();
|
||||||
|
}
|
||||||
loadSingleScript(list[loaded]).then(() => {
|
loadSingleScript(list[loaded]).then(() => {
|
||||||
loaded++;
|
loaded++;
|
||||||
if (loaded >= list.length) {
|
if (loaded >= list.length) {
|
||||||
resolve();
|
resolve && resolve();
|
||||||
} else {
|
} else {
|
||||||
return loadNext();
|
return loadNext();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
};
|
};
|
||||||
loadNext();
|
loadNext();
|
||||||
|
})
|
||||||
};
|
};
|
||||||
loadScripts(scripts, ()=> {})
|
loadScripts(scripts);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user