修复安装应用弹出框点击选择计划后弹出错误提示
This commit is contained in:
parent
1d8820e00c
commit
da162f3cb2
@ -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',
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
v-model="showDialog"
|
||||
:app="app"
|
||||
:currentPlan="currentPlan"
|
||||
@plan-select="onPlanSelect"
|
||||
@plan-select="handlePlanSelect"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -44,7 +44,9 @@ export default {
|
||||
},
|
||||
set(val) {
|
||||
this.$emit('update:modelValue', val);
|
||||
if (!val) this.selectedPlan = null;
|
||||
if (!val) {
|
||||
this.selectedPlan = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
plans() {
|
||||
|
||||
@ -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('<br>')
|
||||
: 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('<br>')
|
||||
: (error.message || fallbackMessage);
|
||||
|
||||
return h('div', {
|
||||
innerHTML: errorMessage,
|
||||
});
|
||||
} catch (e) {
|
||||
return fallbackMessage;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user