tab切换路由有缓存
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
:default-active="menuActiveName || 'home'"
|
:default-active="menuActiveName || 'home'"
|
||||||
:collapse="sidebarFold"
|
:collapse="sidebarFold"
|
||||||
:collapseTransition="false"
|
:collapseTransition="false"
|
||||||
class="site-sidebar__menu">
|
class="site-sidebar__menu"
|
||||||
|
>
|
||||||
<el-menu-item index="home" @click="$router.push({ name: 'home' })">
|
<el-menu-item index="home" @click="$router.push({ name: 'home' })">
|
||||||
<icon-svg name="shouye" class="site-sidebar__menu-icon"></icon-svg>
|
<icon-svg name="shouye" class="site-sidebar__menu-icon"></icon-svg>
|
||||||
<span slot="title">首页</span>
|
<span slot="title">首页</span>
|
||||||
@@ -28,7 +29,8 @@
|
|||||||
v-for="menu in menuList"
|
v-for="menu in menuList"
|
||||||
:key="menu.menuId"
|
:key="menu.menuId"
|
||||||
:menu="menu"
|
:menu="menu"
|
||||||
:dynamicMenuRoutes="dynamicMenuRoutes">
|
:dynamicMenuRoutes="dynamicMenuRoutes"
|
||||||
|
>
|
||||||
</sub-menu>
|
</sub-menu>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
</div>
|
</div>
|
||||||
@@ -36,77 +38,114 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import SubMenu from './main-sidebar-sub-menu'
|
import SubMenu from "./main-sidebar-sub-menu";
|
||||||
import { isURL } from '@/utils/validate'
|
import { isURL } from "@/utils/validate";
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data() {
|
||||||
return {
|
return {
|
||||||
dynamicMenuRoutes: []
|
dynamicMenuRoutes: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
SubMenu
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sidebarLayoutSkin: {
|
||||||
|
get() {
|
||||||
|
return this.$store.state.common.sidebarLayoutSkin;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
sidebarFold: {
|
||||||
SubMenu
|
get() {
|
||||||
},
|
return this.$store.state.common.sidebarFold;
|
||||||
computed: {
|
|
||||||
sidebarLayoutSkin: {
|
|
||||||
get () { return this.$store.state.common.sidebarLayoutSkin }
|
|
||||||
},
|
|
||||||
sidebarFold: {
|
|
||||||
get () { return this.$store.state.common.sidebarFold }
|
|
||||||
},
|
|
||||||
menuList: {
|
|
||||||
get () { return this.$store.state.common.menuList },
|
|
||||||
set (val) { this.$store.commit('common/updateMenuList', val) }
|
|
||||||
},
|
|
||||||
menuActiveName: {
|
|
||||||
get () { return this.$store.state.common.menuActiveName },
|
|
||||||
set (val) { this.$store.commit('common/updateMenuActiveName', val) }
|
|
||||||
},
|
|
||||||
mainTabs: {
|
|
||||||
get () { return this.$store.state.common.mainTabs },
|
|
||||||
set (val) { this.$store.commit('common/updateMainTabs', val) }
|
|
||||||
},
|
|
||||||
mainTabsActiveName: {
|
|
||||||
get () { return this.$store.state.common.mainTabsActiveName },
|
|
||||||
set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
menuList: {
|
||||||
$route: 'routeHandle'
|
get() {
|
||||||
|
return this.$store.state.common.menuList;
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$store.commit("common/updateMenuList", val);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
created () {
|
menuActiveName: {
|
||||||
this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]')
|
get() {
|
||||||
this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]')
|
return this.$store.state.common.menuActiveName;
|
||||||
this.routeHandle(this.$route)
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$store.commit("common/updateMenuActiveName", val);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
mainTabs: {
|
||||||
// 路由操作
|
get() {
|
||||||
routeHandle (route) {
|
return this.$store.state.common.mainTabs;
|
||||||
if (route.meta.isTab) {
|
},
|
||||||
// tab选中, 不存在先添加
|
set(val) {
|
||||||
var tab = this.mainTabs.filter(item => item.name === route.name)[0]
|
this.$store.commit("common/updateMainTabs", val);
|
||||||
if (!tab) {
|
}
|
||||||
if (route.meta.isDynamic) {
|
},
|
||||||
route = this.dynamicMenuRoutes.filter(item => item.name === route.name)[0]
|
mainTabsActiveName: {
|
||||||
if (!route) {
|
get() {
|
||||||
return console.error('未能找到可用标签页!')
|
return this.$store.state.common.mainTabsActiveName;
|
||||||
}
|
},
|
||||||
|
set(val) {
|
||||||
|
this.$store.commit("common/updateMainTabsActiveName", val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
$route: "routeHandle"
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.menuList = JSON.parse(sessionStorage.getItem("menuList") || "[]");
|
||||||
|
this.dynamicMenuRoutes = JSON.parse(
|
||||||
|
sessionStorage.getItem("dynamicMenuRoutes") || "[]"
|
||||||
|
);
|
||||||
|
this.routeHandle(this.$route);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 路由操作
|
||||||
|
routeHandle(route) {
|
||||||
|
console.log("route at line 12384:", route);
|
||||||
|
if (route.meta.isTab) {
|
||||||
|
// tab选中, 不存在先添加
|
||||||
|
var tab = this.mainTabs.filter(item => item.name === route.name)[0];
|
||||||
|
var tabIndex = this.mainTabs.findIndex(item => item.name === route.name);
|
||||||
|
console.log('tabIndex at line 113:', tabIndex)
|
||||||
|
if (!tab) {
|
||||||
|
if (route.meta.isDynamic) {
|
||||||
|
route = this.dynamicMenuRoutes.filter(
|
||||||
|
item => item.name === route.name
|
||||||
|
)[0];
|
||||||
|
if (!route) {
|
||||||
|
return console.error("未能找到可用标签页!");
|
||||||
}
|
}
|
||||||
tab = {
|
|
||||||
menuId: route.meta.menuId || route.name,
|
|
||||||
name: route.name,
|
|
||||||
title: route.meta.title,
|
|
||||||
type: isURL(route.meta.iframeUrl) ? 'iframe' : 'module',
|
|
||||||
iframeUrl: route.meta.iframeUrl || '',
|
|
||||||
params: route.params,
|
|
||||||
query: route.query
|
|
||||||
}
|
|
||||||
this.mainTabs = this.mainTabs.concat(tab)
|
|
||||||
}
|
}
|
||||||
this.menuActiveName = tab.menuId + ''
|
tab = {
|
||||||
this.mainTabsActiveName = tab.name
|
menuId: route.meta.menuId || route.name,
|
||||||
|
name: route.name,
|
||||||
|
title: route.meta.title,
|
||||||
|
type: isURL(route.meta.iframeUrl) ? "iframe" : "module",
|
||||||
|
iframeUrl: route.meta.iframeUrl || "",
|
||||||
|
params: route.params,
|
||||||
|
query: route.query
|
||||||
|
};
|
||||||
|
this.mainTabs = this.mainTabs.concat(tab);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// this.mainTabs = this.mainTabs.concat({
|
||||||
|
// ...tab,
|
||||||
|
// params: route.params,
|
||||||
|
// query: route.query
|
||||||
|
// });
|
||||||
|
this.mainTabs[tabIndex].query=route.query
|
||||||
|
this.mainTabs[tabIndex].params=route.query
|
||||||
|
console.log("at line 107:", "存在先添加",tab);
|
||||||
}
|
}
|
||||||
|
this.menuActiveName = tab.menuId + "";
|
||||||
|
this.mainTabsActiveName = tab.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user