From 01bf014cc27654b9f3a7c0ed7831e68c7786b00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Wed, 16 Oct 2024 16:55:24 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20=E6=89=80=E6=9C=89=20loading=20?= =?UTF-8?q?=E6=95=88=E6=9E=9C=EF=BC=8C=E5=9C=A8=E5=8A=9F=E8=83=BD=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E5=BC=82=E5=B8=B8=E6=97=B6=E4=B9=9F=E8=83=BD=E6=81=A2?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/gui/src/view/mixins/plugin.js | 24 ++++++---- packages/gui/src/view/pages/index.vue | 1 + packages/gui/src/view/pages/setting.vue | 64 ++++++++++++++----------- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js index 9de7dc8d..9ebdb013 100644 --- a/packages/gui/src/view/mixins/plugin.js +++ b/packages/gui/src/view/mixins/plugin.js @@ -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 () { @@ -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 () {} }) diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue index b7c1147c..91b30774 100644 --- a/packages/gui/src/view/pages/index.vue +++ b/packages/gui/src/view/pages/index.vue @@ -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 diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue index d9088333..e42ba77c 100644 --- a/packages/gui/src/view/pages/setting.vue +++ b/packages/gui/src/view/pages/setting.vue @@ -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() @@ -374,25 +377,27 @@ export default { if (this.config.app.remoteConfig.enabled === false) { return } + this.reloadLoading = true + try { + const remoteConfig = {} - 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({ @@ -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 () {} })