mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-12-31 11:39:18 +00:00
tabs优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { filterMenus } from '@/components/utils'
|
import { filterMenus } from '@/components/utils'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
menus: {
|
menus: {
|
||||||
@@ -11,12 +12,16 @@ const props = defineProps({
|
|||||||
const menuItems = computed(() => {
|
const menuItems = computed(() => {
|
||||||
return filterMenus(props.menus)
|
return filterMenus(props.menus)
|
||||||
})
|
})
|
||||||
|
const activeRoutePath = computed(() => {
|
||||||
|
const route = useRoute()
|
||||||
|
return route.path !== '/' ? route.path : ''
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-menu
|
<el-menu
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:default-active="$route.path"
|
:default-active="activeRoutePath"
|
||||||
router
|
router
|
||||||
>
|
>
|
||||||
<slot name="before" />
|
<slot name="before" />
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const removeHistoryTab = path => {
|
|||||||
<el-tabs
|
<el-tabs
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
v-model="currentTabValue"
|
v-model="currentTabValue"
|
||||||
|
class="common-tabs"
|
||||||
type="card"
|
type="card"
|
||||||
:closable="tabsViewStore.historyTabs.length>1"
|
:closable="tabsViewStore.historyTabs.length>1"
|
||||||
@tab-change="selectHistoryTab"
|
@tab-change="selectHistoryTab"
|
||||||
@@ -57,5 +58,10 @@ const removeHistoryTab = path => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.common-tabs > .el-tabs__content {
|
||||||
|
padding: 32px;
|
||||||
|
color: #6b778c;
|
||||||
|
font-size: 32px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useMenuName } from '@/components/utils'
|
import { useMenuInfo, useMenuName } from '@/components/utils'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
import { useTabsViewStore } from '@/stores/TabsViewStore'
|
||||||
|
|
||||||
|
const tabsViewStore = useTabsViewStore()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
tabItem: {
|
tabItem: {
|
||||||
@@ -10,19 +13,36 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const menuName = computed(() => {
|
const menuName = computed(() => {
|
||||||
if (props.tabItem) {
|
return useMenuName(props.tabItem)
|
||||||
return useMenuName(props.tabItem)
|
})
|
||||||
}
|
|
||||||
|
const menuInfo = computed(() => {
|
||||||
|
return props.tabItem.path === '/' ? { icon: 'HomeFilled' } : useMenuInfo(props.tabItem)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-tab-pane
|
<el-tab-pane
|
||||||
:label="menuName"
|
|
||||||
:name="tabItem.path"
|
:name="tabItem.path"
|
||||||
/>
|
>
|
||||||
|
<template #label>
|
||||||
|
<span class="custom-tabs-label">
|
||||||
|
<common-icon
|
||||||
|
v-if="tabsViewStore.isShowTabIcon && menuInfo && menuInfo.icon"
|
||||||
|
:icon="menuInfo.icon"
|
||||||
|
/>
|
||||||
|
<span>{{ menuName }}</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-tab-pane>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.common-tabs .custom-tabs-label .el-icon {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.common-tabs .custom-tabs-label span {
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -12,14 +12,17 @@ const calcWithIf = menuItem => {
|
|||||||
|
|
||||||
export const MENU_INFO_LIST = ref({})
|
export const MENU_INFO_LIST = ref({})
|
||||||
|
|
||||||
export const useMenuInfo = path => {
|
export const useMenuInfo = item => {
|
||||||
const menuInfo = MENU_INFO_LIST.value[path]
|
const path = item.path
|
||||||
console.info('================', MENU_INFO_LIST.value)
|
if (path !== '/') {
|
||||||
return menuInfo
|
const menuInfo = MENU_INFO_LIST.value[path]
|
||||||
|
console.info('config menu:', menuInfo)
|
||||||
|
return menuInfo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMenuName = item => {
|
export const useMenuName = item => {
|
||||||
const menuInfo = useMenuInfo(item.path)
|
const menuInfo = useMenuInfo(item)
|
||||||
if (menuInfo) {
|
if (menuInfo) {
|
||||||
if (menuInfo.label) {
|
if (menuInfo.label) {
|
||||||
return menuInfo.label
|
return menuInfo.label
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ const router = createRouter({
|
|||||||
name: 'home',
|
name: 'home',
|
||||||
component: HomeView,
|
component: HomeView,
|
||||||
children: [{
|
children: [{
|
||||||
|
path: '',
|
||||||
|
name: 'index',
|
||||||
|
component: () => import('@/views/Index.vue'),
|
||||||
|
meta: {
|
||||||
|
labelKey: 'common.label.index'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
path: 'about',
|
path: 'about',
|
||||||
name: 'about',
|
name: 'about',
|
||||||
component: () => import('@/views/account/AboutView.vue')
|
component: () => import('@/views/account/AboutView.vue')
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ export const useBusinessMenus = () => {
|
|||||||
return ref([
|
return ref([
|
||||||
{
|
{
|
||||||
icon: 'HomeFilled',
|
icon: 'HomeFilled',
|
||||||
|
index: '/',
|
||||||
labelIf: () => $i18nBundle('common.label.title')
|
labelIf: () => $i18nBundle('common.label.title')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -105,7 +106,7 @@ export const useBusinessMenus = () => {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'BuildRound',
|
icon: 'BuildFilled',
|
||||||
labelKey: 'menu.label.toolsManagement',
|
labelKey: 'menu.label.toolsManagement',
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@@ -120,7 +121,7 @@ export const useBusinessMenus = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
index: '/forms',
|
index: '/forms',
|
||||||
icon: 'TableRowsTwotone',
|
icon: 'TableRowsFilled',
|
||||||
labelKey: 'menu.label.toolsForms'
|
labelKey: 'menu.label.toolsForms'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { defineStore } from 'pinia'
|
|||||||
export const useTabsViewStore = defineStore('tabsView', () => {
|
export const useTabsViewStore = defineStore('tabsView', () => {
|
||||||
const isTabMode = ref(true)
|
const isTabMode = ref(true)
|
||||||
const isCachedTabMode = ref(true)
|
const isCachedTabMode = ref(true)
|
||||||
|
const isShowTabIcon = ref(true)
|
||||||
const historyTabs = ref([])
|
const historyTabs = ref([])
|
||||||
const cachedTabs = ref([])
|
const cachedTabs = ref([])
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ export const useTabsViewStore = defineStore('tabsView', () => {
|
|||||||
return {
|
return {
|
||||||
isTabMode,
|
isTabMode,
|
||||||
isCachedTabMode,
|
isCachedTabMode,
|
||||||
|
isShowTabIcon,
|
||||||
historyTabs,
|
historyTabs,
|
||||||
cachedTabs,
|
cachedTabs,
|
||||||
changeTabMode () {
|
changeTabMode () {
|
||||||
@@ -75,6 +77,9 @@ export const useTabsViewStore = defineStore('tabsView', () => {
|
|||||||
cachedTabs.value = []
|
cachedTabs.value = []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
changeShowTabIcon () {
|
||||||
|
isShowTabIcon.value = !isShowTabIcon.value
|
||||||
|
},
|
||||||
removeHistoryTab,
|
removeHistoryTab,
|
||||||
clearHistoryTabs,
|
clearHistoryTabs,
|
||||||
findHistoryTab,
|
findHistoryTab,
|
||||||
|
|||||||
13
src/views/Index.vue
Normal file
13
src/views/Index.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<script setup>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<strong>首页测试</strong>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user