From da162f3cb2db97ab3bedbeeb3a34e7e13525829e Mon Sep 17 00:00:00 2001 From: jingrow Date: Tue, 22 Apr 2025 16:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=89=E8=A3=85=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=BC=B9=E5=87=BA=E6=A1=86=E7=82=B9=E5=87=BB=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E8=AE=A1=E5=88=92=E5=90=8E=E5=BC=B9=E5=87=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src2/components/site/InstallAppDialog.vue | 115 +++++++++++------- .../site/SiteAppPlanSelectDialog.vue | 17 +-- .../site/SiteAppPlanSelectorDialog.vue | 4 +- dashboard/src2/utils/toast.js | 46 ++++--- 4 files changed, 117 insertions(+), 65 deletions(-) diff --git a/dashboard/src2/components/site/InstallAppDialog.vue b/dashboard/src2/components/site/InstallAppDialog.vue index 215c08b..bf486b5 100644 --- a/dashboard/src2/components/site/InstallAppDialog.vue +++ b/dashboard/src2/components/site/InstallAppDialog.vue @@ -48,64 +48,97 @@ export default { if (row.plans) { this.show = false; - let SiteAppPlanSelectDialog = defineAsyncComponent(() => - import('./SiteAppPlanSelectDialog.vue') - ); - - renderDialog( - h(SiteAppPlanSelectDialog, { + import('./SiteAppPlanSelectDialog.vue').then(module => { + const SiteAppPlanSelectDialog = module.default; + + const component = h(SiteAppPlanSelectDialog, { app: row, currentPlan: null, onPlanSelected: plan => { - toast.promise( - this.$site.installApp.submit({ - app: row.app, - plan: plan.name - }), - { - loading: '正在安装应用...', - success: jobId => { - router.push({ - name: 'Site Job', - params: { - name: this.site, - id: jobId - } - }); - this.$emit('installed'); - this.show = false; - return '应用即将安装'; - }, - error: e => getToastErrorMessage(e) - } - ); - } - }) - ); + handleAppInstall(row, plan); + }, + "onPlan-selected": plan => { + handleAppInstall(row, plan); + }, + }); + + renderDialog(component); + }).catch(err => { + toast.error('加载组件失败'); + this.show = true; + }); } else { toast.promise( this.$site.installApp.submit({ app: row.app }), { - loading: '正在安装应用...', + loading: '正在创建安装任务...', success: jobId => { - router.push({ - name: 'Site Job', - params: { - name: this.site, - id: jobId - } - }); this.$emit('installed'); this.show = false; - return '应用即将安装'; + + try { + if (jobId) { + router.push({ + name: 'Site Job', + params: { + name: this.site, + id: String(jobId) + } + }).catch(err => { + }); + } else { + } + } catch (err) { + } + + return '应用安装任务已创建'; }, - error: e => getToastErrorMessage(e) + error: e => { + return getToastErrorMessage(e); + } } ); } }; + + const handleAppInstall = (app, plan) => { + toast.promise( + this.$site.installApp.submit({ + app: app.app, + plan: plan.name + }), + { + loading: '正在创建安装任务...', + success: jobId => { + this.$emit('installed'); + this.show = false; + + try { + if (jobId) { + router.push({ + name: 'Site Job', + params: { + name: this.site, + id: String(jobId) + } + }).catch(err => { + }); + } else { + } + } catch (err) { + } + + return '应用安装任务已创建'; + }, + error: e => { + return getToastErrorMessage(e); + } + } + ); + }; + return { label: '应用', fieldname: 'app', diff --git a/dashboard/src2/components/site/SiteAppPlanSelectDialog.vue b/dashboard/src2/components/site/SiteAppPlanSelectDialog.vue index c185d35..289e40b 100644 --- a/dashboard/src2/components/site/SiteAppPlanSelectDialog.vue +++ b/dashboard/src2/components/site/SiteAppPlanSelectDialog.vue @@ -3,7 +3,7 @@ v-model="showDialog" :app="app" :currentPlan="currentPlan" - @plan-select="onPlanSelect" + @plan-select="handlePlanSelect" /> @@ -17,7 +17,7 @@ export default { SiteAppPlanSelectorDialog }, props: ['app', 'currentPlan'], - emits: ['plan-changed', 'plan-selected'], + emits: ['plan-changed', 'plan-selected', 'onPlanSelected'], data() { return { showDialog: true @@ -29,10 +29,9 @@ export default { } }, methods: { - onPlanSelect(plan) { - // if current plan is specified it's for changing plan - // else it's for selecting plan while installing app - if (this.currentPlan) + handlePlanSelect(plan) { + if (this.currentPlan) { + // 更改现有计划 toast.promise( this.$resources.changeAppPlan.submit({ subscription: this.app.subscription.name, @@ -47,7 +46,11 @@ export default { error: e => getToastErrorMessage(e) } ); - else this.$emit('plan-selected', plan); + } else { + this.$emit('plan-selected', plan); + this.$emit('onPlanSelected', plan); + this.showDialog = false; + } } } }; diff --git a/dashboard/src2/components/site/SiteAppPlanSelectorDialog.vue b/dashboard/src2/components/site/SiteAppPlanSelectorDialog.vue index cfbca57..92c83b4 100644 --- a/dashboard/src2/components/site/SiteAppPlanSelectorDialog.vue +++ b/dashboard/src2/components/site/SiteAppPlanSelectorDialog.vue @@ -44,7 +44,9 @@ export default { }, set(val) { this.$emit('update:modelValue', val); - if (!val) this.selectedPlan = null; + if (!val) { + this.selectedPlan = null; + } } }, plans() { diff --git a/dashboard/src2/utils/toast.js b/dashboard/src2/utils/toast.js index 12707da..ce2efc8 100644 --- a/dashboard/src2/utils/toast.js +++ b/dashboard/src2/utils/toast.js @@ -1,16 +1,30 @@ -import { toast } from 'vue-sonner'; -import { h } from 'vue'; - -export function showErrorToast(error) { - let errorMessage = e.messages.length ? e.messages.join('\n') : e.message; - toast.error(errorMessage); -} - -export function getToastErrorMessage(e, fallbackMessage = 'An error occurred') { - const errorMessage = e.messages?.length - ? e.messages.join('
') - : e.message || fallbackMessage; - return h('div', { - innerHTML: errorMessage, - }); -} +import { toast } from 'vue-sonner'; +import { h } from 'vue'; + +export function showErrorToast(error) { + if (!error) { + toast.error('发生了未知错误'); + return; + } + + let errorMessage = error.messages?.length + ? error.messages.join('\n') + : (error.message || '发生了未知错误'); + toast.error(errorMessage); +} + +export function getToastErrorMessage(error, fallbackMessage = '发生了错误') { + if (!error) return fallbackMessage; + + try { + const errorMessage = error.messages?.length + ? error.messages.join('
') + : (error.message || fallbackMessage); + + return h('div', { + innerHTML: errorMessage, + }); + } catch (e) { + return fallbackMessage; + } +} \ No newline at end of file