pref: catch global error and show with notification component
This commit is contained in:
parent
b384fdaf32
commit
aef8830911
|
@ -5,6 +5,7 @@
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"success": "Success",
|
"success": "Success",
|
||||||
"warning": "Warning",
|
"warning": "Warning",
|
||||||
|
"error": "Error",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"default": "Default",
|
"default": "Default",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
"success": "成功",
|
"success": "成功",
|
||||||
"warning": "警告",
|
"warning": "警告",
|
||||||
|
"error": "错误",
|
||||||
"save": "保存",
|
"save": "保存",
|
||||||
"none": "无",
|
"none": "无",
|
||||||
"default": "默认",
|
"default": "默认",
|
||||||
|
|
|
@ -20,6 +20,18 @@ async function setupApp() {
|
||||||
const prefStore = usePreferencesStore()
|
const prefStore = usePreferencesStore()
|
||||||
await prefStore.loadPreferences()
|
await prefStore.loadPreferences()
|
||||||
await setupDiscreteApi()
|
await setupDiscreteApi()
|
||||||
|
app.config.errorHandler = (err, instance, info) => {
|
||||||
|
// TODO: add "send error message to author" later
|
||||||
|
$notification.error({
|
||||||
|
title: i18n.global.t('error'),
|
||||||
|
content: err.toString(),
|
||||||
|
// meta: err.stack,
|
||||||
|
})
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
app.config.warnHandler = (message) => {
|
||||||
|
console.warn(message)
|
||||||
|
}
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ function setupMessage(message) {
|
||||||
return message.info(content, option)
|
return message.info(content, option)
|
||||||
},
|
},
|
||||||
loading: (content, option = null) => {
|
loading: (content, option = null) => {
|
||||||
|
option.duration = option.duration || 30000
|
||||||
|
option.keepAliveOnHover = option.keepAliveOnHover !== undefined ? option.keepAliveOnHover : true
|
||||||
return message.loading(content, option)
|
return message.loading(content, option)
|
||||||
},
|
},
|
||||||
success: (content, option = null) => {
|
success: (content, option = null) => {
|
||||||
|
@ -24,6 +26,26 @@ function setupMessage(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupNotification(notification) {
|
||||||
|
return {
|
||||||
|
error: (content, option = null) => {
|
||||||
|
option.title = option.title || i18nGlobal.t('error')
|
||||||
|
return notification.error(content, option)
|
||||||
|
},
|
||||||
|
info: (content, option = null) => {
|
||||||
|
return notification.info(content, option)
|
||||||
|
},
|
||||||
|
success: (content, option = null) => {
|
||||||
|
option.title = option.title || i18nGlobal.t('success')
|
||||||
|
return notification.success(content, option)
|
||||||
|
},
|
||||||
|
warning: (content, option = null) => {
|
||||||
|
option.title = option.title || i18nGlobal.t('warning')
|
||||||
|
return notification.warning(content, option)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupDialog(dialog) {
|
function setupDialog(dialog) {
|
||||||
return {
|
return {
|
||||||
warning: (content, onConfirm) => {
|
warning: (content, onConfirm) => {
|
||||||
|
@ -53,13 +75,18 @@ export async function setupDiscreteApi() {
|
||||||
theme: prefStore.isDark ? darkTheme : undefined,
|
theme: prefStore.isDark ? darkTheme : undefined,
|
||||||
themeOverrides,
|
themeOverrides,
|
||||||
}))
|
}))
|
||||||
const { message, dialog } = createDiscreteApi(['message', 'dialog'], {
|
const { message, dialog, notification } = createDiscreteApi(['message', 'notification', 'dialog'], {
|
||||||
configProviderProps,
|
configProviderProps,
|
||||||
messageProviderProps: {
|
messageProviderProps: {
|
||||||
placement: 'bottom-right',
|
placement: 'bottom-right',
|
||||||
},
|
},
|
||||||
|
notificationProviderProps: {
|
||||||
|
placement: 'top-right',
|
||||||
|
keepAliveOnHover: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
window.$message = setupMessage(message)
|
window.$message = setupMessage(message)
|
||||||
|
window.$notification = setupNotification(notification)
|
||||||
window.$dialog = setupDialog(dialog)
|
window.$dialog = setupDialog(dialog)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue