Skip to content

Commit

Permalink
optimize: 所有 loading 效果,在功能出现异常时也能恢复
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Oct 16, 2024
1 parent 0859439 commit 01bf014
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
24 changes: 15 additions & 9 deletions packages/gui/src/view/mixins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export default {
return // 防重复提交
}
this.applyLoading = true
await this.applyBefore()
await this.saveConfig()
await this.applyAfter()
this.applyLoading = false
try {
await this.applyBefore()
await this.saveConfig()
await this.applyAfter()
} finally {
this.applyLoading = false
}
},
async applyBefore () {

Expand All @@ -64,12 +67,15 @@ export default {
okText: '确定',
onOk: async () => {
this.resetDefaultLoading = true
this.config = await this.$api.config.resetDefault(key)
if (this.ready) {
await this.ready(this.config)
try {
this.config = await this.$api.config.resetDefault(key)
if (this.ready) {
await this.ready(this.config)
}
await this.apply()
} finally {
this.resetDefaultLoading = false
}
await this.apply()
this.resetDefaultLoading = false
},
onCancel () {}
})
Expand Down
1 change: 1 addition & 0 deletions packages/gui/src/view/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export default {
console.log('this status', this.status)
return ret
} catch (err) {
btn.loading = false // 有时候记录日志会卡死,先设置为false
console.log('api invoke error:', err)
} finally {
btn.loading = false
Expand Down
64 changes: 36 additions & 28 deletions packages/gui/src/view/pages/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,14 @@ export default {
await this.saveConfig()
if (this.config.app.remoteConfig.enabled === true) {
this.reloadLoading = true
this.$message.info('开始下载远程配置')
await this.$api.config.downloadRemoteConfig()
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
this.reloadLoading = false
try {
this.$message.info('开始下载远程配置')
await this.$api.config.downloadRemoteConfig()
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
} finally {
this.reloadLoading = false
}
} else {
this.$message.info('远程配置已关闭,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
Expand All @@ -374,25 +377,27 @@ export default {
if (this.config.app.remoteConfig.enabled === false) {
return
}
this.reloadLoading = true
const remoteConfig = {}
this.reloadLoading = true
try {
const remoteConfig = {}
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old1 = ret })
await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.old2 = ret })
await this.$api.config.downloadRemoteConfig()
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.new1 = ret })
await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.new2 = ret })
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old1 = ret })
await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.old2 = ret })
await this.$api.config.downloadRemoteConfig()
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.new1 = ret })
await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.new2 = ret })
if (remoteConfig.old1 === remoteConfig.new1 && remoteConfig.old2 === remoteConfig.new2) {
this.$message.info('远程配置没有变化,不做任何处理。')
this.$message.warn('如果您确实修改了远程配置,请稍等片刻再重试!')
} else {
this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
if (remoteConfig.old1 === remoteConfig.new1 && remoteConfig.old2 === remoteConfig.new2) {
this.$message.info('远程配置没有变化,不做任何处理。')
this.$message.warn('如果您确实修改了远程配置,请稍等片刻再重试!')
} else {
this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
}
} finally {
this.reloadLoading = false
}
this.reloadLoading = false
},
async restoreFactorySettings () {
this.$confirm({
Expand Down Expand Up @@ -420,15 +425,18 @@ export default {
okText: '确定',
onOk: async () => {
this.removeUserConfigLoading = true
const result = await this.$api.config.removeUserConfig()
if (result) {
this.config = await this.$api.config.get()
this.$message.success('恢复出厂设置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
} else {
this.$message.info('已是出厂设置,无需恢复')
try {
const result = await this.$api.config.removeUserConfig()
if (result) {
this.config = await this.$api.config.get()
this.$message.success('恢复出厂设置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
} else {
this.$message.info('已是出厂设置,无需恢复')
}
} finally {
this.removeUserConfigLoading = false
}
this.removeUserConfigLoading = false
},
onCancel () {}
})
Expand Down

0 comments on commit 01bf014

Please sign in to comment.