perf(tagsView):split to single modules
This commit is contained in:
parent
b7939165d1
commit
ca75f7bcbc
|
@ -1,8 +1,8 @@
|
||||||
const getters = {
|
const getters = {
|
||||||
sidebar: state => state.app.sidebar,
|
sidebar: state => state.app.sidebar,
|
||||||
language: state => state.app.language,
|
language: state => state.app.language,
|
||||||
visitedViews: state => state.app.visitedViews,
|
visitedViews: state => state.tagsView.visitedViews,
|
||||||
cachedViews: state => state.app.cachedViews,
|
cachedViews: state => state.tagsView.cachedViews,
|
||||||
token: state => state.user.token,
|
token: state => state.user.token,
|
||||||
avatar: state => state.user.avatar,
|
avatar: state => state.user.avatar,
|
||||||
name: state => state.user.name,
|
name: state => state.user.name,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import app from './modules/app'
|
import app from './modules/app'
|
||||||
import user from './modules/user'
|
|
||||||
import permission from './modules/permission'
|
import permission from './modules/permission'
|
||||||
|
import tagsView from './modules/tagsView'
|
||||||
|
import user from './modules/user'
|
||||||
import getters from './getters'
|
import getters from './getters'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
@ -10,8 +11,9 @@ Vue.use(Vuex)
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
app,
|
app,
|
||||||
user,
|
permission,
|
||||||
permission
|
tagsView,
|
||||||
|
user
|
||||||
},
|
},
|
||||||
getters
|
getters
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,9 +5,7 @@ const app = {
|
||||||
sidebar: {
|
sidebar: {
|
||||||
opened: !+Cookies.get('sidebarStatus')
|
opened: !+Cookies.get('sidebarStatus')
|
||||||
},
|
},
|
||||||
language: Cookies.get('language') || 'zh',
|
language: Cookies.get('language') || 'zh'
|
||||||
visitedViews: [],
|
|
||||||
cachedViews: []
|
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
TOGGLE_SIDEBAR: state => {
|
TOGGLE_SIDEBAR: state => {
|
||||||
|
@ -21,32 +19,6 @@ const app = {
|
||||||
SET_LANGUAGE: (state, language) => {
|
SET_LANGUAGE: (state, language) => {
|
||||||
state.language = language
|
state.language = language
|
||||||
Cookies.set('language', language)
|
Cookies.set('language', language)
|
||||||
},
|
|
||||||
ADD_VISITED_VIEWS: (state, view) => {
|
|
||||||
if (state.visitedViews.some(v => v.path === view.path)) return
|
|
||||||
state.visitedViews.push({
|
|
||||||
name: view.name,
|
|
||||||
path: view.path,
|
|
||||||
title: view.meta.title || 'no-name'
|
|
||||||
})
|
|
||||||
if (!view.meta.noCache) {
|
|
||||||
state.cachedViews.push(view.name)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DEL_VISITED_VIEWS: (state, view) => {
|
|
||||||
for (const [i, v] of state.visitedViews.entries()) {
|
|
||||||
if (v.path === view.path) {
|
|
||||||
state.visitedViews.splice(i, 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const i of state.cachedViews) {
|
|
||||||
if (i === view.name) {
|
|
||||||
const index = state.cachedViews.indexOf(i)
|
|
||||||
state.cachedViews.splice(index, 1)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -55,15 +27,6 @@ const app = {
|
||||||
},
|
},
|
||||||
setLanguage({ commit }, language) {
|
setLanguage({ commit }, language) {
|
||||||
commit('SET_LANGUAGE', language)
|
commit('SET_LANGUAGE', language)
|
||||||
},
|
|
||||||
addVisitedViews({ commit }, view) {
|
|
||||||
commit('ADD_VISITED_VIEWS', view)
|
|
||||||
},
|
|
||||||
delVisitedViews({ commit, state }, view) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
commit('DEL_VISITED_VIEWS', view)
|
|
||||||
resolve([...state.visitedViews])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
const tagsView = {
|
||||||
|
state: {
|
||||||
|
visitedViews: [],
|
||||||
|
cachedViews: []
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
ADD_VISITED_VIEWS: (state, view) => {
|
||||||
|
if (state.visitedViews.some(v => v.path === view.path)) return
|
||||||
|
state.visitedViews.push({
|
||||||
|
name: view.name,
|
||||||
|
path: view.path,
|
||||||
|
title: view.meta.title || 'no-name'
|
||||||
|
})
|
||||||
|
if (!view.meta.noCache) {
|
||||||
|
state.cachedViews.push(view.name)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DEL_VISITED_VIEWS: (state, view) => {
|
||||||
|
for (const [i, v] of state.visitedViews.entries()) {
|
||||||
|
if (v.path === view.path) {
|
||||||
|
state.visitedViews.splice(i, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const i of state.cachedViews) {
|
||||||
|
if (i === view.name) {
|
||||||
|
const index = state.cachedViews.indexOf(i)
|
||||||
|
state.cachedViews.splice(index, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
addVisitedViews({ commit }, view) {
|
||||||
|
commit('ADD_VISITED_VIEWS', view)
|
||||||
|
},
|
||||||
|
delVisitedViews({ commit, state }, view) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
commit('DEL_VISITED_VIEWS', view)
|
||||||
|
resolve([...state.visitedViews])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default tagsView
|
|
@ -11,7 +11,7 @@ export default {
|
||||||
name: 'TableMain',
|
name: 'TableMain',
|
||||||
computed: {
|
computed: {
|
||||||
cachedViews() {
|
cachedViews() {
|
||||||
return this.$store.state.app.cachedViews
|
return this.$store.state.tagsView.cachedViews
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ export default {
|
||||||
name: 'AppMain',
|
name: 'AppMain',
|
||||||
computed: {
|
computed: {
|
||||||
cachedViews() {
|
cachedViews() {
|
||||||
return this.$store.state.app.cachedViews
|
// console.log(this.$store.state.tagsView.cachedViews)
|
||||||
|
return this.$store.state.tagsView.cachedViews
|
||||||
}
|
}
|
||||||
// key() {
|
// key() {
|
||||||
// return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
|
// return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default {
|
||||||
components: { ScrollPane },
|
components: { ScrollPane },
|
||||||
computed: {
|
computed: {
|
||||||
visitedViews() {
|
visitedViews() {
|
||||||
return this.$store.state.app.visitedViews
|
return this.$store.state.tagsView.visitedViews
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
Loading…
Reference in New Issue