feat: Add Error component
This commit is contained in:
parent
1492f9119a
commit
7411dbc9fd
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 181 KiB |
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 181 KiB |
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 187 KiB |
|
@ -0,0 +1,3 @@
|
|||
import Error from './src/Error.vue'
|
||||
|
||||
export { Error }
|
|
@ -0,0 +1,58 @@
|
|||
<script setup lang="ts">
|
||||
import pageError from '@/assets/svgs/404.svg'
|
||||
import networkError from '@/assets/svgs/500.svg'
|
||||
import noPermission from '@/assets/svgs/403.svg'
|
||||
import { propTypes } from '@/utils/propTypes'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { ElButton } from 'element-plus'
|
||||
|
||||
interface ErrorMap {
|
||||
url: string
|
||||
message: string
|
||||
buttonText: string
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const errorMap: {
|
||||
[key: string]: ErrorMap
|
||||
} = {
|
||||
'404': {
|
||||
url: pageError,
|
||||
message: t('error.pageError'),
|
||||
buttonText: t('error.returnToHome')
|
||||
},
|
||||
'500': {
|
||||
url: networkError,
|
||||
message: t('error.networkError'),
|
||||
buttonText: t('error.returnToHome')
|
||||
},
|
||||
'403': {
|
||||
url: noPermission,
|
||||
message: t('error.noPermission'),
|
||||
buttonText: t('error.returnToHome')
|
||||
}
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
type: propTypes.string.validate((v: string) => ['404', '500', '403'].includes(v)).def('404')
|
||||
})
|
||||
|
||||
const emit = defineEmits(['errorClick'])
|
||||
|
||||
const btnClick = () => {
|
||||
emit('errorClick', props.type)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex justify-center">
|
||||
<div class="text-center">
|
||||
<img width="350" :src="errorMap[type].url" alt="" />
|
||||
<div class="text-14px text-[var(--el-color-info)]">{{ errorMap[type].message }}</div>
|
||||
<div class="mt-20px">
|
||||
<ElButton type="primary" @click="btnClick">{{ errorMap[type].buttonText }}</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
|
@ -41,6 +41,12 @@ export default {
|
|||
delNoData: 'Please select the data to delete',
|
||||
delSuccess: 'Deleted successfully'
|
||||
},
|
||||
error: {
|
||||
noPermission: `Sorry, you don't have permission to access this page.`,
|
||||
pageError: 'Sorry, the page you visited does not exist.',
|
||||
networkError: 'Sorry, the server reported an error.',
|
||||
returnToHome: 'Return to home'
|
||||
},
|
||||
setting: {
|
||||
projectSetting: 'Project setting',
|
||||
theme: 'Theme',
|
||||
|
@ -119,7 +125,8 @@ export default {
|
|||
examplePage: 'Example page',
|
||||
exampleAdd: 'Example page - add',
|
||||
exampleEdit: 'Example page - edit',
|
||||
exampleDetail: 'Example page - detail'
|
||||
exampleDetail: 'Example page - detail',
|
||||
errorPage: 'Error page'
|
||||
},
|
||||
analysis: {
|
||||
newUser: 'New user',
|
||||
|
|
|
@ -41,6 +41,12 @@ export default {
|
|||
delNoData: '请选择需要删除的数据',
|
||||
delSuccess: '删除成功'
|
||||
},
|
||||
error: {
|
||||
noPermission: `抱歉,您无权访问此页面。`,
|
||||
pageError: '抱歉,您访问的页面不存在。',
|
||||
networkError: '抱歉,服务器报告错误。',
|
||||
returnToHome: '返回首页'
|
||||
},
|
||||
setting: {
|
||||
projectSetting: '项目配置',
|
||||
theme: '主题',
|
||||
|
@ -119,7 +125,8 @@ export default {
|
|||
examplePage: '综合示例 - 页面',
|
||||
exampleAdd: '综合示例 - 新增',
|
||||
exampleEdit: '综合示例 - 编辑',
|
||||
exampleDetail: '综合示例 - 详情'
|
||||
exampleDetail: '综合示例 - 详情',
|
||||
errorPage: '错误页面'
|
||||
},
|
||||
analysis: {
|
||||
newUser: '新增用户',
|
||||
|
|
|
@ -27,7 +27,7 @@ router.beforeEach(async (to, from, next) => {
|
|||
next({ path: '/' })
|
||||
} else {
|
||||
if (permissionStore.getIsAddRouters) {
|
||||
next()
|
||||
to.path === '/' ? next({ path: permissionStore.addRouters[0]?.path as string }) : next()
|
||||
return
|
||||
}
|
||||
await permissionStore.generateRoutes()
|
||||
|
@ -42,7 +42,7 @@ router.beforeEach(async (to, from, next) => {
|
|||
}
|
||||
} else {
|
||||
if (whiteList.indexOf(to.path) !== -1) {
|
||||
next()
|
||||
to.path === '/' ? next({ path: permissionStore.addRouters[0]?.path as string }) : next()
|
||||
} else {
|
||||
next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
|
||||
}
|
||||
|
|
|
@ -401,6 +401,43 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
|
|||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/error',
|
||||
component: Layout,
|
||||
redirect: '/error/404',
|
||||
name: 'Error',
|
||||
meta: {
|
||||
title: t('router.errorPage'),
|
||||
icon: 'ci:error',
|
||||
alwaysShow: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '404',
|
||||
component: () => import('@/views/Error/404.vue'),
|
||||
name: '404',
|
||||
meta: {
|
||||
title: '404'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '403',
|
||||
component: () => import('@/views/Error/403.vue'),
|
||||
name: '403',
|
||||
meta: {
|
||||
title: '403'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '500',
|
||||
component: () => import('@/views/Error/500.vue'),
|
||||
name: '500',
|
||||
meta: {
|
||||
title: '500'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
import { Error } from '@/components/Error'
|
||||
import { usePermissionStore } from '@/store/modules/permission'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const { push } = useRouter()
|
||||
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const errorClick = () => {
|
||||
push(permissionStore.addRouters[0]?.path as string)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Error type="403" @errorClick="errorClick" />
|
||||
</template>
|
|
@ -0,0 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
import { Error } from '@/components/Error'
|
||||
import { usePermissionStore } from '@/store/modules/permission'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const { push } = useRouter()
|
||||
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const errorClick = () => {
|
||||
push(permissionStore.addRouters[0]?.path as string)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Error @errorClick="errorClick" />
|
||||
</template>
|
|
@ -0,0 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
import { Error } from '@/components/Error'
|
||||
import { usePermissionStore } from '@/store/modules/permission'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const { push } = useRouter()
|
||||
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const errorClick = () => {
|
||||
push(permissionStore.addRouters[0]?.path as string)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Error type="500" @errorClick="errorClick" />
|
||||
</template>
|
|
@ -186,7 +186,7 @@ const save = async () => {
|
|||
</ContentWrap>
|
||||
|
||||
<Dialog v-model="dialogVisible" :title="dialogTitle">
|
||||
<Write v-if="actionType === 'edit'" ref="writeRef" :current-row="tableObject.currentRow" />
|
||||
<Write v-if="actionType !== 'detail'" ref="writeRef" :current-row="tableObject.currentRow" />
|
||||
|
||||
<Detail v-if="actionType === 'detail'" :current-row="tableObject.currentRow" />
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
import { Form } from '@/components/Form'
|
||||
import { useForm } from '@/hooks/web/useForm'
|
||||
import { PropType, reactive } from 'vue'
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import { TableData } from '@/api/table/types'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { required } from '@/utils/formRules'
|
||||
|
@ -113,17 +113,25 @@ const { register, methods, elFormRef } = useForm({
|
|||
schema
|
||||
})
|
||||
|
||||
if (props.currentRow) {
|
||||
const { setValues, setSchema } = methods
|
||||
setValues(props.currentRow)
|
||||
setSchema([
|
||||
{
|
||||
field: 'content',
|
||||
path: 'componentProps.defaultHtml',
|
||||
value: props.currentRow.content
|
||||
}
|
||||
])
|
||||
}
|
||||
watch(
|
||||
() => props.currentRow,
|
||||
(currentRow) => {
|
||||
if (!currentRow) return
|
||||
const { setValues, setSchema } = methods
|
||||
setValues(currentRow)
|
||||
setSchema([
|
||||
{
|
||||
field: 'content',
|
||||
path: 'componentProps.defaultHtml',
|
||||
value: currentRow.content
|
||||
}
|
||||
])
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
)
|
||||
|
||||
defineExpose({
|
||||
elFormRef,
|
||||
|
|
Loading…
Reference in New Issue