Aside.vue 9.0 KB

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