lazy路由加载

This commit is contained in:
王铜 2020-11-30 12:01:35 +08:00
parent 9dbeeeec35
commit 1f09e43e44
2 changed files with 76 additions and 58 deletions

View File

@ -1,27 +1,29 @@
<template> <template>
<a-layout> <a-layout>
<a-layout-header style="height: 110px;"> <a-layout-header style="height: 110px">
<a-row> <a-row>
<a-col :span="12" style="color:white;"> <a-col :span="12" style="color: white">
<span class="w-title">水质监测平台</span> <span class="w-title">水质监测平台</span>
</a-col> </a-col>
<a-col :span="2" :offset="10"> <a-col :span="2" :offset="10">
<a-popover :title="username" trigger="hover" placement="bottom"> <a-popover :title="username" trigger="hover" placement="bottom">
<template slot="content"> <template slot="content">
<p v-if="!isAnyone" style="cursor: pointer;" @click="changePasswd"> <p v-if="!isAnyone" style="cursor: pointer" @click="changePasswd">
更改密码 更改密码
</p> </p>
<p style="cursor: pointer;" @click="logout"> <p style="cursor: pointer" @click="logout">登出</p>
登出
</p>
</template> </template>
<a-avatar :size="48" icon="user" /> <a-avatar :size="48" icon="user" />
</a-popover> </a-popover>
</a-col> </a-col>
</a-row> </a-row>
<a-row> <a-row>
<a-menu v-model="current" mode="horizontal" theme="dark" @click="handleMenuClick"> <a-menu
v-model="current"
mode="horizontal"
theme="dark"
@click="handleMenuClick"
>
<a-menu-item key="map-layout"> <a-menu-item key="map-layout">
<icon-font type="wt-iconmap" />主页 <icon-font type="wt-iconmap" />主页
</a-menu-item> </a-menu-item>
@ -29,7 +31,9 @@
<span slot="title" class="submenu-title-wrapper" <span slot="title" class="submenu-title-wrapper"
><icon-font type="wt-iconsearch" />数据查询</span ><icon-font type="wt-iconsearch" />数据查询</span
> >
<a-menu-item key="detail-search"> <icon-font type="wt-iconxiangxi" />详细数据 </a-menu-item> <a-menu-item key="detail-search">
<icon-font type="wt-iconxiangxi" />详细数据
</a-menu-item>
</a-sub-menu> </a-sub-menu>
<a-menu-item key="analysis"> <a-menu-item key="analysis">
<icon-font type="wt-iconfenxi" />图形分析 <icon-font type="wt-iconfenxi" />图形分析
@ -37,13 +41,12 @@
<a-menu-item key="admin" v-if="isAdmin"> <a-menu-item key="admin" v-if="isAdmin">
<icon-font type="wt-iconhoutai" />后台管理 <icon-font type="wt-iconhoutai" />后台管理
</a-menu-item> </a-menu-item>
</a-menu> </a-menu>
</a-row> </a-row>
</a-layout-header> </a-layout-header>
<a-layout-content> <a-layout-content>
<keep-alive exclude="map-layout"> <keep-alive>
<component :is="currentComp"/> <router-view />
</keep-alive> </keep-alive>
</a-layout-content> </a-layout-content>
<a-modal <a-modal
@ -52,69 +55,76 @@
:destroyOnClose="true" :destroyOnClose="true"
:footer="null" :footer="null"
> >
<password-change <password-change @ok="logout" @cancle="passwd_visible = false" />
@ok="logout"
@cancle="passwd_visible = false"
/>
</a-modal> </a-modal>
</a-layout> </a-layout>
</template> </template>
<script> <script>
import IconFont from "@/components/icon";
// import MapLayout from "@/components/map/Index";
// import DetailSearch from "@/components/search/Index";
// import Analysis from "@/components/analysis/Index";
import IconFont from '@/components/icon' import Logs from "@/components/logs/Index";
import MapLayout from '@/components/map/Index' import Admin from "@/components/admin/Index";
import DetailSearch from '@/components/search/Index' import { logout } from "@/utils/http";
import Analysis from '@/components/analysis/Index' import PasswordChange from "./admin/forms/PasswordChange.vue";
import Logs from '@/components/logs/Index'
import Admin from '@/components/admin/Index'
import { logout } from '@/utils/http'
import PasswordChange from './admin/forms/PasswordChange.vue'
export default { export default {
components: { components: {
'icon-font':IconFont, "icon-font": IconFont,
'map-layout':MapLayout, // "map-layout": MapLayout,
'detail-search':DetailSearch, // "detail-search": DetailSearch,
'analysis':Analysis, // analysis: Analysis,
// 'logs':Logs, // 'logs':Logs,
'admin':Admin, // admin: Admin,
PasswordChange PasswordChange,
}, },
data() { data() {
return { return {
current:['map-layout'], current: ["map-layout"],
currentComp: 'map-layout', currentComp: "map-layout",
passwd_visible: false passwd_visible: false,
}; };
}, },
watch:{
currentComp: function(old, newVal) {
this.$router.push({
name: this.currentComp
})
}
},
computed: { computed: {
isAdmin() { isAdmin() {
return this.$store.getters.isSuper || this.$store.getters.isProject return this.$store.getters.isSuper || this.$store.getters.isProject;
}, },
isAnyone() { isAnyone() {
return this.$store.getters.isAnyone return this.$store.getters.isAnyone;
}, },
username() { username() {
return this.$store.getters.username return this.$store.getters.username;
} },
}, },
methods: { methods: {
handleMenuClick({item, key, keyPath}) { handleMenuClick({ item, key, keyPath }) {
this.currentComp = key this.currentComp = key;
}, },
logout() { logout() {
logout() logout();
sessionStorage.clear() sessionStorage.clear();
this.$store.commit('logout') this.$store.commit("logout");
this.$router.push({ this.$router.push({
path: '/login' path: "/login",
}) });
}, },
changePasswd() { changePasswd() {
this.passwd_visible = true this.passwd_visible = true;
} },
},
mounted() {
// this.$router.push({
// name:this.currentComp
// })
} }
}; };
</script> </script>
@ -126,11 +136,10 @@ export default {
.ant-layout-content { .ant-layout-content {
height: calc(100vh - 110px); height: calc(100vh - 110px);
} }
.w-title{ .w-title {
color: white; color: white;
line-height: 50px; line-height: 50px;
font-size: 24px; font-size: 24px;
font-weight: 600; font-weight: 600;
} }
</style> </style>

View File

@ -4,8 +4,16 @@ import Index from '@/components/Main'
import Login from '@/components/Login' import Login from '@/components/Login'
import store from './store' import store from './store'
import { setAuth } from './http' import { setAuth } from './http'
Vue.use(Router) Vue.use(Router)
const funcRoutes = [
{ path:'map-layout', name:'map-layout', component: ()=>import(/* webpackChunkName: "map-layout" */ '@/components/map/Index' ) },
{ path:'detail-search', name:'detail-search', component: ()=>import(/* webpackChunkName: "detail-search" */ '@/components/search/Index' ) },
{ path:'admin', name:'admin', component: ()=>import(/* webpackChunkName: "admin" */ '@/components/admin/Index' ) },
{ path:'analysis', name:'analysis', component: ()=>import(/* webpackChunkName: "analysis" */ '@/components/analysis/Index' ) },
]
const routes = [ const routes = [
{ {
path: '/', path: '/',
@ -14,7 +22,8 @@ const routes = [
{ {
path: '/index', path: '/index',
name: 'index', name: 'index',
component: Index, component: () => import(/* webpackChunkName: "index" */ '@/components/Main'),
children: funcRoutes,
meta: { meta: {
requireAuth: true requireAuth: true
} }