Files
iot-device-management-frontend/packages/effects/common-ui/src/ui/fallback/fallback.vue

165 lines
3.7 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-06-09 18:58:30 +08:00
import { computed, defineAsyncComponent } from 'vue';
2024-05-19 21:20:42 +08:00
import { useRouter } from 'vue-router';
import { ArrowLeft, RotateCw } from '@vben/icons';
import { $t } from '@vben/locales';
2024-06-08 19:49:06 +08:00
import { VbenButton } from '@vben-core/shadcn-ui';
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,
2024-07-14 13:48:47 +08:00
status: 'coming-soon',
2024-05-19 21:20:42 +08:00
title: '',
});
2024-06-09 18:58:30 +08:00
const Icon403 = defineAsyncComponent(() => import('./icons/icon-403.vue'));
const Icon404 = defineAsyncComponent(() => import('./icons/icon-404.vue'));
const Icon500 = defineAsyncComponent(() => import('./icons/icon-500.vue'));
2024-06-29 15:41:10 +08:00
const IconHello = defineAsyncComponent(
2024-07-14 13:48:47 +08:00
() => import('./icons/icon-coming-soon.vue'),
2024-06-29 15:41:10 +08:00
);
2024-06-09 18:58:30 +08:00
const IconOffline = defineAsyncComponent(
() => import('./icons/icon-offline.vue'),
);
2024-05-19 21:20:42 +08:00
const titleText = computed(() => {
2024-06-08 20:14:04 +08:00
if (props.title) {
return props.title;
}
switch (props.status) {
case '403': {
return $t('ui.fallback.forbidden');
2024-06-08 20:14:04 +08:00
}
2024-06-16 13:43:33 +08:00
case '404': {
return $t('ui.fallback.pageNotFound');
2024-06-16 13:43:33 +08:00
}
2024-06-08 20:14:04 +08:00
case '500': {
return $t('ui.fallback.internalError');
2024-06-08 20:14:04 +08:00
}
2024-07-14 13:48:47 +08:00
case 'coming-soon': {
return $t('ui.fallback.comingSoon');
2024-06-16 15:45:15 +08:00
}
chore(deps-dev): bump the non-breaking-changes group with 3 updates (#4671) * chore(deps-dev): bump the non-breaking-changes group with 3 updates Bumps the non-breaking-changes group with 3 updates: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node), [cspell](https://github.com/streetsidesoftware/cspell/tree/HEAD/packages/cspell) and [sass](https://github.com/sass/dart-sass). Updates `@types/node` from 22.7.5 to 22.7.6 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `cspell` from 8.15.2 to 8.15.3 - [Release notes](https://github.com/streetsidesoftware/cspell/releases) - [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/packages/cspell/CHANGELOG.md) - [Commits](https://github.com/streetsidesoftware/cspell/commits/v8.15.3/packages/cspell) Updates `sass` from 1.79.5 to 1.80.1 - [Release notes](https://github.com/sass/dart-sass/releases) - [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md) - [Commits](https://github.com/sass/dart-sass/compare/1.79.5...1.80.1) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: cspell dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: sass dependency-type: direct:development update-type: version-update:semver-minor dependency-group: non-breaking-changes ... Signed-off-by: dependabot[bot] <support@github.com> * chore: update deps * chore: update deps --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-18 21:38:39 +08:00
case 'offline': {
return $t('ui.fallback.offlineError');
chore(deps-dev): bump the non-breaking-changes group with 3 updates (#4671) * chore(deps-dev): bump the non-breaking-changes group with 3 updates Bumps the non-breaking-changes group with 3 updates: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node), [cspell](https://github.com/streetsidesoftware/cspell/tree/HEAD/packages/cspell) and [sass](https://github.com/sass/dart-sass). Updates `@types/node` from 22.7.5 to 22.7.6 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `cspell` from 8.15.2 to 8.15.3 - [Release notes](https://github.com/streetsidesoftware/cspell/releases) - [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/packages/cspell/CHANGELOG.md) - [Commits](https://github.com/streetsidesoftware/cspell/commits/v8.15.3/packages/cspell) Updates `sass` from 1.79.5 to 1.80.1 - [Release notes](https://github.com/sass/dart-sass/releases) - [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md) - [Commits](https://github.com/sass/dart-sass/compare/1.79.5...1.80.1) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: cspell dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: sass dependency-type: direct:development update-type: version-update:semver-minor dependency-group: non-breaking-changes ... Signed-off-by: dependabot[bot] <support@github.com> * chore: update deps * chore: update deps --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-18 21:38:39 +08:00
}
2024-06-08 20:14:04 +08:00
default: {
2024-06-16 13:43:33 +08:00
return '';
2024-06-08 20:14:04 +08:00
}
}
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('ui.fallback.forbiddenDesc');
2024-06-08 20:14:04 +08:00
}
2024-06-16 13:43:33 +08:00
case '404': {
return $t('ui.fallback.pageNotFoundDesc');
2024-06-16 13:43:33 +08:00
}
2024-06-08 20:14:04 +08:00
case '500': {
return $t('ui.fallback.internalErrorDesc');
2024-06-08 20:14:04 +08:00
}
2024-06-09 18:58:30 +08:00
case 'offline': {
return $t('ui.fallback.offlineErrorDesc');
2024-06-09 18:58:30 +08:00
}
2024-06-08 20:14:04 +08:00
default: {
2024-06-16 13:43:33 +08:00
return '';
2024-06-08 20:14:04 +08:00
}
}
});
const fallbackIcon = computed(() => {
switch (props.status) {
case '403': {
return Icon403;
}
2024-06-16 13:43:33 +08:00
case '404': {
return Icon404;
}
2024-06-08 20:14:04 +08:00
case '500': {
return Icon500;
}
2024-07-14 13:48:47 +08:00
case 'coming-soon': {
2024-06-16 13:43:33 +08:00
return IconHello;
}
chore(deps-dev): bump the non-breaking-changes group with 3 updates (#4671) * chore(deps-dev): bump the non-breaking-changes group with 3 updates Bumps the non-breaking-changes group with 3 updates: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node), [cspell](https://github.com/streetsidesoftware/cspell/tree/HEAD/packages/cspell) and [sass](https://github.com/sass/dart-sass). Updates `@types/node` from 22.7.5 to 22.7.6 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `cspell` from 8.15.2 to 8.15.3 - [Release notes](https://github.com/streetsidesoftware/cspell/releases) - [Changelog](https://github.com/streetsidesoftware/cspell/blob/main/packages/cspell/CHANGELOG.md) - [Commits](https://github.com/streetsidesoftware/cspell/commits/v8.15.3/packages/cspell) Updates `sass` from 1.79.5 to 1.80.1 - [Release notes](https://github.com/sass/dart-sass/releases) - [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md) - [Commits](https://github.com/sass/dart-sass/compare/1.79.5...1.80.1) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: cspell dependency-type: direct:development update-type: version-update:semver-patch dependency-group: non-breaking-changes - dependency-name: sass dependency-type: direct:development update-type: version-update:semver-minor dependency-group: non-breaking-changes ... Signed-off-by: dependabot[bot] <support@github.com> * chore: update deps * chore: update deps --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-18 21:38:39 +08:00
case 'offline': {
return IconOffline;
}
2024-06-08 20:14:04 +08:00
default: {
2024-06-16 13:43:33 +08:00
return null;
2024-06-08 20:14:04 +08:00
}
}
2024-05-19 21:20:42 +08:00
});
2024-06-16 13:43:33 +08:00
const showBack = computed(() => {
2024-07-16 22:07:28 +08:00
return props.status === '403' || props.status === '404';
2024-06-16 13:43:33 +08:00
});
const showRefresh = computed(() => {
2024-07-16 22:07:28 +08:00
return props.status === '500' || props.status === 'offline';
2024-06-16 13:43:33 +08:00
});
2024-05-19 21:20:42 +08:00
const { push } = useRouter();
// 返回首页
function back() {
push(props.homePath);
}
2024-06-16 13:43:33 +08:00
function refresh() {
location.reload();
}
2024-05-19 21:20:42 +08:00
</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-16 13:43:33 +08:00
<component
:is="fallbackIcon"
v-else-if="fallbackIcon"
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-16 13:43:33 +08:00
<slot v-if="$slots.title" name="title"></slot>
2024-06-08 20:14:04 +08:00
<p
2024-06-16 13:43:33 +08:00
v-else-if="titleText"
2024-06-16 23:25:28 +08:00
class="text-foreground mt-8 text-2xl md:text-3xl lg:text-4xl"
2024-06-08 20:14:04 +08:00
>
2024-05-19 21:20:42 +08:00
{{ titleText }}
</p>
2024-06-16 13:43:33 +08:00
<slot v-if="$slots.describe" name="describe"></slot>
2024-06-08 20:14:04 +08:00
<p
2024-06-16 13:43:33 +08:00
v-else-if="descText"
2024-06-16 23:25:28 +08:00
class="text-muted-foreground md:text-md my-4 lg:text-lg"
2024-06-08 20:14:04 +08:00
>
2024-05-19 21:20:42 +08:00
{{ descText }}
</p>
2024-06-16 13:43:33 +08:00
<slot v-if="$slots.action" name="action"></slot>
<VbenButton v-else-if="showBack" size="lg" @click="back">
<ArrowLeft class="mr-2 size-4" />
{{ $t('common.backToHome') }}
2024-05-19 21:20:42 +08:00
</VbenButton>
2024-06-16 13:43:33 +08:00
<VbenButton v-else-if="showRefresh" size="lg" @click="refresh">
<RotateCw class="mr-2 size-4" />
2024-06-16 13:43:33 +08:00
{{ $t('common.refresh') }}
</VbenButton>
2024-05-19 21:20:42 +08:00
</div>
</div>
</template>