-
Notifications
You must be signed in to change notification settings - Fork 34
/
Index.vue
187 lines (185 loc) · 5.01 KB
/
Index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
<el-container>
<el-header :style="headerStyle" class="custom-theme-bg">
<v-app-header />
</el-header>
<el-container>
<el-aside :style="sidebarStyle">
<v-app-sidebar :collspse="menuCollspse" />
</el-aside>
<el-container class="layout-main">
<div @click="e=>menuCollspse=!menuCollspse" class="layout-toggle-menu custom-theme-bg">
<i :class="{'el-icon-arrow-left':!menuCollspse,'el-icon-arrow-right':menuCollspse}"></i>
</div>
<el-tabs v-model="currentTab" type="card" @tab-click="clickTab" @tab-remove="removeTab" class="layout-nav-tabs">
<el-tab-pane :label="item.tabName" :closable="!disableTab" v-for="item in pageTabs" :key="item.tabKey" :name="item.tabKey"></el-tab-pane>
</el-tabs>
<v-app-main class="layout-main-content">
<keep-alive v-if="router_cache">
<router-view></router-view>
</keep-alive>
<router-view v-else></router-view>
</v-app-main>
</el-container>
</el-container>
</el-container>
</template>
<script>
import VAppContainer from './components/AppContainer'
import VAppHeader from './components/AppHeader'
import VAppSidebar from './components/AppSidebar'
import VAppMain from './components/AppMain'
import { mapGetters } from 'vuex'
export default {
name: 'layout',
components: {
VAppContainer,
VAppHeader,
VAppSidebar,
VAppMain
},
data() {
return {
menus: window.authInfo.menus,
currentTab: '',
pageTabs: [],
menuCollspse: window.innerWidth < 800,
headerHeight: 50,
innerHeight: 0,
disableTab: localStorage.DISABLE_TAB === 'true'
}
},
watch: {
$route: {
handler(val) {
const routeInfo = this.currentRouteInfo(this.$route.name) || {
menuName: this.$route.meta.title || this.$route.fullPath,
menuUrl: this.$route.fullPath,
menuCode: this.$route.name
}
// console.log(routeInfo)
this.currentTab = this.$route.name
if (this.pageTabs.find(e => e.tabKey === this.currentTab)) return
var newRoute = {
tabName: routeInfo.menuName,
tabRoute: routeInfo.menuUrl
? routeInfo.menuUrl
: { name: routeInfo.menuCode },
tabKey: routeInfo.menuCode
}
this.disableTab
? (this.pageTabs = [newRoute])
: this.pageTabs.push(newRoute)
},
immediate: true
},
removeNavTab(val) {
if (val) {
this.removeTab(val)
this.$store.dispatch('removeNavTab', '')
}
}
},
created() {
var _this = this
_this.innerHeight = window.innerHeight
window.onresize = function() {
if (_this.innerHeight !== window.innerHeight) {
_this.innerHeight = window.innerHeight
}
}
},
computed: {
...mapGetters(['removeNavTab']),
headerStyle() {
return `height:${this.headerHeight}px;line-height: ${
this.headerHeight
}px;`
},
sidebarStyle() {
return (
'width:auto;height:' + (this.innerHeight - this.headerHeight) + 'px'
)
},
router_cache() {
return this.$route.meta.cache === true
}
},
methods: {
currentRouteInfo(routeName) {
var arr = []
;(function fn(key, value, items, resultArr) {
var checkResult = false
for (let index = 0; index < items.length; index++) {
const e = items[index]
checkResult =
e[key] === value ||
(e.children && fn(key, value, e.children, resultArr))
if (checkResult) {
resultArr.push(e)
break
}
}
return checkResult
})('menuCode', routeName, this.menus, arr)
return arr[0]
},
clickTab(tab) {
var currentRoute = this.pageTabs.find(e => e.tabKey === this.currentTab)
if (!currentRoute) return this.$ui.pages.link(this.$codes.index_path)
this.$ui.pages.link(currentRoute.tabRoute)
},
removeTab(targetName) {
this.pageTabs = this.pageTabs.filter(e => e.tabKey !== targetName)
const currentRoute =
this.pageTabs.length > 0 &&
this.pageTabs[this.pageTabs.length - 1].tabRoute
if (!currentRoute) {
return this.$ui.pages.link(this.$codes.index_path)
}
// this.currentTab = currentRoute.tabKey
this.$ui.pages.link(currentRoute)
}
}
}
</script>
<style>
.layout-main {
position: relative;
}
.layout-main-content {
position: absolute;
top: 43px;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
padding: 15px;
}
.layout-toggle-menu {
width: 40px;
height: 39px;
background: #1f2f3d;
position: absolute;
top: 0;
z-index: 1000;
cursor: pointer;
line-height: 40px;
text-align: center;
color: #fff;
font-size: 14px;
opacity: 0.5;
transition: opacity 0.3s ease-out;
margin-left: 1px;
margin-top: 2px;
}
.layout-nav-tabs {
width: 100%;
height: 40px;
z-index: 999;
}
.layout-nav-tabs .el-tabs__header {
padding-left: 42px;
padding-top: 2px;
}
</style>