From da1da1d4d5dfdc79f305523c33a1930427851bee Mon Sep 17 00:00:00 2001 From: huzhushan Date: Thu, 29 Apr 2021 11:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=87=E7=AD=BE=E6=A0=8F?= =?UTF-8?q?=E4=B8=AD=EF=BC=9A1.=E5=9B=BA=E5=AE=9A=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E7=9A=84=E4=BD=8D=E7=BD=AE=EF=BC=9B2.vuex=E4=B8=AD=E7=9A=84act?= =?UTF-8?q?ions=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tagsbar/hooks/useContextMenu.js | 4 +- .../components/Tagsbar/hooks/useTags.js | 5 +- src/router/modules/test.js | 2 +- src/store/modules/tags.js | 68 ++++++------------- 4 files changed, 28 insertions(+), 51 deletions(-) diff --git a/src/layout/components/Tagsbar/hooks/useContextMenu.js b/src/layout/components/Tagsbar/hooks/useContextMenu.js index 18d7b34..b0384a9 100644 --- a/src/layout/components/Tagsbar/hooks/useContextMenu.js +++ b/src/layout/components/Tagsbar/hooks/useContextMenu.js @@ -26,7 +26,7 @@ * @version: * @Date: 2021-04-20 11:06:21 * @LastEditors: huzhushan@126.com - * @LastEditTime: 2021-04-21 12:47:01 + * @LastEditTime: 2021-04-29 10:52:41 * @Author: huzhushan@126.com * @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin @@ -58,7 +58,7 @@ export const useContextMenu = tagList => { state.visible = false }, refreshSelectedTag(tag) { - store.dispatch('tags/delCacheList', tag) + store.commit('tags/DEL_CACHE_LIST', tag) const { fullPath } = tag nextTick(() => { router.replace({ diff --git a/src/layout/components/Tagsbar/hooks/useTags.js b/src/layout/components/Tagsbar/hooks/useTags.js index 2a386f1..9217c42 100644 --- a/src/layout/components/Tagsbar/hooks/useTags.js +++ b/src/layout/components/Tagsbar/hooks/useTags.js @@ -24,7 +24,7 @@ * @version: * @Date: 2021-04-20 11:06:21 * @LastEditors: huzhushan@126.com - * @LastEditTime: 2021-04-21 12:47:12 + * @LastEditTime: 2021-04-29 11:13:55 * @Author: huzhushan@126.com * @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin @@ -63,6 +63,7 @@ export const useTags = () => { ) const filterAffixTags = routes => { + console.log(222, routes) return routes.filter(route => isAffix(route)) } @@ -71,7 +72,7 @@ export const useTags = () => { for (const tag of affixTags) { if (tag.name) { - store.dispatch('tags/addTagList', tag) + store.dispatch('tags/addTag', tag) } } } diff --git a/src/router/modules/test.js b/src/router/modules/test.js index 6192c45..60ce8e0 100644 --- a/src/router/modules/test.js +++ b/src/router/modules/test.js @@ -3,7 +3,7 @@ * @version: * @Date: 2021-04-21 09:18:32 * @LastEditors: huzhushan@126.com - * @LastEditTime: 2021-04-28 16:49:53 + * @LastEditTime: 2021-04-29 11:20:14 * @Author: huzhushan@126.com * @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin diff --git a/src/store/modules/tags.js b/src/store/modules/tags.js index c461334..015bab5 100644 --- a/src/store/modules/tags.js +++ b/src/store/modules/tags.js @@ -3,7 +3,7 @@ * @version: * @Date: 2021-04-20 11:06:21 * @LastEditors: huzhushan@126.com - * @LastEditTime: 2021-04-28 17:40:11 + * @LastEditTime: 2021-04-29 11:19:20 * @Author: huzhushan@126.com * @HomePage: https://huzhushan.gitee.io/vue3-element-admin * @Github: https://github.com/huzhushan/vue3-element-admin @@ -16,25 +16,30 @@ const TAGLIST = 'VEA-TAGLIST' const state = { tagList: getItem(TAGLIST) || [], cacheList: [], - activePosition: 0, + activePosition: -1, } const mutations = { ADD_TAG_LIST: (state, { path, fullPath, name, meta, params, query }) => { if (state.tagList.some(v => v.path === path)) return false - state.tagList.splice( - state.activePosition + 1, - 0, - Object.assign( - {}, - { path, fullPath, name, meta, params, query }, - { - title: meta.title || '未命名', - fullPath: fullPath || path, - } - ) + const target = Object.assign( + {}, + { path, fullPath, name, meta, params, query }, + { + title: meta.title || '未命名', + fullPath: fullPath || path, + } ) + if (state.activePosition === -1) { + if (name === 'home') { + state.tagList.unshift(target) + } else { + state.tagList.push(target) + } + } else { + state.tagList.splice(state.activePosition + 1, 0, target) + } // 保存到localStorage setItem(TAGLIST, state.tagList) @@ -107,55 +112,26 @@ const actions = { saveActivePosition({ commit }, index) { commit('SAVE_ACTIVE_POSITION', index) }, - addTag({ dispatch }, tag) { - dispatch('addTagList', tag) - dispatch('addCacheList', tag) - }, - addTagList({ commit }, tag) { + addTag({ commit }, tag) { commit('ADD_TAG_LIST', tag) - }, - addCacheList({ commit }, tag) { commit('ADD_CACHE_LIST', tag) }, - - delTag({ dispatch }, tag) { - dispatch('delTagList', tag) - dispatch('delCacheList', tag) - }, - delTagList({ commit }, tag) { + delTag({ commit }, tag) { commit('DEL_TAG_LIST', tag) - }, - delCacheList({ commit }, tag) { commit('DEL_CACHE_LIST', tag) }, - - delOtherTags({ dispatch }, tag) { - dispatch('delOtherTagList', tag) - dispatch('delOtherCacheList', tag) - }, - delOtherTagList({ commit }, tag) { + delOtherTags({ commit }, tag) { commit('DEL_OTHER_TAG_LIST', tag) - }, - delOtherCacheList({ commit }, tag) { commit('DEL_OTHER_CACHE_LIST', tag) }, - delSomeTags({ commit }, tags) { commit('DEL_SOME_TAG_LIST', tags) commit('DEL_SOME_CACHE_LIST', tags) }, - - delAllTags({ dispatch }) { - dispatch('delAllTagList') - dispatch('delAllCacheList') - }, - delAllTagList({ commit }) { + delAllTags({ commit }) { commit('DEL_ALL_TAG_LIST') - }, - delAllCacheList({ commit }) { commit('DEL_ALL_CACHE_LIST') }, - updateTagList({ commit }, { path, fullPath, name, meta, params, query }) { commit('UPDATE_TAG_LIST', { path, fullPath, name, meta, params, query }) },