tags menu

This commit is contained in:
zhangtao 2022-05-19 09:04:05 +08:00
parent a62eb480b3
commit c88d526db9
3 changed files with 45 additions and 23 deletions

View File

@ -21,7 +21,7 @@ const asyncRoutes = [
component: 'views/system/user/index', component: 'views/system/user/index',
name: 'SystemUser', name: 'SystemUser',
meta: { meta: {
title: '菜单管理' title: '用户管理'
} }
}, },
{ {

View File

@ -18,7 +18,7 @@
<div <div
:id="`tag${element.fullPath.split('/').join('\/')}`" :id="`tag${element.fullPath.split('/').join('\/')}`"
class="tabs-card-scroll-item" class="tabs-card-scroll-item"
:class="{ 'active-item': activeKey === element.path }" :class="{ 'active-item': state.activeKey === element.path }"
@click.stop="goPage(element)" @click.stop="goPage(element)"
@contextmenu="handleContextMenu($event, element)" @contextmenu="handleContextMenu($event, element)"
> >
@ -42,15 +42,18 @@ import {
CloseOutlined CloseOutlined
} from '@vicons/antd' } from '@vicons/antd'
import Draggable from 'vuedraggable' import Draggable from 'vuedraggable'
import { reactive, computed, toRaw } from 'vue' import { reactive, computed, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useTagsMenuStore } from '@/store/modules/tagsMenu.js' import { useTagsMenuStore } from '@/store/modules/tagsMenu.js'
import { useSettingStore } from '@/store/modules/setting.js' import { useSettingStore } from '@/store/modules/setting.js'
import { getTags, setTags } from '@/utils/tags.js' import { getTags, setTags } from '@/utils/tags.js'
import { isString } from '@/utils/is.js'
/* 获取路由器 */ /* 获取路由器 */
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const { push, replace } = router
const tagsMenuStore = useTagsMenuStore() const tagsMenuStore = useTagsMenuStore()
const settingStore = useSettingStore() const settingStore = useSettingStore()
const tabsList = computed(() => tagsMenuStore.tabsList) const tabsList = computed(() => tagsMenuStore.tabsList)
@ -82,6 +85,18 @@ const state = reactive({
scrollable: false scrollable: false
}) })
watch(
() => route.fullPath,
(to) => {
console.log('to', to)
// if (whiteList.includes(route.name)) return
state.activeKey = to
tagsMenuStore.addTabs(getSimpleRoute(route))
// updateNavScroll(true)
},
{ immediate: true }
)
/** /**
* @description: * @description:
* @param { Object } route * @param { Object } route
@ -119,10 +134,10 @@ function scrollNext() {
* @return {*} * @return {*}
*/ */
function goPage(e) { function goPage(e) {
// const { fullPath } = e const { fullPath } = e
// if (fullPath === route.fullPath) return if (fullPath === route.fullPath) return
// state.activeKey = fullPath state.activeKey = fullPath
// go(e, true) go(e, true)
} }
/** /**
* @description: 删除项 * @description: 删除项
@ -149,6 +164,18 @@ function handleContextMenu(e, item) {
// }) // })
} }
function go(opt, isReplace = false) {
if (!opt) {
return
}
if (isString(opt)) {
isReplace ? replace(opt).catch(e => console.log(e)) : push(opt).catch(e => console.log(e))
} else {
const o = opt
isReplace ? replace(o).catch(e => console.log(e)) : push(o).catch(e => console.log(e))
}
}
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.tabs-view { .tabs-view {
@ -156,6 +183,7 @@ function handleContextMenu(e, item) {
padding: 6px 0; padding: 6px 0;
display: flex; display: flex;
transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
background: #f5f7f9;
.tabs-view-main { .tabs-view-main {
height: 32px; height: 32px;
display: flex; display: flex;
@ -189,9 +217,9 @@ function handleContextMenu(e, item) {
.tabs-card-scroll { .tabs-card-scroll {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
&-item { .tabs-card-scroll-item {
background: v-bind(getCardColor); background: #ffffff;
color: v-bind(getBaseColor); // color: v-bind('tagsMenuSetting.color');
height: 32px; height: 32px;
padding: 6px 16px 4px; padding: 6px 16px 4px;
border-radius: 3px; border-radius: 3px;
@ -200,16 +228,13 @@ function handleContextMenu(e, item) {
display: inline-block; display: inline-block;
position: relative; position: relative;
flex: 0 0 auto; flex: 0 0 auto;
span { span {
float: left; float: left;
vertical-align: middle; vertical-align: middle;
} }
&:hover { &:hover {
color: #515a6e; color: #515a6e;
} }
.n-icon { .n-icon {
height: 22px; height: 22px;
width: 21px; width: 21px;
@ -218,20 +243,18 @@ function handleContextMenu(e, item) {
vertical-align: middle; vertical-align: middle;
text-align: center; text-align: center;
color: #808695; color: #808695;
&:hover { &:hover {
color: #515a6e !important; color: #515a6e !important;
} }
svg { svg {
height: 21px; height: 21px;
display: inline-block; display: inline-block;
} }
} }
&.active-item {
color: #2d8cf0;
}
} }
// .active-item {
// color: v-bind(getAppTheme);
// }
} }
} }
} }
@ -244,7 +267,4 @@ function handleContextMenu(e, item) {
left: 200px; left: 200px;
} }
.tabs-view-default-background {
background: #f5f7f9;
}
</style> </style>

View File

@ -17,7 +17,7 @@
<n-layout> <n-layout>
<Header /> <Header />
<Tags v-if="tagsMenuSetting.show" /> <Tags v-if="tagsMenuSetting.show" />
<n-layout class="layout__content"> <n-layout class="layout__content" :class="{'layout__content--fix': tagsMenuSetting.fixed }">
<router-view /> <router-view />
</n-layout> </n-layout>
</n-layout> </n-layout>
@ -39,5 +39,7 @@ const tagsMenuSetting = computed(() => settingStore.getTagsMenuSetting)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.layout__content--fix{
padding-top: 44px;
}
</style> </style>