Aside.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="aside-main">
  3. <section
  4. v-show="showNavTag"
  5. :class="{
  6. 'left-aside': !collapsed && navTagType === 1,
  7. 'hidden-left-aside': collapsed && navTagType === 1,
  8. 'top-aside': navTagType === 2
  9. }"
  10. >
  11. <div class="business">
  12. <div
  13. v-if="false"
  14. class="business-select"
  15. :class="{ 'show-business-all': showBizIdSelect }"
  16. @mouseenter="showBizIdSelect = true"
  17. @mouseleave="showBizIdSelect = false"
  18. >
  19. <img src="../../assets/业务线选择.png" class="business-logo"><span v-show="showBizIdSelect">项目管理首页</span>
  20. </div>
  21. {{ bizName }}
  22. <svg-icon icon-class="select-business" @click="handleClickRouter({ name: '业务线选择' })" />
  23. </div>
  24. <ul class="all-pages-list">
  25. <li v-for="item in routesList" :key="item.path" @click="handleClickRouter(item)">
  26. <template v-if="!item.hidden">
  27. <div v-if="item.cutOff" class="cut-off" />
  28. <div class="page-item" :class="{ 'active-page': activePage === item.name }">
  29. <svg-icon v-if="item.icon" v-show="navTagType === 1" :icon-class="item.icon" />
  30. {{ item.name }}
  31. </div>
  32. </template>
  33. </li>
  34. </ul>
  35. <div v-show="!collapsed && navTagType === 1" class="bottom-collapsed">
  36. <img src="../../assets/expand.png" @click="toggleCollapsed()">
  37. </div>
  38. </section>
  39. <section v-show="collapsed && navTagType === 1 && showNavTag" class="left-aside-collapsed">
  40. <div class="button-collapsed" @click="toggleCollapsed()"><i class="el-icon-arrow-right" /></div>
  41. </section>
  42. </div>
  43. </template>
  44. <script>
  45. import { mapGetters } from 'vuex'
  46. import routes from '@/router/newRouter'
  47. export default {
  48. data() {
  49. return {
  50. routesList: [], // 路由数组
  51. activePage: '', // 当前page页面
  52. showBizIdSelect: false // 显示业务线选择按钮
  53. }
  54. },
  55. computed: {
  56. ...mapGetters(['bizId', 'bizName', 'activeNavTag', 'navTagType', 'showNavTag', 'collapsed'])
  57. },
  58. watch: {
  59. // 当前2级导航栏对应的1级导航
  60. activeNavTag() {
  61. this.init()
  62. },
  63. // 当前2级导航的类型
  64. navTagType(newV) {
  65. newV === 1
  66. ? this.$store.dispatch('global/setCollapsed', false) // 二级侧边栏不收起
  67. : this.$store.dispatch('global/setCollapsed', true) // 二级侧边栏收起
  68. },
  69. $route: {
  70. handler(to) {
  71. this.activePage = to.name
  72. },
  73. immediate: true
  74. }
  75. },
  76. created() {
  77. this.init()
  78. },
  79. methods: {
  80. init() {
  81. const config = routes.find(item => item.name === this.activeNavTag)
  82. this.routesList = config.children
  83. // 子路由数量小于1,隐藏二级侧边栏控制
  84. if (this.routesList.length <= 1) {
  85. this.$store.dispatch('global/setShowNavTag', false) // 不展示二级侧边栏
  86. this.$store.dispatch('global/setCollapsed', true) // 二级侧边栏收起
  87. } else {
  88. this.$store.dispatch('global/setShowNavTag', true) // 展示二级侧边栏
  89. this.navTagType === 1
  90. ? this.$store.dispatch('global/setCollapsed', false) // 二级侧边栏不收起
  91. : this.$store.dispatch('global/setCollapsed', true) // 二级侧边栏收起
  92. }
  93. },
  94. // 路由跳转
  95. handleClickRouter(router) {
  96. this.$router.push({ name: router.name })
  97. },
  98. // 展开/收起侧边栏
  99. toggleCollapsed() {
  100. this.$store.dispatch('global/setCollapsed', !this.collapsed) // 二级侧边栏不收起
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. ul,li{
  107. list-style: none;
  108. padding: 0;
  109. margin: 0;
  110. }
  111. section {
  112. height: 100%;
  113. }
  114. @keyframes expande {
  115. 0% {
  116. width: 0;
  117. }
  118. 100% {
  119. width: 135px;
  120. }
  121. }
  122. @keyframes close {
  123. 0% {
  124. width: 135px;
  125. }
  126. 100% {
  127. width: 0;
  128. }
  129. }
  130. @keyframes topExpande {
  131. 0% {
  132. height: 0;
  133. }
  134. 100% {
  135. height: 60px;
  136. }
  137. }
  138. .left-aside {
  139. width: 135px;
  140. // animation: 0.5s expande linear;
  141. }
  142. .hidden-left-aside {
  143. width: 0;
  144. // animation: 0.5s close linear;
  145. }
  146. //左边导航栏样式
  147. .left-aside,
  148. .hidden-left-aside {
  149. height: 100%;
  150. position: relative;
  151. overflow: hidden;
  152. background-color: #ffffff;
  153. .business {
  154. position: relative;
  155. width: 100%;
  156. height: 60px;
  157. padding-top: 5px;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. color: #333333;
  162. font-size: 18px;
  163. border-bottom: 1px solid #eeeeee;
  164. white-space: nowrap;
  165. svg {
  166. cursor: pointer;
  167. }
  168. .business-select {
  169. cursor: pointer;
  170. position: absolute;
  171. top: 0;
  172. left: 0;
  173. width: 32px;
  174. height: 20px;
  175. line-height: 20px;
  176. padding-left: 5px;
  177. background-color: #f2f8ff;
  178. border-radius: 0px 0px 10px 0px;
  179. span {
  180. margin-right: 5px;
  181. font-size: 12px;
  182. color: #565656;
  183. }
  184. }
  185. .show-business-all {
  186. width: 100px;
  187. }
  188. .business-logo {
  189. height: 15px;
  190. width: 15px;
  191. margin-right: 2px;
  192. }
  193. }
  194. .all-pages-list {
  195. margin-top: 33px;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. font-size: 14px;
  200. color: #444444;
  201. li {
  202. width: 100%;
  203. }
  204. .page-item {
  205. width: 100%;
  206. white-space: nowrap;
  207. padding: 5px 0 0 27px;
  208. margin-bottom: 10px;
  209. cursor: pointer;
  210. svg {
  211. margin-right: 5px;
  212. }
  213. }
  214. .active-page {
  215. color: #409eff;
  216. }
  217. .cut-off {
  218. border-top: 1px solid #eeeeee;
  219. margin: 10px 25px 20px 25px;
  220. }
  221. .page-item:hover {
  222. background-color: rgba(64, 158, 255, 0.1);
  223. }
  224. }
  225. .bottom-collapsed {
  226. height: 60px;
  227. padding: 0px;
  228. min-height: 5%;
  229. border-top: 1px solid #dcdfe6;
  230. position: absolute;
  231. bottom: 0;
  232. left: 0;
  233. width: 100%;
  234. display: flex;
  235. justify-content: flex-end;
  236. font-size: 30px;
  237. img {
  238. height: 20px;
  239. margin-top: 10px;
  240. margin-right: 10px;
  241. }
  242. }
  243. }
  244. //顶部导航栏样式
  245. .top-aside {
  246. width: calc(100% - 80px);
  247. position: fixed;
  248. z-index: 99;
  249. top: 0;
  250. left: 81px;
  251. height: 70px;
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. overflow: hidden;
  256. background-color: #ffffff;
  257. // animation: 0.5s topExpande linear;
  258. border-bottom: 10px solid #F2F3F6;
  259. .business {
  260. position: absolute;
  261. top: 0;
  262. left: 0;
  263. width: 135px;
  264. height: 60px;
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. flex-shrink: 0;
  269. color: #333333;
  270. font-size: 18px;
  271. border-right: 1px solid #eeeeee;
  272. white-space: nowrap;
  273. .business-select {
  274. cursor: pointer;
  275. position: absolute;
  276. top: 0;
  277. left: 0;
  278. width: 32px;
  279. height: 20px;
  280. line-height: 20px;
  281. padding-left: 5px;
  282. background-color: #f2f8ff;
  283. border-radius: 0px 0px 10px 0px;
  284. span {
  285. margin-right: 5px;
  286. font-size: 12px;
  287. color: #565656;
  288. }
  289. }
  290. .show-business-all {
  291. width: 100px;
  292. }
  293. .business-logo {
  294. height: 15px;
  295. width: 15px;
  296. margin-right: 2px;
  297. }
  298. }
  299. .all-pages-list {
  300. display: flex;
  301. align-items: center;
  302. font-size: 14px;
  303. color: #444444;
  304. height: 100%;
  305. li {
  306. height: 100%;
  307. display: flex;
  308. align-items: center;
  309. }
  310. .page-item {
  311. height: 100%;
  312. display: flex;
  313. align-items: center;
  314. white-space: nowrap;
  315. padding: 0 5px;
  316. margin-right: 10px;
  317. cursor: pointer;
  318. }
  319. .active-page {
  320. color: #409eff;
  321. }
  322. .cut-off {
  323. height: 60%;
  324. margin: auto;
  325. border-left: 1px solid #eeeeee;
  326. margin-left: 10px;
  327. margin-right: 20px;
  328. }
  329. .page-item:hover {
  330. background-color: rgba(64, 158, 255, 0.1);
  331. }
  332. }
  333. }
  334. .left-aside-collapsed {
  335. background-color: #f7f8fc;
  336. color: #409eff;
  337. height: 100%;
  338. .button-collapsed {
  339. cursor: pointer;
  340. position: absolute;
  341. z-index: 101;
  342. bottom: 20px;
  343. width: 12px;
  344. height: 30px;
  345. background-color: #ffffff;
  346. font-size: 10px;
  347. display: flex;
  348. align-items: center;
  349. border-bottom: 1px solid #409eff;
  350. border-top: 1px solid#409eff;
  351. border-right: 1px solid #409eff;
  352. border-top-right-radius: 4px;
  353. border-bottom-right-radius: 4px;
  354. }
  355. }
  356. .iconFont {
  357. font-size: 14px;
  358. margin: 3px 4px 0;
  359. }
  360. .iconFont:hover {
  361. cursor: pointer;
  362. color: #409eff;
  363. }
  364. </style>