Browse Source
- 新增 ErrorDialog 组件,用于在对话框中展示错误信息 - 在 config.ts 中集成 ErrorDialog,用于处理业务异常 - 优化了异常处理逻辑,增加了错误详情的展示功能master
2 changed files with 105 additions and 1 deletions
@ -0,0 +1,90 @@ |
|||
<script setup lang="ts"> |
|||
import { reactive } from "vue"; |
|||
import { ElIcon, ElSwitch } from "element-plus"; |
|||
import { CircleCloseFilled } from "@element-plus/icons-vue"; |
|||
|
|||
defineOptions({ |
|||
name: 'ErrorDialog', |
|||
}); |
|||
|
|||
// 定义 Props 类型 |
|||
interface ErrorDialogProps { |
|||
err: AxiosInterceptorError; |
|||
} |
|||
|
|||
// 读取组件 props 属性 |
|||
const props = withDefaults(defineProps<ErrorDialogProps>(), {}); |
|||
|
|||
// 定义 State 类型 |
|||
interface ErrorDialogState { |
|||
show: boolean; |
|||
} |
|||
|
|||
// state 属性 |
|||
const state = reactive<ErrorDialogState>({ |
|||
show: false, |
|||
}); |
|||
|
|||
// 定义 Data 类型 |
|||
interface ErrorDialogData { |
|||
} |
|||
|
|||
// 内部数据 |
|||
const data: ErrorDialogData = {}; |
|||
|
|||
interface ErrorDialogExpose { |
|||
state: ErrorDialogState; |
|||
data: ErrorDialogData; |
|||
} |
|||
|
|||
const expose: ErrorDialogExpose = { |
|||
state, |
|||
data, |
|||
}; |
|||
// 定义组件公开内容 |
|||
defineExpose(expose); |
|||
|
|||
export type { |
|||
ErrorDialogProps, |
|||
ErrorDialogState, |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<div class="error-dialog flex-column-container"> |
|||
<div class="flex-row-container"> |
|||
<ElIcon :size="20" style="color: #ff4d4f;"> |
|||
<CircleCloseFilled/> |
|||
</ElIcon> |
|||
<div class="flex-item-fill"> |
|||
{{ props.err?.message }} |
|||
</div> |
|||
<div v-if="props.err?.data?.error"> |
|||
<ElSwitch size="small" v-model="state.show"/> |
|||
查看详情 |
|||
</div> |
|||
</div> |
|||
<div v-if="props.err?.data?.error && state.show" class="show-details flex-item-fill"> |
|||
<pre class="show-details-pre">{{ props.err?.data?.error }}</pre> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<style scoped> |
|||
.show-details-pre { |
|||
width: 790px; |
|||
height: 470px; |
|||
overflow: auto; |
|||
padding: 0; |
|||
} |
|||
</style> |
|||
|
|||
<style> |
|||
.el-dialog:has(> .el-dialog__body > .error-dialog) { |
|||
min-height: 160px; |
|||
} |
|||
|
|||
.el-dialog:has(> .el-dialog__body > .error-dialog > .show-details) { |
|||
height: 600px !important; |
|||
} |
|||
</style> |
|||
Loading…
Reference in new issue