mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-29 13:34:32 +08:00
初步修改加载机制
This commit is contained in:
1 parent
6404c6f4d0
commit
39c655d355
13 files changed
+165
-333
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import axios, { AxiosRequestConfig } from 'axios';
|
||||
|
||||
class LoadTask<T> {
|
||||
loaded: boolean = false;
|
||||
promise?: Promise<T>;
|
||||
url: string;
|
||||
config?: AxiosRequestConfig<T>;
|
||||
|
||||
constructor(url: string, config?: AxiosRequestConfig<T>) {
|
||||
this.url = url;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
load() {
|
||||
if (this.promise) return this.promise;
|
||||
|
||||
return (this.promise = axios.get(this.url, this.config));
|
||||
}
|
||||
|
||||
static list: Promise<any>[] = [];
|
||||
static push(...tasks: LoadTask<any>[]) {
|
||||
this.list.push(...tasks.map(v => v.load()));
|
||||
}
|
||||
|
||||
static onEnd<T extends any[] = any[]>(): Promise<T> {
|
||||
return Promise.all(LoadTask.list) as Promise<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export default function load() {}
|
||||
Reference in new issue
Block a user