admin-vben5/packages/business/common-ui/src/fallback/fallback.vue

111 lines
2.3 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script setup lang="ts">
2024-06-08 20:14:04 +08:00
import type { FallbackProps } from './fallback';
2024-05-19 21:20:42 +08:00
import { computed } from 'vue';
import { useRouter } from 'vue-router';
2024-06-08 19:49:06 +08:00
import { $t } from '@vben/locales';
import { IcRoundArrowBackIosNew } from '@vben-core/iconify';
import { VbenButton } from '@vben-core/shadcn-ui';
2024-06-08 20:14:04 +08:00
import Icon403 from './icons/icon-403.vue';
import Icon404 from './icons/icon-404.vue';
import Icon500 from './icons/icon-500.vue';
2024-05-19 21:20:42 +08:00
2024-06-08 20:14:04 +08:00
interface Props extends FallbackProps {}
2024-05-19 21:20:42 +08:00
defineOptions({
name: 'Fallback',
});
const props = withDefaults(defineProps<Props>(), {
description: '',
homePath: '/',
image: '',
2024-06-08 20:14:04 +08:00
showBack: true,
status: '404',
2024-05-19 21:20:42 +08:00
title: '',
});
const titleText = computed(() => {
2024-06-08 20:14:04 +08:00
if (props.title) {
return props.title;
}
switch (props.status) {
case '403': {
return $t('fallback.forbidden');
}
case '500': {
return $t('fallback.internal-error');
}
default: {
return $t('fallback.page-not-found');
}
}
2024-05-19 21:20:42 +08:00
});
const descText = computed(() => {
2024-06-08 20:14:04 +08:00
if (props.description) {
return props.description;
}
switch (props.status) {
case '403': {
return $t('fallback.forbidden-desc');
}
case '500': {
return $t('fallback.internal-error-desc');
}
default: {
return $t('fallback.page-not-found-desc');
}
}
});
const fallbackIcon = computed(() => {
switch (props.status) {
case '403': {
return Icon403;
}
case '500': {
return Icon500;
}
default: {
return Icon404;
}
}
2024-05-19 21:20:42 +08:00
});
const { push } = useRouter();
// 返回首页
function back() {
push(props.homePath);
}
</script>
<template>
2024-06-08 20:14:04 +08:00
<div class="flex size-full flex-col items-center justify-center duration-300">
2024-05-19 21:20:42 +08:00
<img v-if="image" :src="image" class="md:1/3 w-1/2 lg:w-1/4" />
2024-06-08 20:14:04 +08:00
<component :is="fallbackIcon" v-else class="md:1/3 h-1/3 w-1/2 lg:w-1/4" />
2024-05-28 23:53:15 +08:00
<div class="flex-col-center">
2024-06-08 20:14:04 +08:00
<p
v-if="titleText"
class="text-foreground mt-12 text-3xl md:text-4xl lg:text-5xl"
>
2024-05-19 21:20:42 +08:00
{{ titleText }}
</p>
2024-06-08 20:14:04 +08:00
<p
v-if="descText"
class="text-muted-foreground md:text-md my-6 lg:text-lg"
>
2024-05-19 21:20:42 +08:00
{{ descText }}
</p>
2024-06-08 20:14:04 +08:00
<VbenButton v-if="showBack" size="lg" @click="back">
2024-05-19 21:20:42 +08:00
<IcRoundArrowBackIosNew class="mr-2" />
{{ $t('common.back-to-home') }}
</VbenButton>
</div>
</div>
</template>