Commit a04dfb47 authored by “yiyousong”'s avatar “yiyousong”

perf: 优化

parent 634f8615
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"css-loader": "^3.5.3", "css-loader": "^3.5.3",
"element-china-area-data": "^5.0.2", "element-china-area-data": "^5.0.2",
"element-ui": "^2.15.10", "element-ui": "^2.15.14",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"moment": "^2.29.4", "moment": "^2.29.4",
"npm": "^6.13.7", "npm": "^6.13.7",
......
...@@ -9,27 +9,8 @@ export default { ...@@ -9,27 +9,8 @@ export default {
data() { data() {
return {}; return {};
}, },
created() { created() {},
// this.readVueXData(); methods: {},
},
methods: {
// 解决刷新store初始化问题
readVueXData() {
window.addEventListener("beforeunload", () => {
sessionStorage.setItem("store", JSON.stringify(this.$store.state));
});
if (sessionStorage.getItem("store")) {
this.$store.replaceState(
Object.assign(
{},
this.$store.state,
JSON.parse(sessionStorage.getItem("store"))
)
);
sessionStorage.removeItem("store");
}
},
},
}; };
</script> </script>
...@@ -38,6 +19,5 @@ export default { ...@@ -38,6 +19,5 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: #f0f2f5; background-color: #f0f2f5;
// display: flex;
} }
</style> </style>
<template> <template>
<div class="layouts flex flexc aic"> <el-container>
<el-header height="64px">
<Header></Header> <Header></Header>
<!-- <div class="crumbs"> </el-header>
<el-breadcrumb separator="/"> <el-container>
<el-breadcrumb-item <el-aside width="200px" v-if="layout === 'side'">
><a :href="portalUrl + '/#/home/dataManagement/dataAdmin'" <MenuBar></MenuBar>
>政务一体化平台</a </el-aside>
></el-breadcrumb-item <el-main>
>
<el-breadcrumb-item
><a :href="portalUrl + '/#/home/siteArrange'"
>站点编排</a
></el-breadcrumb-item
>
<el-breadcrumb-item
v-for="bread in breads"
:key="bread.title"
:to="bread.to"
>{{ bread.title }}</el-breadcrumb-item
>
</el-breadcrumb>
</div> -->
<div class="main flex1 flex flexc">
<!-- <el-tabs :value="activeKey" @tab-click="changeRouter">
<el-tab-pane v-for="v in subMenus" :key="v.path" :name="v.path">
<template slot="label">
<i v-if="v.meta.icon" :class="['mr5', 'primary', v.meta.icon]"></i>
<span class="tab-label">{{ v.meta.title }}</span>
</template>
</el-tab-pane>
</el-tabs> -->
<div class="out-box flex1">
<keep-alive> <keep-alive>
<!-- 需要缓存的视图组件 --> <!-- 需要缓存的视图组件 -->
<router-view v-if="$route.meta.keepAlive"> </router-view> <router-view v-if="$route.meta.keepAlive"> </router-view>
</keep-alive> </keep-alive>
<!-- 不需要缓存的视图组件 --> <!-- 不需要缓存的视图组件 -->
<router-view v-if="!$route.meta.keepAlive"> </router-view> <router-view v-if="!$route.meta.keepAlive"> </router-view>
</div> </el-main>
</div> </el-container>
</div> </el-container>
</template> </template>
<script> <script>
import Header from "./components/Header.vue"; import Header from "./components/Header.vue";
import MenuBar from "./components/MenuBar.vue";
import { getdeptList } from "@/api/department"; import { getdeptList } from "@/api/department";
import { mapMutations, mapState } from "vuex"; import { mapMutations, mapState } from "vuex";
import local from "@/utils/local"; import local from "@/utils/local";
import { findBottomSubarrays } from "@/utils";
import { systemName } from "@/config"; import { systemName } from "@/config";
export default { export default {
components: { components: {
Header, Header,
MenuBar,
}, },
data() { data() {
return { return {
...@@ -62,49 +40,18 @@ export default { ...@@ -62,49 +40,18 @@ export default {
}; };
}, },
created() { created() {
// this.getSubMenus();
document.title = this.sysName ? this.sysName : this.systemName; // 设置项目标题 document.title = this.sysName ? this.sysName : this.systemName; // 设置项目标题
// this.calcBreads();
this.getdeptList(); this.getdeptList();
}, },
// watch: {
// "$route.path"() {
// this.calcBreads();
// },
// },
computed: { computed: {
...mapState(["sysName"]), ...mapState(["sysName", "layout"]),
activeKey() { activeKey() {
return this.$route.path; return this.$route.path;
}, },
}, },
methods: { methods: {
...mapMutations(["SET_deptList"]), ...mapMutations(["SET_deptList"]),
// 计算面包屑
calcBreads() {
let temp = [{ to: "/basicsset", title: "数字样表系统" }];
// 过滤出路由数据
let r = this.$route.matched
.filter((v) => v.meta.title)
.map((v) => {
return { to: v.path, title: v.meta.title };
});
// 赋值给面包屑渲染
this.breads = [...temp, ...r];
},
// 获取当前顶层路由下的所有子路由
getSubMenus() {
let path = this.$route?.meta.activeMenu
? this.$route.meta.activeMenu
: this.$route.path;
let options = this.$router.options.routes[0].children;
let curRouters = options.filter((v) => v.path == path);
this.subMenus = findBottomSubarrays(curRouters).filter(
(v) => !v.meta.hidden
);
},
// 获取部门列表 // 获取部门列表
async getdeptList() { async getdeptList() {
let res = await getdeptList({ let res = await getdeptList({
...@@ -126,27 +73,18 @@ export default { ...@@ -126,27 +73,18 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.layouts { .el-container {
width: 100%; width: 100vw;
// min-width: 1620px; height: 100vh;
height: 100%; }
padding-bottom: 15px; .el-header {
// .crumbs { padding: 0px 20px;
// margin: 10px 0px; background: linear-gradient(90deg, #1845c6 0%, #2999ff 100%);
// width: 98%; }
// } .el-aside {
background-color: #fff;
.main { }
width: 98%; .el-main {
margin-top: 15px; overflow: auto;
// padding-bottom: 15px;
border-radius: 4px;
overflow-y: auto;
// background-color: #fff;
}
.out-box {
// padding: 15px;
overflow-y: auto;
}
} }
</style> </style>
<template> <template>
<div class="header flex aic jcb"> <div class="header-content">
<div class="left flex aic"> <div class="logo-box">
<img <img
class="pointer mr10 logo" class="logo"
:src="sysLogo ? sysLogo : require('@/assets/img/logo.png')" :src="sysLogo ? sysLogo : require('@/assets/img/logo.png')"
alt="LOGO" alt="LOGO"
@click="handleGoHome" @click="handleGoHome"
/> />
<h1 class="title pointer" @click="handleGoHome"> <h1 class="title" @click="handleGoHome">
{{ sysName ? sysName : systemName }} {{ sysName ? sysName : systemName }}
</h1> </h1>
<HeaderSite class="mr50 ml20"></HeaderSite> <HeaderSite></HeaderSite>
<!-- 导航 -->
<el-menu
:default-active="activeMenu"
mode="horizontal"
router
text-color="rgba(254, 254, 254, 0.65)"
@select="selectMenu"
>
<template v-for="v in menus">
<!-- 有子路由 -->
<el-submenu
v-if="!v.hideChildrenInMenu && v.children && v.children.length"
:key="'a' + v.path"
:index="v.path"
>
<template slot="title">
<i v-if="v.meta && v.meta.icon" :class="v.meta.icon"></i>
{{ v.meta.title }}
</template>
<el-menu-item
v-for="item in v.children"
:key="item.path"
:index="item.path"
>
<i v-if="item.meta && item.meta.icon" :class="item.meta.icon"></i>
{{ item.meta && item.meta.title }}
</el-menu-item>
</el-submenu>
<!-- 单个路由 -->
<el-menu-item v-else :key="v.path" :index="v.path">
<i v-if="v.meta && v.meta.icon" :class="v.meta.icon"></i>
{{ v.meta.title }}
</el-menu-item>
</template>
<!-- <el-menu-item v-for="v in menus" :key="v.path" :index="v.path">
<i :class="v.meta.icon"></i>
{{ v.meta.title }}
</el-menu-item> -->
</el-menu>
</div> </div>
<!-- 导航 -->
<MenuBar v-if="layout === 'head'" mode="horizontal"></MenuBar>
<!-- 返回门户 --> <!-- 返回门户 -->
<div class="back-btn"> <div class="back-btn">
<el-tooltip effect="dark" content="返回门户" placement="bottom"> <el-tooltip effect="dark" content="返回门户" placement="bottom">
...@@ -65,11 +27,14 @@ ...@@ -65,11 +27,14 @@
<script> <script>
import HeaderSite from "./HeaderSite.vue"; import HeaderSite from "./HeaderSite.vue";
import MenuBar from "./MenuBar.vue";
import { systemName } from "@/config"; import { systemName } from "@/config";
import { mapState, mapMutations } from "vuex"; import { mapState, mapMutations } from "vuex";
export default { export default {
components: { components: {
HeaderSite, HeaderSite,
MenuBar,
}, },
data() { data() {
return { return {
...@@ -88,7 +53,7 @@ export default { ...@@ -88,7 +53,7 @@ export default {
return curMatched[0].path; return curMatched[0].path;
} }
}, },
...mapState(["menus", "sysName", "sysLogo", "path"]), ...mapState(["menus", "sysName", "sysLogo", "path", "layout"]),
}, },
created() {}, created() {},
methods: { methods: {
...@@ -107,24 +72,30 @@ export default { ...@@ -107,24 +72,30 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.header { .header-content {
height: 64px; height: 100%;
width: 100%; width: 100%;
padding: 0px 24px;
// background-color: #2681e8;
background: linear-gradient(90deg, #1845c6 0%, #2999ff 100%);
color: #fff; color: #fff;
flex-shrink: 0; display: flex;
align-items: center;
justify-content: space-between;
.logo-box {
display: flex;
align-items: center;
}
.logo { .logo {
height: 32px; height: 32px;
object-fit: contain; object-fit: contain;
margin-right: 8px;
} }
.left {
height: 100%;
}
.title { .title {
max-width: 200px; margin-right: 34px;
font-weight: bold;
font-size: 18px; font-size: 18px;
line-height: normal;
color: #fff;
cursor: pointer;
} }
.back-btn { .back-btn {
a { a {
...@@ -133,67 +104,4 @@ export default { ...@@ -133,67 +104,4 @@ export default {
} }
} }
} }
/deep/.el-menu {
height: 100% !important;
border: none !important;
background-color: transparent;
i {
color: rgba(254, 254, 254, 0.65);
}
.el-menu-item {
height: 100% !important;
border: none !important;
display: flex;
align-items: center;
color: rgba(254, 254, 254, 0.65);
&:hover {
// background-color: transparent !important;
color: #fff !important;
background-color: #1890ff !important;
// border-bottom: 2px solid #fff !important;
}
}
}
/deep/.el-submenu {
height: 100% !important;
.el-submenu__title {
height: 100% !important;
display: flex;
align-items: center;
color: rgba(254, 254, 254, 0.65) !important;
border: none !important;
&:hover {
// background-color: transparent !important;
color: #fff !important;
background-color: #1890ff !important;
// border-bottom: 2px solid #fff !important;
}
}
}
.el-menu--horizontal .el-menu .el-menu-item {
color: #909399;
&:hover {
i {
color: #1890ff;
}
color: #1890ff;
}
}
.el-menu--horizontal .el-menu .el-menu-item.is-active {
color: #1890ff !important;
}
/deep/.is-active {
// border-bottom: 2px solid #fff !important;
color: #fff !important;
// background-color: transparent !important;
background-color: #1890ff !important;
.el-submenu__title {
border: none !important;
color: #fff !important;
// background-color: transparent !important;
background-color: #1890ff !important;
}
}
</style> </style>
<template>
<el-menu
:default-active="activeMenu"
:mode="mode"
router
@select="selectMenu"
>
<template v-for="v in menus">
<!-- 有子路由 -->
<el-submenu
v-if="!v.hideChildrenInMenu && v.children && v.children.length"
:key="'a' + v.path"
:index="v.path"
>
<template slot="title">
<i v-if="v.meta && v.meta.icon" :class="v.meta.icon"></i>
{{ v.meta.title }}
</template>
<el-menu-item
v-for="item in v.children"
:key="item.path"
:index="item.path"
>
<i v-if="item.meta && item.meta.icon" :class="item.meta.icon"></i>
{{ item.meta && item.meta.title }}
</el-menu-item>
</el-submenu>
<!-- 单个路由 -->
<el-menu-item v-else :key="v.path" :index="v.path">
<i v-if="v.meta && v.meta.icon" :class="v.meta.icon"></i>
{{ v.meta.title }}
</el-menu-item>
</template>
</el-menu>
</template>
<script>
import { systemName } from "@/config";
import { mapState, mapMutations } from "vuex";
export default {
props: {
mode: {
type: String,
default: "",
},
},
data() {
return {
systemName,
portal: process.env.VUE_APP_API_portal_URL + "/#",
};
},
computed: {
...mapState(["menus", "sysName", "sysLogo", "path"]),
activeMenu() {
const route = this.$route;
const { meta, matched } = route;
if (meta.activeMenu) {
return meta.activeMenu;
} else {
let curMatched = matched.filter((v) => v.path);
return curMatched[0].path;
}
},
},
created() {},
methods: {
...mapMutations(["SET_secondaryRoutes"]),
selectMenu(index) {
this.SET_secondaryRoutes(index);
},
handleGoHome() {
let path = this.menus[0].path;
if (path) {
this.$router.push(path);
}
},
},
};
</script>
<style lang="less" scoped>
.el-menu {
border: none !important;
// .is-active {
// :deep(.el-submenu__title) {
// color: #1890ff !important;
// i {
// color: #1890ff !important;
// }
// }
// }
}
.el-menu-item,
:deep(.el-submenu__title) {
display: flex;
align-items: center;
}
.el-menu--horizontal {
height: 100% !important;
border: none !important;
background-color: transparent;
i {
color: rgba(254, 254, 254, 0.65);
}
.el-menu-item {
height: 100% !important;
border: none !important;
display: flex;
align-items: center;
color: rgba(254, 254, 254, 0.65);
&:hover {
// background-color: transparent !important;
color: #fff !important;
background-color: #1890ff !important;
// border-bottom: 2px solid #fff !important;
}
}
:deep(.el-submenu) {
height: 100% !important;
.el-submenu__title {
height: 100% !important;
display: flex;
align-items: center;
color: rgba(254, 254, 254, 0.65);
border: none !important;
i {
color: rgba(254, 254, 254, 0.65);
}
&:hover {
// background-color: transparent !important;
color: #fff !important;
background-color: #1890ff !important;
// border-bottom: 2px solid #fff !important;
}
}
}
.is-active {
// border-bottom: 2px solid #fff !important;
color: #fff !important;
// background-color: transparent !important;
background-color: #1890ff !important;
:deep(.el-submenu__title) {
border: none !important;
color: #fff !important;
// background-color: transparent !important;
background-color: #1890ff !important;
}
}
.el-menu--popup {
.el-menu-item {
color: #909399 !important;
i {
color: #909399 !important;
}
&:hover {
i {
color: #1890ff !important;
}
color: #1890ff !important;
background-color: transparent !important;
}
}
.is-active {
color: #1890ff !important;
background-color: transparent !important;
i {
color: #1890ff !important;
}
}
}
}
</style>
...@@ -8,6 +8,7 @@ Vue.use(Vuex); ...@@ -8,6 +8,7 @@ Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
layout: "head", //导航布局,可选 side 和 head,分别为侧边导航和顶部导航
token: "", token: "",
siteId: "", // 站点id siteId: "", // 站点id
deptList: [], // 部门列表 deptList: [], // 部门列表
...@@ -24,6 +25,9 @@ export default new Vuex.Store({ ...@@ -24,6 +25,9 @@ export default new Vuex.Store({
permissions: [], // 按钮权限字符列表 permissions: [], // 按钮权限字符列表
}, },
getters: { getters: {
layout(state) {
return state.layout;
},
siteId(state) { siteId(state) {
return state.siteId; return state.siteId;
}, },
...@@ -60,6 +64,9 @@ export default new Vuex.Store({ ...@@ -60,6 +64,9 @@ export default new Vuex.Store({
}, },
}, },
mutations: { mutations: {
SET_layout(state, layout) {
state.layout = layout;
},
SET_menusList(state, menusList) { SET_menusList(state, menusList) {
state.menusList = menusList; state.menusList = menusList;
}, },
...@@ -71,7 +78,10 @@ export default new Vuex.Store({ ...@@ -71,7 +78,10 @@ export default new Vuex.Store({
}, },
SET_secondaryRoutes(state, value) { SET_secondaryRoutes(state, value) {
let routes = state.menus.find((v) => v.path == value); let routes = state.menus.find((v) => v.path == value);
let secondaryRoutes = routes.children || []; let secondaryRoutes = [];
if (routes) {
secondaryRoutes = routes.children;
}
state.secondaryRoutes = secondaryRoutes; state.secondaryRoutes = secondaryRoutes;
}, },
SET_path(state, path) { SET_path(state, path) {
......
...@@ -3576,10 +3576,10 @@ element-china-area-data@^5.0.2: ...@@ -3576,10 +3576,10 @@ element-china-area-data@^5.0.2:
china-area-data "^5.0.1" china-area-data "^5.0.1"
lodash-es "^4.17.15" lodash-es "^4.17.15"
element-ui@^2.15.10: element-ui@^2.15.14:
version "2.15.10" version "2.15.14"
resolved "https://registry.npmmirror.com/element-ui/-/element-ui-2.15.10.tgz#fde0ff5cb4c30e8eb166d617f85916defe5948f1" resolved "https://registry.npmmirror.com/element-ui/-/element-ui-2.15.14.tgz#3c34df79467636592812d720d2e6784e7a6ec2ea"
integrity sha512-jmD++mU2wKXbisvx4fxOl2mHaU+HWHTAq/3Wf8x9Bwyu4GdDZPLABb+CGi3DWN6fPqdgRcd74aX39DO+YHObLw== integrity sha512-2v9fHL0ZGINotOlRIAJD5YuVB8V7WKxrE9Qy7dXhRipa035+kF7WuU/z+tEmLVPBcJ0zt8mOu1DKpWcVzBK8IA==
dependencies: dependencies:
async-validator "~1.8.1" async-validator "~1.8.1"
babel-helper-vue-jsx-merge-props "^2.0.0" babel-helper-vue-jsx-merge-props "^2.0.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment