修复多标签页拖拽后关闭页面时对首页的处理
This commit is contained in:
@@ -183,17 +183,16 @@ export default {
|
|||||||
* @param {Object} payload { tagName: 要关闭的标签名字 }
|
* @param {Object} payload { tagName: 要关闭的标签名字 }
|
||||||
*/
|
*/
|
||||||
async close ({ state, commit, dispatch }, { tagName }) {
|
async close ({ state, commit, dispatch }, { tagName }) {
|
||||||
// 下个新的页面
|
// 预定下个新页面
|
||||||
let newPage = state.opened[0]
|
let newPage = {}
|
||||||
const isCurrent = state.current === tagName
|
const isCurrent = state.current === tagName
|
||||||
// 如果关闭的页面就是当前显示的页面
|
// 如果关闭的页面就是当前显示的页面
|
||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
// 去找一个新的页面
|
// 去找一个新的页面
|
||||||
let len = state.opened.length
|
let len = state.opened.length
|
||||||
for (let i = 1; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
if (state.opened[i].fullPath === tagName) {
|
if (state.opened[i].fullPath === tagName) {
|
||||||
if (i < len - 1) newPage = state.opened[i + 1]
|
newPage = i < len - 1 ? state.opened[i + 1] : state.opened[i - 1]
|
||||||
else newPage = state.opened[i - 1]
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +209,7 @@ export default {
|
|||||||
await dispatch('opened2db')
|
await dispatch('opened2db')
|
||||||
// 最后需要判断是否需要跳到首页
|
// 最后需要判断是否需要跳到首页
|
||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
const { name = '', params = {}, query = {} } = newPage
|
const { name = 'index', params = {}, query = {} } = newPage
|
||||||
let routerObj = {
|
let routerObj = {
|
||||||
name,
|
name,
|
||||||
params,
|
params,
|
||||||
@@ -233,7 +232,14 @@ export default {
|
|||||||
})
|
})
|
||||||
if (currentIndex > 0) {
|
if (currentIndex > 0) {
|
||||||
// 删除打开的页面 并在缓存设置中删除
|
// 删除打开的页面 并在缓存设置中删除
|
||||||
state.opened.splice(1, currentIndex - 1).forEach(({ name }) => commit('keepAliveRemove', name))
|
for (let i = state.opened.length - 1; i >= 0; i--) {
|
||||||
|
if (state.opened[i].name === 'index' || i >= currentIndex) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('keepAliveRemove', state.opened[i].name)
|
||||||
|
state.opened.splice(i, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
state.current = pageAim
|
state.current = pageAim
|
||||||
if (router.app.$route.fullPath !== pageAim) router.push(pageAim)
|
if (router.app.$route.fullPath !== pageAim) router.push(pageAim)
|
||||||
@@ -253,7 +259,14 @@ export default {
|
|||||||
if (page.fullPath === pageAim) currentIndex = index
|
if (page.fullPath === pageAim) currentIndex = index
|
||||||
})
|
})
|
||||||
// 删除打开的页面 并在缓存设置中删除
|
// 删除打开的页面 并在缓存设置中删除
|
||||||
state.opened.splice(currentIndex + 1).forEach(({ name }) => commit('keepAliveRemove', name))
|
for (let i = state.opened.length - 1; i >= 0; i--) {
|
||||||
|
if (state.opened[i].name === 'index' || currentIndex >= i) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('keepAliveRemove', state.opened[i].name)
|
||||||
|
state.opened.splice(i, 1)
|
||||||
|
}
|
||||||
// 设置当前的页面
|
// 设置当前的页面
|
||||||
state.current = pageAim
|
state.current = pageAim
|
||||||
if (router.app.$route.fullPath !== pageAim) router.push(pageAim)
|
if (router.app.$route.fullPath !== pageAim) router.push(pageAim)
|
||||||
@@ -273,11 +286,13 @@ export default {
|
|||||||
if (page.fullPath === pageAim) currentIndex = index
|
if (page.fullPath === pageAim) currentIndex = index
|
||||||
})
|
})
|
||||||
// 删除打开的页面数据 并更新缓存设置
|
// 删除打开的页面数据 并更新缓存设置
|
||||||
if (currentIndex === 0) {
|
for (let i = state.opened.length - 1; i >= 0; i--) {
|
||||||
state.opened.splice(1).forEach(({ name }) => commit('keepAliveRemove', name))
|
if (state.opened[i].name === 'index' || currentIndex === i) {
|
||||||
} else {
|
continue
|
||||||
state.opened.splice(currentIndex + 1).forEach(({ name }) => commit('keepAliveRemove', name))
|
}
|
||||||
state.opened.splice(1, currentIndex - 1).forEach(({ name }) => commit('keepAliveRemove', name))
|
|
||||||
|
commit('keepAliveRemove', state.opened[i].name)
|
||||||
|
state.opened.splice(i, 1)
|
||||||
}
|
}
|
||||||
// 设置新的页面
|
// 设置新的页面
|
||||||
state.current = pageAim
|
state.current = pageAim
|
||||||
@@ -292,7 +307,14 @@ export default {
|
|||||||
*/
|
*/
|
||||||
async closeAll ({ state, commit, dispatch }) {
|
async closeAll ({ state, commit, dispatch }) {
|
||||||
// 删除打开的页面 并在缓存设置中删除
|
// 删除打开的页面 并在缓存设置中删除
|
||||||
state.opened.splice(1).forEach(({ name }) => commit('keepAliveRemove', name))
|
for (let i = state.opened.length - 1; i >= 0; i--) {
|
||||||
|
if (state.opened[i].name === 'index') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('keepAliveRemove', state.opened[i].name)
|
||||||
|
state.opened.splice(i, 1)
|
||||||
|
}
|
||||||
// 持久化
|
// 持久化
|
||||||
await dispatch('opened2db')
|
await dispatch('opened2db')
|
||||||
// 关闭所有的标签页后需要判断一次现在是不是在首页
|
// 关闭所有的标签页后需要判断一次现在是不是在首页
|
||||||
|
|||||||
Reference in New Issue
Block a user