Skip to content

Commit

Permalink
新增示例demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jekip committed Jul 15, 2021
1 parent 8fd663e commit a6aa6d4
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/assets/images/exception/403.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/exception/404.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/exception/500.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/exception/developing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/exception/load-error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/exception/nodata.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/enums/pageEnum.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export enum PageEnum {
// basic login path
// 登录
BASE_LOGIN = '/login',
// basic home path
//重定向
REDIRECT = '/Redirect',
// 首页
BASE_HOME = '/dashboard',
// error page path
// 错误
ERROR_PAGE = '/exception',
// error log page path
ERROR_LOG_PAGE = '/error-log/list',
}
12 changes: 9 additions & 3 deletions src/layout/components/TagsView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
<div ref="navRef" class="tabs-card-nav" :style="getNavStyle">
<Draggable :list="tabsList" animation="300" item-key="fullPath">
<template #item="{element}">
<div class="tabs-card-scroll-item" @click.stop="goPage(element)" @contextmenu="handleContextMenu">
<div class="tabs-card-scroll-item"
:class="{'active-item':activeKey === element.path }"
@click.stop="goPage(element)"
@contextmenu="handleContextMenu">
<span>{{ element.meta.title }}</span>
<n-icon size="14" @click.stop="closeTabItem(element)">
<CloseOutlined/>
Expand Down Expand Up @@ -59,6 +62,7 @@ import { RouteItem } from '@/store/modules/tabsView'
import { useProjectSetting } from '@/hooks/setting/useProjectSetting'
import { useMessage } from 'naive-ui'
import Draggable from 'vuedraggable/src/vuedraggable'
import { PageEnum } from '@/enums/pageEnum'
import {
DownOutlined,
ReloadOutlined,
Expand Down Expand Up @@ -199,8 +203,7 @@ export default defineComponent({
// 标签页列表
const tabsList: any = computed(() => tabsViewStore.tabsList)
const whiteList = ['Redirect', 'login']
const whiteList = [PageEnum.REDIRECT, PageEnum.BASE_LOGIN]
watch(
() => route.fullPath,
Expand Down Expand Up @@ -516,6 +519,9 @@ export default defineComponent({
}
}
}
.active-item{
color: #2d8cf0
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions src/router/constant.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { MainView } from '@/layout/components/Main'

export const RedirectName = 'Redirect';

export const ParentLayout = 'ParentLayout';

export const ErrorPage = () => import('@/views/exception/404.vue');

/**
* @description: default layout
*/
export const Layout = () => import('@/layout/index.vue');

/**
* @description: parent-layout
*/
export const getParentLayout = (_name?: string) => {
return () =>
new Promise((resolve) => {
resolve({
name: PARENT_LAYOUT_NAME,
});
});
};
57 changes: 57 additions & 0 deletions src/router/modules/exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { RouteRecordRaw } from 'vue-router'
import { Layout } from '@/router/constant';
import { ExclamationCircleOutlined } from '@vicons/antd'
import { renderIcon } from '@/utils/index'

/**
* @param name 路由名称, 必须设置,且不能重名
* @param meta 路由元信息(路由附带扩展信息)
* @param redirect 重定向地址, 访问这个路由时,自定进行重定向
* @param meta.disabled 禁用整个菜单
* @param meta.title 菜单名称
* @param meta.icon 菜单图标
* @param meta.keepAlive 缓存该路由
* @param meta.sort 排序越小越排前
*
* */
const routes: Array<RouteRecordRaw> = [
{
path: '/exception',
name: 'Exception',
redirect: '/exception/403',
component: Layout,
meta: {
title: '异常页面',
icon: renderIcon(ExclamationCircleOutlined),
sort: 3
},
children: [
{
path: '403',
name: 'exception-403',
meta: {
title: '403',
},
component: () => import('@/views/exception/403.vue')
},
{
path: '404',
name: 'exception-404',
meta: {
title: '404',
},
component: () => import('@/views/exception/404.vue')
},
{
path: '500',
name: 'exception-500',
meta: {
title: '500',
},
component: () => import('@/views/exception/500.vue')
},
],
}
]

export default routes
57 changes: 57 additions & 0 deletions src/router/modules/result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { RouteRecordRaw } from 'vue-router'
import { Layout } from '@/router/constant';
import { CheckCircleOutlined } from '@vicons/antd'
import { renderIcon } from '@/utils/index'

/**
* @param name 路由名称, 必须设置,且不能重名
* @param meta 路由元信息(路由附带扩展信息)
* @param redirect 重定向地址, 访问这个路由时,自定进行重定向
* @param meta.disabled 禁用整个菜单
* @param meta.title 菜单名称
* @param meta.icon 菜单图标
* @param meta.keepAlive 缓存该路由
* @param meta.sort 排序越小越排前
*
* */
const routes: Array<RouteRecordRaw> = [
{
path: '/result',
name: 'Result',
redirect: '/result/success',
component: Layout,
meta: {
title: '结果页面',
icon: renderIcon(CheckCircleOutlined),
sort: 4
},
children: [
{
path: 'success',
name: 'result-success',
meta: {
title: '成功页',
},
component: () => import('@/views/result/success.vue')
},
{
path: 'fail',
name: 'result-fail',
meta: {
title: '失败页',
},
component: () => import('@/views/result/fail.vue')
},
{
path: 'info',
name: 'result-info',
meta: {
title: '信息页',
},
component: () => import('@/views/result/info.vue')
},
],
}
]

export default routes
4 changes: 4 additions & 0 deletions src/styles/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ body .n-card {
transition: all .2s ease-in-out;
}

body .n-icon{
vertical-align:middle;
}

body .proCard {
border-radius: 4px;

Expand Down
43 changes: 43 additions & 0 deletions src/views/exception/403.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div class="flex flex-col justify-center page-container">
<div class="text-center">
<img src="~@/assets/images/exception/403.svg" alt=""/>
</div>
<div class="text-center">
<h1 class="text-base text-gray-500">抱歉,你无权访问该页面</h1>
<n-button type="info" @click="goHome">回到首页</n-button>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRouter } from 'vue-router'
export default defineComponent({
setup() {
const router = useRouter()
return {
goHome(){
router.push('/')
}
}
}
})
</script>

<style lang="less" scoped>
.page-container {
width: 100%;
background-color: white;
border-radius: 4px;
padding: 50px 0;
.text-center{
h1{ color: #666;padding: 20px 0}
}
img {
width: 350px;
margin: 0 auto;
}
}
</style>
25 changes: 17 additions & 8 deletions src/views/exception/404.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
<template>
<div class="flex flex-col align-center justify-center page-container">
<div class="flex flex-col justify-center page-container">
<div class="text-center">
<h1 class="text-base text-gray-500">哎哟喂,您好像走丢了...</h1>
<router-link to="/" class="n-btn n-btn-primary">回到首页</router-link>
<img src="~@/assets/images/exception/404.svg" alt=""/>
</div>
<div class="text-center">
<img src="~@/assets/images/Error.svg" alt=""/>
<h1 class="text-base text-gray-500">抱歉,你访问的页面不存在</h1>
<n-button type="info" @click="goHome">回到首页</n-button>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { routes } from '@/router'
import { useRouter } from 'vue-router'
export default defineComponent({
name: '404'
setup() {
const router = useRouter()
return {
goHome(){
router.push('/')
}
}
}
})
</script>

<style lang="less" scoped>
.page-container {
width: 100%;
height: 100vh;
background-color: white;
border-radius: 4px;
padding: 50px 0;
.text-center{
h1{ color: #666;padding: 20px 0}
}
img {
width: 350px;
margin: 0 auto;
Expand Down
43 changes: 43 additions & 0 deletions src/views/exception/500.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div class="flex flex-col justify-center page-container">
<div class="text-center">
<img src="~@/assets/images/exception/500.svg" alt=""/>
</div>
<div class="text-center">
<h1 class="text-base text-gray-500">抱歉,服务器出错了</h1>
<n-button type="info" @click="goHome">回到首页</n-button>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRouter } from 'vue-router'
export default defineComponent({
setup() {
const router = useRouter()
return {
goHome(){
router.push('/')
}
}
}
})
</script>

<style lang="less" scoped>
.page-container {
width: 100%;
background-color: white;
border-radius: 4px;
padding: 50px 0;
.text-center{
h1{ color: #666;padding: 20px 0}
}
img {
width: 350px;
margin: 0 auto;
}
}
</style>
Loading

0 comments on commit a6aa6d4

Please sign in to comment.