Browse Source

tags menu

master
zhangtao 2 years ago
parent
commit
c88d526db9
3 changed files with 45 additions and 23 deletions
  1. +1
    -1
      mock/system/router.js
  2. +40
    -20
      src/layout/components/Tags/index.vue
  3. +4
    -2
      src/layout/index.vue

+ 1
- 1
mock/system/router.js View File

component: 'views/system/user/index', component: 'views/system/user/index',
name: 'SystemUser', name: 'SystemUser',
meta: { meta: {
title: '菜单管理'
title: '用户管理'
} }
}, },
{ {

+ 40
- 20
src/layout/components/Tags/index.vue View File

<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)"
> >
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)
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
* @return {*} * @return {*}
*/ */
function goPage(e) { function goPage(e) {
// const { fullPath } = e
// if (fullPath === route.fullPath) return
// state.activeKey = fullPath
// go(e, true)
const { fullPath } = e
if (fullPath === route.fullPath) return
state.activeKey = fullPath
go(e, true)
} }
/** /**
* @description: 删除项 * @description: 删除项
// }) // })
} }


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 {
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;
.tabs-card-scroll { .tabs-card-scroll {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
&-item {
background: v-bind(getCardColor);
color: v-bind(getBaseColor);
.tabs-card-scroll-item {
background: #ffffff;
// color: v-bind('tagsMenuSetting.color');
height: 32px; height: 32px;
padding: 6px 16px 4px; padding: 6px 16px 4px;
border-radius: 3px; border-radius: 3px;
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;
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);
// }
} }
} }
} }
left: 200px; left: 200px;
} }


.tabs-view-default-background {
background: #f5f7f9;
}
</style> </style>

+ 4
- 2
src/layout/index.vue View File

<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>
</script> </script>


<style lang="scss" scoped> <style lang="scss" scoped>

.layout__content--fix{
padding-top: 44px;
}
</style> </style>

Loading…
Cancel
Save