optimize: 所有 loading 效果,在功能出现异常时也能恢复

pull/375/head
王良 2024-10-16 16:55:24 +08:00
parent 0859439f0a
commit 01bf014cc2
3 changed files with 52 additions and 37 deletions

View File

@ -44,10 +44,13 @@ export default {
return // 防重复提交 return // 防重复提交
} }
this.applyLoading = true this.applyLoading = true
try {
await this.applyBefore() await this.applyBefore()
await this.saveConfig() await this.saveConfig()
await this.applyAfter() await this.applyAfter()
} finally {
this.applyLoading = false this.applyLoading = false
}
}, },
async applyBefore () { async applyBefore () {
@ -64,12 +67,15 @@ export default {
okText: '确定', okText: '确定',
onOk: async () => { onOk: async () => {
this.resetDefaultLoading = true this.resetDefaultLoading = true
try {
this.config = await this.$api.config.resetDefault(key) this.config = await this.$api.config.resetDefault(key)
if (this.ready) { if (this.ready) {
await this.ready(this.config) await this.ready(this.config)
} }
await this.apply() await this.apply()
} finally {
this.resetDefaultLoading = false this.resetDefaultLoading = false
}
}, },
onCancel () {} onCancel () {}
}) })

View File

@ -313,6 +313,7 @@ export default {
console.log('this status', this.status) console.log('this status', this.status)
return ret return ret
} catch (err) { } catch (err) {
btn.loading = false // false
console.log('api invoke error:', err) console.log('api invoke error:', err)
} finally { } finally {
btn.loading = false btn.loading = false

View File

@ -360,11 +360,14 @@ export default {
await this.saveConfig() await this.saveConfig()
if (this.config.app.remoteConfig.enabled === true) { if (this.config.app.remoteConfig.enabled === true) {
this.reloadLoading = true this.reloadLoading = true
try {
this.$message.info('开始下载远程配置') this.$message.info('开始下载远程配置')
await this.$api.config.downloadRemoteConfig() await this.$api.config.downloadRemoteConfig()
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理') this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart() await this.reloadConfigAndRestart()
} finally {
this.reloadLoading = false this.reloadLoading = false
}
} else { } else {
this.$message.info('远程配置已关闭,开始重启代理服务和系统代理') this.$message.info('远程配置已关闭,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart() await this.reloadConfigAndRestart()
@ -374,8 +377,9 @@ export default {
if (this.config.app.remoteConfig.enabled === false) { if (this.config.app.remoteConfig.enabled === false) {
return return
} }
this.reloadLoading = true
this.reloadLoading = true
try {
const remoteConfig = {} const remoteConfig = {}
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old1 = ret }) await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old1 = ret })
@ -391,8 +395,9 @@ export default {
this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理') this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart() await this.reloadConfigAndRestart()
} }
} finally {
this.reloadLoading = false this.reloadLoading = false
}
}, },
async restoreFactorySettings () { async restoreFactorySettings () {
this.$confirm({ this.$confirm({
@ -420,6 +425,7 @@ export default {
okText: '确定', okText: '确定',
onOk: async () => { onOk: async () => {
this.removeUserConfigLoading = true this.removeUserConfigLoading = true
try {
const result = await this.$api.config.removeUserConfig() const result = await this.$api.config.removeUserConfig()
if (result) { if (result) {
this.config = await this.$api.config.get() this.config = await this.$api.config.get()
@ -428,7 +434,9 @@ export default {
} else { } else {
this.$message.info('已是出厂设置,无需恢复') this.$message.info('已是出厂设置,无需恢复')
} }
} finally {
this.removeUserConfigLoading = false this.removeUserConfigLoading = false
}
}, },
onCancel () {} onCancel () {}
}) })