From 27f3c15f763b21de70ebfa7f245c57a9b85c99ff Mon Sep 17 00:00:00 2001 From: huzhushan Date: Fri, 9 Apr 2021 16:47:31 +0800 Subject: [PATCH] update --- .../Tagsbar/hooks/useContextMenu.js | 30 ++++--- src/router/modules/error.js | 23 +++++- src/router/modules/redirect.js | 9 ++- src/store/modules/tags.js | 78 +++++-------------- src/views/error/index.vue | 25 +----- 5 files changed, 67 insertions(+), 98 deletions(-) diff --git a/src/layout/components/Tagsbar/hooks/useContextMenu.js b/src/layout/components/Tagsbar/hooks/useContextMenu.js index b36d072..6ee3d72 100644 --- a/src/layout/components/Tagsbar/hooks/useContextMenu.js +++ b/src/layout/components/Tagsbar/hooks/useContextMenu.js @@ -23,12 +23,11 @@ export const useContextMenu = (tagList) => { state.visible = false; }, refreshSelectedTag (tag) { - store.dispatch("tags/delCacheList", tag).then(() => { - const { fullPath } = tag; - nextTick(() => { - router.replace({ - path: "/redirect" + fullPath, - }); + store.dispatch("tags/delCacheList", tag) + const { fullPath } = tag; + nextTick(() => { + router.replace({ + path: "/redirect" + fullPath, }); }); }, @@ -38,21 +37,18 @@ export const useContextMenu = (tagList) => { const closedTagIndex = tagList.value.findIndex( (item) => item.fullPath === tag.fullPath ); - store.dispatch("tags/delTag", tag).then(() => { - if (isActive(tag)) { - toLastTag(closedTagIndex - 1); - } - }); + store.dispatch("tags/delTag", tag) + if (isActive(tag)) { + toLastTag(closedTagIndex - 1); + } }, closeOtherTags () { - store.dispatch("tags/delOtherTags", state.selectedTag).then(() => { - router.push(state.selectedTag); - }); + store.dispatch("tags/delOtherTags", state.selectedTag) + router.push(state.selectedTag); }, closeAllTags () { - store.dispatch("tags/delAllTags").then(() => { - router.push("/"); - }); + store.dispatch("tags/delAllTags") + router.push("/"); } }) diff --git a/src/router/modules/error.js b/src/router/modules/error.js index 0238cd6..76f9d0a 100644 --- a/src/router/modules/error.js +++ b/src/router/modules/error.js @@ -1,7 +1,19 @@ +import store from '@/store' + +const checkUserinfo = (code) => { + const userinfo = store.state.account.userinfo + if (!!userinfo) { + return `/error/${code}` + } + return true +} + const Layout = () => import('@/layout/index.vue') const Error = () => import("@/views/error/index.vue"); + + export default [ { path: '/error', @@ -42,6 +54,9 @@ export default [ component: Error, props: { error: '403' + }, + beforeEnter () { + return checkUserinfo('403') } }, { @@ -50,14 +65,20 @@ export default [ component: Error, props: { error: '500' + }, + beforeEnter () { + return checkUserinfo('500') } }, { - path: '/:pathMatch(.*)*', + path: '/:pathMatch(.*)', name: 'not-found', component: Error, props: { error: '404' + }, + beforeEnter () { + return checkUserinfo('404') } }, ] \ No newline at end of file diff --git a/src/router/modules/redirect.js b/src/router/modules/redirect.js index 08d5792..c0ec68e 100644 --- a/src/router/modules/redirect.js +++ b/src/router/modules/redirect.js @@ -1,8 +1,15 @@ +const Layout = () => import('@/layout/index.vue') const Redirect = () => import("@/views/redirect/index.vue"); export default [ { path: '/redirect/:path(.*)', - component: Redirect, + component: Layout, + children: [ + { + path: '', + component: Redirect, + } + ] } ] \ No newline at end of file diff --git a/src/store/modules/tags.js b/src/store/modules/tags.js index 6d26b2a..3344a40 100644 --- a/src/store/modules/tags.js +++ b/src/store/modules/tags.js @@ -87,73 +87,37 @@ const actions = { commit('ADD_CACHE_LIST', tag) }, - delTag ({ dispatch, state }, tag) { - return new Promise(resolve => { - dispatch('delTagList', tag) - dispatch('delCacheList', tag) - resolve({ - tagList: [...state.tagList], - cacheList: [...state.cacheList] - }) - }) + delTag ({ dispatch }, tag) { + dispatch('delTagList', tag) + dispatch('delCacheList', tag) }, - delTagList ({ commit, state }, tag) { - return new Promise(resolve => { - commit('DEL_TAG_LIST', tag) - resolve([...state.tagList]) - }) + delTagList ({ commit }, tag) { + commit('DEL_TAG_LIST', tag) }, - delCacheList ({ commit, state }, tag) { - return new Promise(resolve => { - commit('DEL_CACHE_LIST', tag) - resolve([...state.cacheList]) - }) + delCacheList ({ commit }, tag) { + commit('DEL_CACHE_LIST', tag) }, - delOtherTags ({ dispatch, state }, tag) { - return new Promise(resolve => { - dispatch('delOtherTagList', tag) - dispatch('delOtherCacheList', tag) - resolve({ - tagList: [...state.tagList], - cacheList: [...state.cacheList] - }) - }) + delOtherTags ({ dispatch }, tag) { + dispatch('delOtherTagList', tag) + dispatch('delOtherCacheList', tag) }, - delOtherTagList ({ commit, state }, tag) { - return new Promise(resolve => { - commit('DEL_OTHER_TAG_LIST', tag) - resolve([...state.tagList]) - }) + delOtherTagList ({ commit }, tag) { + commit('DEL_OTHER_TAG_LIST', tag) }, - delOtherCacheList ({ commit, state }, tag) { - return new Promise(resolve => { - commit('DEL_OTHER_CACHE_LIST', tag) - resolve([...state.cacheList]) - }) + delOtherCacheList ({ commit }, tag) { + commit('DEL_OTHER_CACHE_LIST', tag) }, - delAllTags ({ dispatch, state }) { - return new Promise(resolve => { - dispatch('delAllTagList') - dispatch('delAllCacheList') - resolve({ - tagList: [...state.tagList], - cacheList: [...state.cacheList] - }) - }) + delAllTags ({ dispatch }) { + dispatch('delAllTagList') + dispatch('delAllCacheList') }, - delAllTagList ({ commit, state }) { - return new Promise(resolve => { - commit('DEL_ALL_TAG_LIST') - resolve([...state.tagList]) - }) + delAllTagList ({ commit }) { + commit('DEL_ALL_TAG_LIST') }, - delAllCacheList ({ commit, state }) { - return new Promise(resolve => { - commit('DEL_ALL_CACHE_LIST') - resolve([...state.cacheList]) - }) + delAllCacheList ({ commit }) { + commit('DEL_ALL_CACHE_LIST') }, updateTagList ({ commit }, tag) { diff --git a/src/views/error/index.vue b/src/views/error/index.vue index 516aab5..cd13d4c 100644 --- a/src/views/error/index.vue +++ b/src/views/error/index.vue @@ -2,48 +2,29 @@
返回首页 -