perf(tagsView):split to single modules
This commit is contained in:
		@@ -5,9 +5,7 @@ const app = {
 | 
			
		||||
    sidebar: {
 | 
			
		||||
      opened: !+Cookies.get('sidebarStatus')
 | 
			
		||||
    },
 | 
			
		||||
    language: Cookies.get('language') || 'zh',
 | 
			
		||||
    visitedViews: [],
 | 
			
		||||
    cachedViews: []
 | 
			
		||||
    language: Cookies.get('language') || 'zh'
 | 
			
		||||
  },
 | 
			
		||||
  mutations: {
 | 
			
		||||
    TOGGLE_SIDEBAR: state => {
 | 
			
		||||
@@ -21,32 +19,6 @@ const app = {
 | 
			
		||||
    SET_LANGUAGE: (state, language) => {
 | 
			
		||||
      state.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: {
 | 
			
		||||
@@ -55,15 +27,6 @@ const app = {
 | 
			
		||||
    },
 | 
			
		||||
    setLanguage({ commit }, 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])
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										47
									
								
								src/store/modules/tagsView.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/store/modules/tagsView.js
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
		Reference in New Issue
	
	Block a user