修复安装应用弹出框点击选择计划后弹出错误提示
This commit is contained in:
parent
1d8820e00c
commit
da162f3cb2
@ -48,64 +48,97 @@ export default {
|
|||||||
if (row.plans) {
|
if (row.plans) {
|
||||||
this.show = false;
|
this.show = false;
|
||||||
|
|
||||||
let SiteAppPlanSelectDialog = defineAsyncComponent(() =>
|
import('./SiteAppPlanSelectDialog.vue').then(module => {
|
||||||
import('./SiteAppPlanSelectDialog.vue')
|
const SiteAppPlanSelectDialog = module.default;
|
||||||
);
|
|
||||||
|
|
||||||
renderDialog(
|
const component = h(SiteAppPlanSelectDialog, {
|
||||||
h(SiteAppPlanSelectDialog, {
|
|
||||||
app: row,
|
app: row,
|
||||||
currentPlan: null,
|
currentPlan: null,
|
||||||
onPlanSelected: plan => {
|
onPlanSelected: plan => {
|
||||||
toast.promise(
|
handleAppInstall(row, plan);
|
||||||
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)
|
"onPlan-selected": plan => {
|
||||||
}
|
handleAppInstall(row, plan);
|
||||||
);
|
},
|
||||||
}
|
});
|
||||||
})
|
|
||||||
);
|
renderDialog(component);
|
||||||
|
}).catch(err => {
|
||||||
|
toast.error('加载组件失败');
|
||||||
|
this.show = true;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
toast.promise(
|
toast.promise(
|
||||||
this.$site.installApp.submit({
|
this.$site.installApp.submit({
|
||||||
app: row.app
|
app: row.app
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
loading: '正在安装应用...',
|
loading: '正在创建安装任务...',
|
||||||
success: jobId => {
|
success: jobId => {
|
||||||
|
this.$emit('installed');
|
||||||
|
this.show = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (jobId) {
|
||||||
router.push({
|
router.push({
|
||||||
name: 'Site Job',
|
name: 'Site Job',
|
||||||
params: {
|
params: {
|
||||||
name: this.site,
|
name: this.site,
|
||||||
id: jobId
|
id: String(jobId)
|
||||||
}
|
}
|
||||||
|
}).catch(err => {
|
||||||
});
|
});
|
||||||
this.$emit('installed');
|
} else {
|
||||||
this.show = false;
|
}
|
||||||
return '应用即将安装';
|
} 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 {
|
return {
|
||||||
label: '应用',
|
label: '应用',
|
||||||
fieldname: 'app',
|
fieldname: 'app',
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
v-model="showDialog"
|
v-model="showDialog"
|
||||||
:app="app"
|
:app="app"
|
||||||
:currentPlan="currentPlan"
|
:currentPlan="currentPlan"
|
||||||
@plan-select="onPlanSelect"
|
@plan-select="handlePlanSelect"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export default {
|
|||||||
SiteAppPlanSelectorDialog
|
SiteAppPlanSelectorDialog
|
||||||
},
|
},
|
||||||
props: ['app', 'currentPlan'],
|
props: ['app', 'currentPlan'],
|
||||||
emits: ['plan-changed', 'plan-selected'],
|
emits: ['plan-changed', 'plan-selected', 'onPlanSelected'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showDialog: true
|
showDialog: true
|
||||||
@ -29,10 +29,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPlanSelect(plan) {
|
handlePlanSelect(plan) {
|
||||||
// if current plan is specified it's for changing plan
|
if (this.currentPlan) {
|
||||||
// else it's for selecting plan while installing app
|
// 更改现有计划
|
||||||
if (this.currentPlan)
|
|
||||||
toast.promise(
|
toast.promise(
|
||||||
this.$resources.changeAppPlan.submit({
|
this.$resources.changeAppPlan.submit({
|
||||||
subscription: this.app.subscription.name,
|
subscription: this.app.subscription.name,
|
||||||
@ -47,7 +46,11 @@ export default {
|
|||||||
error: e => getToastErrorMessage(e)
|
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) {
|
set(val) {
|
||||||
this.$emit('update:modelValue', val);
|
this.$emit('update:modelValue', val);
|
||||||
if (!val) this.selectedPlan = null;
|
if (!val) {
|
||||||
|
this.selectedPlan = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plans() {
|
plans() {
|
||||||
|
|||||||
@ -2,15 +2,29 @@ import { toast } from 'vue-sonner';
|
|||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
|
|
||||||
export function showErrorToast(error) {
|
export function showErrorToast(error) {
|
||||||
let errorMessage = e.messages.length ? e.messages.join('\n') : e.message;
|
if (!error) {
|
||||||
|
toast.error('发生了未知错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let errorMessage = error.messages?.length
|
||||||
|
? error.messages.join('\n')
|
||||||
|
: (error.message || '发生了未知错误');
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getToastErrorMessage(e, fallbackMessage = 'An error occurred') {
|
export function getToastErrorMessage(error, fallbackMessage = '发生了错误') {
|
||||||
const errorMessage = e.messages?.length
|
if (!error) return fallbackMessage;
|
||||||
? e.messages.join('<br>')
|
|
||||||
: e.message || fallbackMessage;
|
try {
|
||||||
|
const errorMessage = error.messages?.length
|
||||||
|
? error.messages.join('<br>')
|
||||||
|
: (error.message || fallbackMessage);
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
innerHTML: errorMessage,
|
innerHTML: errorMessage,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return fallbackMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user