|
@@ -42,9 +42,9 @@ export default new (class {
|
|
|
* https://uniapp.dcloud.net.cn/tutorial/app-ios-uiwebview.html
|
|
* https://uniapp.dcloud.net.cn/tutorial/app-ios-uiwebview.html
|
|
|
*/
|
|
*/
|
|
|
private init(): Promise<typeof this.config> {
|
|
private init(): Promise<typeof this.config> {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
|
+ const filePath = './config/appconfig.json'
|
|
|
const getAppConfig = async () => {
|
|
const getAppConfig = async () => {
|
|
|
- const filePath = './config/appconfig.json'
|
|
|
|
|
if (plus.hasPlus()) {
|
|
if (plus.hasPlus()) {
|
|
|
const res = await plus.getLocalFileContent(filePath)
|
|
const res = await plus.getLocalFileContent(filePath)
|
|
|
return JSON.parse(res)
|
|
return JSON.parse(res)
|
|
@@ -60,30 +60,33 @@ export default new (class {
|
|
|
this.isReady = true
|
|
this.isReady = true
|
|
|
resolve(this.config)
|
|
resolve(this.config)
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
- reject('服务地址加载失败')
|
|
|
|
|
|
|
+ const result = this.tryinit('服务地址加载失败')
|
|
|
|
|
+ resolve(result)
|
|
|
})
|
|
})
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
- reject('配置文件加载失败')
|
|
|
|
|
|
|
+ const result = this.tryinit('配置文件加载失败')
|
|
|
|
|
+ resolve(result)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 服务初始化完成时触发
|
|
|
|
|
|
|
+ * 失败时重新尝试初始化,直到成功为止
|
|
|
|
|
+ * @param msg
|
|
|
*/
|
|
*/
|
|
|
- onReady() {
|
|
|
|
|
|
|
+ private tryinit = (msg: string) => {
|
|
|
|
|
+ console.error(msg)
|
|
|
return new Promise<typeof this.config>((resolve) => {
|
|
return new Promise<typeof this.config>((resolve) => {
|
|
|
- this.onload.finally(() => {
|
|
|
|
|
- if (this.isReady) {
|
|
|
|
|
- resolve(this.onload)
|
|
|
|
|
- } else {
|
|
|
|
|
- // 失败时重新尝试,直到成功为止
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- this.onload = this.init()
|
|
|
|
|
- this.onReady()
|
|
|
|
|
- }, 5000)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ resolve(this.init())
|
|
|
|
|
+ }, 5000)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 服务初始化完成时触发
|
|
|
|
|
+ */
|
|
|
|
|
+ onReady() {
|
|
|
|
|
+ return this.onload
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|