30 changed files with 476 additions and 620 deletions
@ -1,18 +0,0 @@ |
|||||
const getters = { |
|
||||
sidebar: state => state.app.sidebar, |
|
||||
size: state => state.app.size, |
|
||||
device: state => state.app.device, |
|
||||
visitedViews: state => state.tagsView.visitedViews, |
|
||||
cachedViews: state => state.tagsView.cachedViews, |
|
||||
token: state => state.user.token, |
|
||||
avatar: state => state.user.avatar, |
|
||||
name: state => state.user.name, |
|
||||
introduction: state => state.user.introduction, |
|
||||
roles: state => state.user.roles, |
|
||||
permissions: state => state.user.permissions, |
|
||||
permission_routes: state => state.permission.routes, |
|
||||
topbarRouters:state => state.permission.topbarRouters, |
|
||||
defaultRoutes:state => state.permission.defaultRoutes, |
|
||||
sidebarRouters:state => state.permission.sidebarRouters, |
|
||||
} |
|
||||
export default getters |
|
||||
@ -1,21 +1,3 @@ |
|||||
import { createStore } from 'vuex' |
const store = createPinia() |
||||
import app from './modules/app' |
|
||||
import user from './modules/user' |
|
||||
import tagsView from './modules/tagsView' |
|
||||
import permission from './modules/permission' |
|
||||
import settings from './modules/settings' |
|
||||
import getters from './getters' |
|
||||
|
|
||||
const store = createStore({ |
|
||||
modules: { |
|
||||
app, |
|
||||
user, |
|
||||
tagsView, |
|
||||
permission, |
|
||||
settings |
|
||||
}, |
|
||||
getters |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
export default store |
export default store |
||||
@ -1,66 +1,47 @@ |
|||||
import Cookies from 'js-cookie' |
import Cookies from 'js-cookie' |
||||
|
|
||||
const state = { |
|
||||
sidebar: { |
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, |
|
||||
withoutAnimation: false, |
|
||||
hide: false |
|
||||
}, |
|
||||
device: 'desktop', |
|
||||
size: Cookies.get('size') || 'default' |
|
||||
} |
|
||||
|
|
||||
const mutations = { |
const useAppStore = defineStore( |
||||
TOGGLE_SIDEBAR: state => { |
'app', |
||||
if (state.sidebar.hide) { |
{ |
||||
return false; |
state: () => ({ |
||||
|
sidebar: { |
||||
|
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, |
||||
|
withoutAnimation: false, |
||||
|
hide: false |
||||
|
}, |
||||
|
device: 'desktop', |
||||
|
size: Cookies.get('size') || 'default' |
||||
|
}), |
||||
|
actions: { |
||||
|
toggleSideBar(withoutAnimation) { |
||||
|
if (this.sidebar.hide) { |
||||
|
return false; |
||||
|
} |
||||
|
this.sidebar.opened = !this.sidebar.opened |
||||
|
this.sidebar.withoutAnimation = withoutAnimation |
||||
|
if (this.sidebar.opened) { |
||||
|
Cookies.set('sidebarStatus', 1) |
||||
|
} else { |
||||
|
Cookies.set('sidebarStatus', 0) |
||||
|
} |
||||
|
}, |
||||
|
closeSideBar(withoutAnimation) { |
||||
|
Cookies.set('sidebarStatus', 0) |
||||
|
this.sidebar.opened = false |
||||
|
this.sidebar.withoutAnimation = withoutAnimation |
||||
|
}, |
||||
|
toggleDevice(device) { |
||||
|
this.device = device |
||||
|
}, |
||||
|
setSize(size) { |
||||
|
this.size = size; |
||||
|
Cookies.set('size', size) |
||||
|
}, |
||||
|
toggleSideBarHide(status) { |
||||
|
this.sidebar.hide = status |
||||
|
} |
||||
} |
} |
||||
state.sidebar.opened = !state.sidebar.opened |
}) |
||||
state.sidebar.withoutAnimation = false |
|
||||
if (state.sidebar.opened) { |
|
||||
Cookies.set('sidebarStatus', 1) |
|
||||
} else { |
|
||||
Cookies.set('sidebarStatus', 0) |
|
||||
} |
|
||||
}, |
|
||||
CLOSE_SIDEBAR: (state, withoutAnimation) => { |
|
||||
Cookies.set('sidebarStatus', 0) |
|
||||
state.sidebar.opened = false |
|
||||
state.sidebar.withoutAnimation = withoutAnimation |
|
||||
}, |
|
||||
TOGGLE_DEVICE: (state, device) => { |
|
||||
state.device = device |
|
||||
}, |
|
||||
SET_SIZE: (state, size) => { |
|
||||
state.size = size |
|
||||
Cookies.set('size', size) |
|
||||
}, |
|
||||
SET_SIDEBAR_HIDE: (state, status) => { |
|
||||
state.sidebar.hide = status |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
const actions = { |
|
||||
toggleSideBar({ commit }) { |
|
||||
commit('TOGGLE_SIDEBAR') |
|
||||
}, |
|
||||
closeSideBar({ commit }, { withoutAnimation }) { |
|
||||
commit('CLOSE_SIDEBAR', withoutAnimation) |
|
||||
}, |
|
||||
toggleDevice({ commit }, device) { |
|
||||
commit('TOGGLE_DEVICE', device) |
|
||||
}, |
|
||||
setSize({ commit }, size) { |
|
||||
commit('SET_SIZE', size) |
|
||||
}, |
|
||||
toggleSideBarHide({ commit }, status) { |
|
||||
commit('SET_SIDEBAR_HIDE', status) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default { |
export default useAppStore |
||||
namespaced: true, |
|
||||
state, |
|
||||
mutations, |
|
||||
actions |
|
||||
} |
|
||||
|
|||||
@ -1,207 +1,153 @@ |
|||||
const state = { |
const useTagsViewStore = defineStore( |
||||
visitedViews: [], |
'tags-view', |
||||
cachedViews: [] |
{ |
||||
} |
state: () => ({ |
||||
|
visitedViews: [], |
||||
const mutations = { |
cachedViews: [] |
||||
ADD_VISITED_VIEW: (state, view) => { |
}), |
||||
if (state.visitedViews.some(v => v.path === view.path)) return |
actions: { |
||||
state.visitedViews.push( |
addView(view) { |
||||
Object.assign({}, view, { |
this.addVisitedView(view) |
||||
title: view.meta.title || 'no-name' |
this.addCachedView(view) |
||||
}) |
}, |
||||
) |
addVisitedView(view) { |
||||
}, |
if (this.visitedViews.some(v => v.path === view.path)) return |
||||
ADD_CACHED_VIEW: (state, view) => { |
this.visitedViews.push( |
||||
if (state.cachedViews.includes(view.name)) return |
Object.assign({}, view, { |
||||
if (!view.meta.noCache) { |
title: view.meta.title || 'no-name' |
||||
state.cachedViews.push(view.name) |
}) |
||||
} |
) |
||||
}, |
}, |
||||
|
addCachedView(view) { |
||||
DEL_VISITED_VIEW: (state, view) => { |
if (this.cachedViews.includes(view.name)) return |
||||
for (const [i, v] of state.visitedViews.entries()) { |
if (!view.meta.noCache) { |
||||
if (v.path === view.path) { |
this.cachedViews.push(view.name) |
||||
state.visitedViews.splice(i, 1) |
} |
||||
break |
}, |
||||
} |
delView(view) { |
||||
} |
return new Promise(resolve => { |
||||
}, |
this.delVisitedView(view) |
||||
DEL_CACHED_VIEW: (state, view) => { |
this.delCachedView(view) |
||||
const index = state.cachedViews.indexOf(view.name) |
resolve({ |
||||
index > -1 && state.cachedViews.splice(index, 1) |
visitedViews: [...this.visitedViews], |
||||
}, |
cachedViews: [...this.cachedViews] |
||||
|
}) |
||||
DEL_OTHERS_VISITED_VIEWS: (state, view) => { |
}) |
||||
state.visitedViews = state.visitedViews.filter(v => { |
}, |
||||
return v.meta.affix || v.path === view.path |
delVisitedView(view) { |
||||
}) |
return new Promise(resolve => { |
||||
}, |
for (const [i, v] of this.visitedViews.entries()) { |
||||
DEL_OTHERS_CACHED_VIEWS: (state, view) => { |
if (v.path === view.path) { |
||||
const index = state.cachedViews.indexOf(view.name) |
this.visitedViews.splice(i, 1) |
||||
if (index > -1) { |
break |
||||
state.cachedViews = state.cachedViews.slice(index, index + 1) |
} |
||||
} else { |
} |
||||
state.cachedViews = [] |
resolve([...this.visitedViews]) |
||||
} |
}) |
||||
}, |
}, |
||||
|
delCachedView(view) { |
||||
DEL_ALL_VISITED_VIEWS: state => { |
return new Promise(resolve => { |
||||
// keep affix tags
|
const index = this.cachedViews.indexOf(view.name) |
||||
const affixTags = state.visitedViews.filter(tag => tag.meta.affix) |
index > -1 && this.cachedViews.splice(index, 1) |
||||
state.visitedViews = affixTags |
resolve([...this.cachedViews]) |
||||
}, |
}) |
||||
DEL_ALL_CACHED_VIEWS: state => { |
}, |
||||
state.cachedViews = [] |
delOthersViews(view) { |
||||
}, |
return new Promise(resolve => { |
||||
|
this.delOthersVisitedViews(view) |
||||
UPDATE_VISITED_VIEW: (state, view) => { |
this.delOthersCachedViews(view) |
||||
for (let v of state.visitedViews) { |
resolve({ |
||||
if (v.path === view.path) { |
visitedViews: [...this.visitedViews], |
||||
v = Object.assign(v, view) |
cachedViews: [...this.cachedViews] |
||||
break |
}) |
||||
} |
}) |
||||
} |
}, |
||||
}, |
delOthersVisitedViews(view) { |
||||
|
return new Promise(resolve => { |
||||
DEL_RIGHT_VIEWS: (state, view) => { |
this.visitedViews = this.visitedViews.filter(v => { |
||||
const index = state.visitedViews.findIndex(v => v.path === view.path) |
return v.meta.affix || v.path === view.path |
||||
if (index === -1) { |
}) |
||||
return |
resolve([...this.visitedViews]) |
||||
} |
}) |
||||
state.visitedViews = state.visitedViews.filter((item, idx) => { |
}, |
||||
if (idx <= index || (item.meta && item.meta.affix)) { |
delOthersCachedViews(view) { |
||||
return true |
return new Promise(resolve => { |
||||
} |
const index = this.cachedViews.indexOf(view.name) |
||||
const i = state.cachedViews.indexOf(item.name) |
if (index > -1) { |
||||
if (i > -1) { |
this.cachedViews = this.cachedViews.slice(index, index + 1) |
||||
state.cachedViews.splice(i, 1) |
} else { |
||||
|
this.cachedViews = [] |
||||
|
} |
||||
|
resolve([...this.cachedViews]) |
||||
|
}) |
||||
|
}, |
||||
|
delAllViews(view) { |
||||
|
return new Promise(resolve => { |
||||
|
this.delAllVisitedViews(view) |
||||
|
this.delAllCachedViews(view) |
||||
|
resolve({ |
||||
|
visitedViews: [...this.visitedViews], |
||||
|
cachedViews: [...this.cachedViews] |
||||
|
}) |
||||
|
}) |
||||
|
}, |
||||
|
delAllVisitedViews(view) { |
||||
|
return new Promise(resolve => { |
||||
|
const affixTags = this.visitedViews.filter(tag => tag.meta.affix) |
||||
|
this.visitedViews = affixTags |
||||
|
resolve([...this.visitedViews]) |
||||
|
}) |
||||
|
}, |
||||
|
delAllCachedViews(view) { |
||||
|
return new Promise(resolve => { |
||||
|
this.cachedViews = [] |
||||
|
resolve([...this.cachedViews]) |
||||
|
}) |
||||
|
}, |
||||
|
updateVisitedView(view) { |
||||
|
for (let v of this.visitedViews) { |
||||
|
if (v.path === view.path) { |
||||
|
v = Object.assign(v, view) |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
delRightTags(view) { |
||||
|
return new Promise(resolve => { |
||||
|
const index = this.visitedViews.findIndex(v => v.path === view.path) |
||||
|
if (index === -1) { |
||||
|
return |
||||
|
} |
||||
|
this.visitedViews = this.visitedViews.filter((item, idx) => { |
||||
|
if (idx <= index || (item.meta && item.meta.affix)) { |
||||
|
return true |
||||
|
} |
||||
|
const i = this.cachedViews.indexOf(item.name) |
||||
|
if (i > -1) { |
||||
|
this.cachedViews.splice(i, 1) |
||||
|
} |
||||
|
return false |
||||
|
}) |
||||
|
resolve([...this.visitedViews]) |
||||
|
}) |
||||
|
}, |
||||
|
delLeftTags(view) { |
||||
|
const index = this.visitedViews.findIndex(v => v.path === view.path) |
||||
|
if (index === -1) { |
||||
|
return |
||||
|
} |
||||
|
this.visitedViews = this.visitedViews.filter((item, idx) => { |
||||
|
if (idx >= index || (item.meta && item.meta.affix)) { |
||||
|
return true |
||||
|
} |
||||
|
const i = this.cachedViews.indexOf(item.name) |
||||
|
if (i > -1) { |
||||
|
this.cachedViews.splice(i, 1) |
||||
|
} |
||||
|
return false |
||||
|
}) |
||||
} |
} |
||||
return false |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
DEL_LEFT_VIEWS: (state, view) => { |
|
||||
const index = state.visitedViews.findIndex(v => v.path === view.path) |
|
||||
if (index === -1) { |
|
||||
return |
|
||||
} |
} |
||||
state.visitedViews = state.visitedViews.filter((item, idx) => { |
}) |
||||
if (idx >= index || (item.meta && item.meta.affix)) { |
|
||||
return true |
|
||||
} |
|
||||
const i = state.cachedViews.indexOf(item.name) |
|
||||
if (i > -1) { |
|
||||
state.cachedViews.splice(i, 1) |
|
||||
} |
|
||||
return false |
|
||||
}) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
const actions = { |
|
||||
addView({ dispatch }, view) { |
|
||||
dispatch('addVisitedView', view) |
|
||||
dispatch('addCachedView', view) |
|
||||
}, |
|
||||
addVisitedView({ commit }, view) { |
|
||||
commit('ADD_VISITED_VIEW', view) |
|
||||
}, |
|
||||
addCachedView({ commit }, view) { |
|
||||
commit('ADD_CACHED_VIEW', view) |
|
||||
}, |
|
||||
|
|
||||
delView({ dispatch, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
dispatch('delVisitedView', view) |
|
||||
dispatch('delCachedView', view) |
|
||||
resolve({ |
|
||||
visitedViews: [...state.visitedViews], |
|
||||
cachedViews: [...state.cachedViews] |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
delVisitedView({ commit, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_VISITED_VIEW', view) |
|
||||
resolve([...state.visitedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
delCachedView({ commit, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_CACHED_VIEW', view) |
|
||||
resolve([...state.cachedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
delOthersViews({ dispatch, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
dispatch('delOthersVisitedViews', view) |
|
||||
dispatch('delOthersCachedViews', view) |
|
||||
resolve({ |
|
||||
visitedViews: [...state.visitedViews], |
|
||||
cachedViews: [...state.cachedViews] |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
delOthersVisitedViews({ commit, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_OTHERS_VISITED_VIEWS', view) |
|
||||
resolve([...state.visitedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
delOthersCachedViews({ commit, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_OTHERS_CACHED_VIEWS', view) |
|
||||
resolve([...state.cachedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
delAllViews({ dispatch, state }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
dispatch('delAllVisitedViews', view) |
|
||||
dispatch('delAllCachedViews', view) |
|
||||
resolve({ |
|
||||
visitedViews: [...state.visitedViews], |
|
||||
cachedViews: [...state.cachedViews] |
|
||||
}) |
|
||||
}) |
|
||||
}, |
|
||||
delAllVisitedViews({ commit, state }) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_ALL_VISITED_VIEWS') |
|
||||
resolve([...state.visitedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
delAllCachedViews({ commit, state }) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_ALL_CACHED_VIEWS') |
|
||||
resolve([...state.cachedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
updateVisitedView({ commit }, view) { |
|
||||
commit('UPDATE_VISITED_VIEW', view) |
|
||||
}, |
|
||||
|
|
||||
delRightTags({ commit }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_RIGHT_VIEWS', view) |
|
||||
resolve([...state.visitedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
delLeftTags({ commit }, view) { |
|
||||
return new Promise(resolve => { |
|
||||
commit('DEL_LEFT_VIEWS', view) |
|
||||
resolve([...state.visitedViews]) |
|
||||
}) |
|
||||
}, |
|
||||
} |
|
||||
|
|
||||
export default { |
export default useTagsViewStore |
||||
namespaced: true, |
|
||||
state, |
|
||||
mutations, |
|
||||
actions |
|
||||
} |
|
||||
|
|||||
@ -1,12 +1,14 @@ |
|||||
import store from '@/store' |
import store from '@/store' |
||||
import defaultSettings from '@/settings' |
import defaultSettings from '@/settings' |
||||
|
import useSettingsStore from '@/store/modules/settings' |
||||
|
|
||||
/** |
/** |
||||
* 动态修改标题 |
* 动态修改标题 |
||||
*/ |
*/ |
||||
export function useDynamicTitle() { |
export function useDynamicTitle() { |
||||
if (store.state.settings.dynamicTitle) { |
const settingsStore = useSettingsStore(); |
||||
document.title = store.state.settings.title + ' - ' + defaultSettings.title; |
if (settingsStore.dynamicTitle) { |
||||
|
document.title = settingsStore.title + ' - ' + defaultSettings.title; |
||||
} else { |
} else { |
||||
document.title = defaultSettings.title; |
document.title = defaultSettings.title; |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue