diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue index 24a92f1d..e5aa91a6 100644 --- a/src/layout/components/TagsView/index.vue +++ b/src/layout/components/TagsView/index.vue @@ -155,7 +155,7 @@ export default { toLastView(visitedViews, view) { const latestView = visitedViews.slice(-1)[0] if (latestView) { - this.$router.push(latestView) + this.$router.push(latestView.fullPath) } else { // now the default is to redirect to the home page if there is no tags-view, // you can adjust it according to your needs. diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index 3e2c1703..57e72421 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -28,13 +28,8 @@ const mutations = { } }, DEL_CACHED_VIEW: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews.splice(index, 1) - break - } - } + const index = state.cachedViews.indexOf(view.name) + index > -1 && state.cachedViews.splice(index, 1) }, DEL_OTHERS_VISITED_VIEWS: (state, view) => { @@ -43,12 +38,12 @@ const mutations = { }) }, DEL_OTHERS_CACHED_VIEWS: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews = state.cachedViews.slice(index, index + 1) - break - } + const index = state.cachedViews.indexOf(view.name) + if (index > -1) { + state.cachedViews = state.cachedViews.slice(index, index + 1) + } else { + // if index = -1, there is no cached tags + state.cachedViews = [] } }, diff --git a/src/store/modules/user.js b/src/store/modules/user.js index dbc29003..1391fa4a 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -73,13 +73,18 @@ const actions = { }, // user logout - logout({ commit, state }) { + logout({ commit, state, dispatch }) { return new Promise((resolve, reject) => { logout(state.token).then(() => { commit('SET_TOKEN', '') commit('SET_ROLES', []) removeToken() resetRouter() + + // reset visited views and cached views + // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485 + dispatch('tagsView/delAllViews', null, { root: true }) + resolve() }).catch(error => { reject(error) diff --git a/src/utils/index.js b/src/utils/index.js index ffb55260..2684e3c2 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -6,7 +6,7 @@ * Parse the time to string * @param {(Object|string|number)} time * @param {string} cFormat - * @returns {string} + * @returns {string | null} */ export function parseTime(time, cFormat) { if (arguments.length === 0) { @@ -34,14 +34,11 @@ export function parseTime(time, cFormat) { s: date.getSeconds(), a: date.getDay() } - const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { - let value = formatObj[key] + const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => { + const value = formatObj[key] // Note: getDay() returns 0 on Sunday if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } - if (result.length > 0 && value < 10) { - value = '0' + value - } - return value || 0 + return value.toString().padStart(2, '0') }) return time_str } diff --git a/src/views/example/components/ArticleDetail.vue b/src/views/example/components/ArticleDetail.vue index ef0f1df9..8aa97339 100644 --- a/src/views/example/components/ArticleDetail.vue +++ b/src/views/example/components/ArticleDetail.vue @@ -170,8 +170,6 @@ export default { if (this.isEdit) { const id = this.$route.params && this.$route.params.id this.fetchData(id) - } else { - this.postForm = Object.assign({}, defaultForm) } // Why need to make a copy of this.$route here? diff --git a/src/views/example/create.vue b/src/views/example/create.vue index 4d3a24b5..f28ce287 100644 --- a/src/views/example/create.vue +++ b/src/views/example/create.vue @@ -6,7 +6,7 @@ import ArticleDetail from './components/ArticleDetail' export default { - name: 'CreateForm', + name: 'CreateArticle', components: { ArticleDetail } }