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