From e3cbf4ad90130ba3637f267bad0058d2824b2a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Mon, 30 Sep 2019 16:38:18 +0800 Subject: [PATCH 1/6] fix[example]: fixed create.vue cache error https://github.com/PanJiaChen/vue-element-admin/issues/2608 --- src/views/example/components/ArticleDetail.vue | 2 -- src/views/example/create.vue | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) 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 } } From 9c723c66182308995f090621f86cd263c856d6fa Mon Sep 17 00:00:00 2001 From: monkeycf <41945134+monkeycf@users.noreply.github.com> Date: Tue, 8 Oct 2019 17:54:47 +0800 Subject: [PATCH 2/6] perf[utils.js]: perf parseTime function (#2625) --- src/utils/index.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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 } From 0343988f3de2a181bfbee43b1a1400f68f9ffa3b Mon Sep 17 00:00:00 2001 From: monkeycf <41945134+monkeycf@users.noreply.github.com> Date: Tue, 8 Oct 2019 18:15:22 +0800 Subject: [PATCH 3/6] perf[tagsView]: pref DEL_CACHED_VIEW and DEL_OTHERS_CACHED_VIEWS function (#2626) --- src/store/modules/tagsView.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index 3e2c1703..f94546ce 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,13 +38,8 @@ 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) + index > -1 && (state.cachedViews = state.cachedViews.slice(index, index + 1)) }, DEL_ALL_VISITED_VIEWS: state => { From f266713daf5ae75d3da792aea129d35905b763da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Tue, 8 Oct 2019 18:20:11 +0800 Subject: [PATCH 4/6] fix[tagsView]: fixed DEL_OTHERS_CACHED_VIEWS bug --- src/store/modules/tagsView.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index f94546ce..57e72421 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -39,7 +39,12 @@ const mutations = { }, DEL_OTHERS_CACHED_VIEWS: (state, view) => { const index = state.cachedViews.indexOf(view.name) - index > -1 && (state.cachedViews = state.cachedViews.slice(index, index + 1)) + if (index > -1) { + state.cachedViews = state.cachedViews.slice(index, index + 1) + } else { + // if index = -1, there is no cached tags + state.cachedViews = [] + } }, DEL_ALL_VISITED_VIEWS: state => { From b4cdf528ba786060709227f0471640d72298a27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Tue, 8 Oct 2019 20:38:19 +0800 Subject: [PATCH 5/6] fix[logout]: empty tagsview when logout (#2632) --- src/store/modules/user.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) From 197948dc4414db87df36419022aaf0502d503a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Tue, 8 Oct 2019 21:20:34 +0800 Subject: [PATCH 6/6] fix[TagsView]: fixed toLastView bug (#2634) --- src/layout/components/TagsView/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.