mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-02-02 15:38:10 +00:00
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import type { RouteLocationNormalizedLoaded, RouteRecordName } from 'vue-router'
|
|
import useSystemStore from '@/stores/modules/system'
|
|
|
|
interface Tabbar {
|
|
curr: string,
|
|
tabs: {
|
|
[key: RouteRecordName]: any
|
|
}
|
|
}
|
|
|
|
const useTabbarStore = defineStore('tabbar', {
|
|
state: (): Tabbar => {
|
|
return {
|
|
curr: '',
|
|
tabs: {}
|
|
}
|
|
},
|
|
actions: {
|
|
addTab(roter: RouteLocationNormalizedLoaded) {
|
|
if (roter.meta && roter.meta.type != 1) return
|
|
if (this.tabs[roter.name]) {
|
|
this.tabs[roter.name].query = roter.query || {}
|
|
return
|
|
}
|
|
this.tabs[roter.name] = {
|
|
path: roter.path,
|
|
title: roter.meta ? roter.meta.title : '',
|
|
name: roter.name,
|
|
query: roter.query || {},
|
|
compomentName: roter.matched.at(-1).components.default.__name
|
|
}
|
|
},
|
|
removeTab(path: string) {
|
|
delete this.tabs[path]
|
|
},
|
|
clearTab() {
|
|
this.tabs = {}
|
|
}
|
|
},
|
|
getters: {
|
|
tabLength: (state) => Object.keys(state.tabs).length,
|
|
tabNames: (state) => {
|
|
const name: any[] = []
|
|
if (!useSystemStore().tab) return name
|
|
Object.keys(state.tabs).forEach(key => {
|
|
name.push(state.tabs[key].compomentName)
|
|
})
|
|
return name
|
|
}
|
|
}
|
|
})
|
|
|
|
export default useTabbarStore
|