Skip to content

Commit d89d67e

Browse files
committed
增加标签页演示页面
1 parent 7f0d841 commit d89d67e

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

src/router/modules/tab.example.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { RouteRecordRaw } from 'vue-router'
2+
3+
function Layout() {
4+
return import('@/layouts/index.vue')
5+
}
6+
7+
const routes: RouteRecordRaw = {
8+
path: '/tab_example',
9+
component: Layout,
10+
redirect: '/tab_example/index',
11+
name: 'tabExample',
12+
meta: {
13+
title: '标签栏',
14+
i18n: 'route.tabbar',
15+
icon: 'i-ic:round-tab',
16+
},
17+
children: [
18+
{
19+
path: 'index',
20+
name: 'tabExampleIndex',
21+
component: () => import('@/views/tab_example/index.vue'),
22+
meta: {
23+
title: '标签栏演示',
24+
i18n: 'route.tabbar',
25+
sidebar: false,
26+
breadcrumb: false,
27+
activeMenu: '/tab_example',
28+
},
29+
},
30+
],
31+
}
32+
33+
export default routes

src/router/routes.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { RouteRecordRaw } from 'vue-router'
44
import MultilevelMenuExample from './modules/multilevel.menu.example'
55
import BreadcrumbExample from './modules/breadcrumb.example'
66
import KeepAliveExample from './modules/keep.alive.example'
7+
import TabExample from './modules/tab.example'
78
import ComponentExample from './modules/component.example'
89
import IconExample from './modules/icon.example'
910
import FeatureExample from './modules/feature.example'
@@ -96,6 +97,7 @@ const asyncRoutes: Route.recordMainRaw[] = [
9697
MultilevelMenuExample,
9798
BreadcrumbExample,
9899
KeepAliveExample,
100+
TabExample,
99101
ComponentExample,
100102
IconExample,
101103
FeatureExample,

src/views/tab_example/index.vue

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<route lang="yaml">
2+
meta:
3+
enabled: false
4+
</route>
5+
6+
<script setup lang="ts">
7+
import useSettingsStore from '@/store/modules/settings'
8+
9+
const settingsStore = useSettingsStore()
10+
11+
const tabbar = useTabbar()
12+
13+
function open() {
14+
tabbar.open(settingsStore.settings.home.fullPath)
15+
}
16+
function close() {
17+
tabbar.close(settingsStore.settings.home.fullPath)
18+
}
19+
function closeById() {
20+
tabbar.closeById()
21+
}
22+
function closeById2() {
23+
tabbar.closeById(settingsStore.settings.home.fullPath)
24+
}
25+
function closeOtherSide() {
26+
tabbar.closeOtherSide()
27+
}
28+
function closeLeftSide() {
29+
tabbar.closeLeftSide()
30+
}
31+
function closeRightSide() {
32+
tabbar.closeRightSide()
33+
}
34+
</script>
35+
36+
<template>
37+
<div>
38+
<PageHeader title="标签栏" content="功能类似于浏览器的标签栏,支持右键操作" />
39+
<PageMain title="打开新标签页">
40+
<p>如果目标地址已在标签栏存在,则直接切换并访问。如果目标地址在标签栏不存在,则会在当前标签页后面插入新的标签页。</p>
41+
<ElButton @click="open">
42+
打开主页
43+
</ElButton>
44+
</PageMain>
45+
<PageMain title="关闭当前标签页并跳转">
46+
<p>关闭当前标签页,同时跳转到新页面。</p>
47+
<ElButton @click="close">
48+
关闭当前标签页,并跳转到主页
49+
</ElButton>
50+
</PageMain>
51+
<PageMain title="关闭指定标签页">
52+
<p>如果当前只有一个标签时,则无法关闭。</p>
53+
<p>如果关闭的是当前标签页,则会在关闭后跳转至紧邻的标签页。</p>
54+
<p>如果关闭的目标页面不存在,则无法关闭。</p>
55+
<ElButton @click="closeById">
56+
关闭当前页面
57+
</ElButton>
58+
<ElButton @click="closeById2">
59+
关闭主页
60+
</ElButton>
61+
</PageMain>
62+
<PageMain title="关闭非当前标签页">
63+
<p>除了提供关闭非当前标签页的 API 外,还提供了校验 API 。</p>
64+
<ElButton :disabled="!tabbar.checkCloseOtherSide()" @click="closeOtherSide">
65+
关闭两侧标签页
66+
</ElButton>
67+
<ElButton :disabled="!tabbar.checkCloseLeftSide()" @click="closeLeftSide">
68+
关闭左侧标签页
69+
</ElButton>
70+
<ElButton :disabled="!tabbar.checkCloseRightSide()" @click="closeRightSide">
71+
关闭右侧标签页
72+
</ElButton>
73+
</PageMain>
74+
</div>
75+
</template>

0 commit comments

Comments
 (0)