Menu.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="level-2-wrap" :class="{ 'light-theme': light, 'w-0': !l2MenuVisibleForStore }" :style="wrapStyle">
  3. <scrollbar
  4. class="level-2-menu">
  5. <div class="title text-truncate pr-2" :title="getLabel(l2Menu.meta)">{{ getLabel(l2Menu.meta) }}</div>
  6. <div
  7. class="level-3-item"
  8. v-for="(citem, cidx) of menus"
  9. :key="cidx">
  10. <div
  11. class="group-menu"
  12. v-if="citem.submenus">
  13. <div class="level-3-group-title text-truncate pr-2" :title="getLabel(citem.meta)">{{ getLabel(citem.meta) }}</div>
  14. <router-link
  15. v-for="(sitem, sidx) of citem.submenus"
  16. v-show="showMenu(sitem)"
  17. :key="sidx"
  18. class="menu-item text-truncate pr-2"
  19. :to="sitem.path"
  20. :title="getLabel(sitem.meta)"
  21. tag="a"
  22. active-class="active">
  23. {{ getLabel(sitem.meta) }}
  24. </router-link>
  25. </div>
  26. <router-link
  27. v-else
  28. class="menu-item text-truncate pr-2"
  29. :to="citem.path"
  30. :title="getLabel(citem.meta)"
  31. tag="a"
  32. active-class="active">
  33. {{ getLabel(citem.meta) }}
  34. </router-link>
  35. </div>
  36. </scrollbar>
  37. <div class="level-2-menu-collapse" @click="$store.commit('setting/SET_L2_MENU_VISIBLE', !l2MenuVisibleForStore)">
  38. <div class="level-2-menu-collapse-bg" />
  39. <div class="level-2-menu-collapse-icon d-flex align-items-center">
  40. <a-icon type="left" style="font-size: 12px;" v-show="l2MenuVisibleForStore" />
  41. <a-icon type="right" style="font-size: 12px;" v-show="!l2MenuVisibleForStore" />
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import { mapGetters, mapState } from 'vuex'
  48. import * as R from 'ramda'
  49. import { hasPermission } from '@/utils/auth'
  50. export default {
  51. name: 'Level2Menu',
  52. props: {
  53. l2Menu: {
  54. type: Object,
  55. required: true,
  56. },
  57. },
  58. computed: {
  59. ...mapGetters(['theme']),
  60. ...mapState('common', {
  61. openCloudShell: state => state.openCloudShell,
  62. cloudShellHeight: state => state.cloudShellHeight,
  63. }),
  64. wrapStyle () {
  65. return {
  66. bottom: this.openCloudShell ? `${this.cloudShellHeight}px` : '0',
  67. }
  68. },
  69. light () {
  70. return this.theme === 'light'
  71. },
  72. menus () {
  73. const menus = this.l2Menu.menus
  74. const res = []
  75. menus.forEach(m2item => {
  76. const m2 = { ...m2item }
  77. if (this.showMenu(m2)) {
  78. if (m2.submenus) {
  79. let flag = false
  80. const submenus = []
  81. m2.submenus.forEach(m3item => {
  82. if (this.showMenu(m3item)) {
  83. submenus.push(m3item)
  84. flag = true
  85. }
  86. })
  87. if (flag) {
  88. m2.submenus = submenus
  89. res.push(m2)
  90. }
  91. } else {
  92. res.push(m2)
  93. }
  94. }
  95. })
  96. return res
  97. },
  98. l2MenuVisibleForStore () {
  99. return this.$store.state.setting.l2MenuVisible
  100. },
  101. },
  102. methods: {
  103. getLabel (meta) {
  104. if (meta.t) {
  105. return this.$t(meta.t)
  106. }
  107. return R.is(Function, meta.label) ? meta.label() : meta.label
  108. },
  109. getMenuHidden (menu) {
  110. if (!R.isNil(menu.meta.hidden)) {
  111. if (R.is(Function, menu.meta.hidden)) {
  112. return menu.meta.hidden(this.userInfo)
  113. }
  114. return menu.meta.hidden
  115. }
  116. if (!R.isNil(menu.meta.invisible)) {
  117. if (R.is(Function, menu.meta.invisible)) {
  118. return menu.meta.invisible(this.userInfo)
  119. }
  120. return menu.meta.invisible
  121. }
  122. return false
  123. },
  124. showMenu (item) {
  125. const hidden = this.getMenuHidden(item)
  126. if (R.isNil(item.meta.permission) || R.isEmpty(item.meta.permission)) {
  127. return !hidden && true
  128. }
  129. return !hidden && hasPermission({ key: item.meta.permission })
  130. },
  131. },
  132. }
  133. </script>
  134. <style lang="less" scoped>
  135. @import "../../../src/styles/less/theme";
  136. .level-2-wrap {
  137. position: fixed;
  138. left: 0;
  139. width: 160px;
  140. top: 60px;
  141. background-color: @sidebar-dark-bg-color;
  142. box-shadow: 1px 0 6px 0 rgba(165,192,207,.3);
  143. z-index: 5;
  144. transition: width .2s ease;
  145. ::v-deep {
  146. .scrollbar-wrap {
  147. overflow-x: hidden;
  148. }
  149. }
  150. &.light-theme {
  151. background-color: @sidebar-light-bg-color;
  152. .level-2-menu {
  153. .title {
  154. color: #000;
  155. }
  156. }
  157. .level-3-item {
  158. .level-3-group-title {
  159. color: #000000;
  160. font-weight: 500;
  161. }
  162. .menu-item {
  163. position: relative;
  164. color: @sidebar-light-text-color;
  165. // &::after {
  166. // background-color: @primary-color;
  167. // }
  168. &:hover, &.active {
  169. &::after {
  170. width: 6px;
  171. height: 6px;
  172. border-radius: 50%;
  173. position: absolute;
  174. top: 50%;
  175. transform: translate(4px, -50%);
  176. background-color: @primary-color;
  177. overflow: hidden;
  178. }
  179. }
  180. &:hover {
  181. color: @sidebar-light-hover-text-color;
  182. }
  183. &.active {
  184. color: @primary-color;
  185. }
  186. }
  187. }
  188. }
  189. &.w-0 {
  190. width: 0;
  191. }
  192. }
  193. .level-2-menu {
  194. width: 100%;
  195. height: 100%;
  196. font-size: 14px;
  197. color: #fff;
  198. transition: left .2s;
  199. padding: 24px 0 0 23px;
  200. .title {
  201. color: #fff;
  202. font-size: 20px;
  203. font-weight: bold;
  204. margin-bottom: 16px;
  205. }
  206. }
  207. .level-3-item {
  208. .group-menu {
  209. margin-bottom: 10px;
  210. }
  211. .level-3-group-title {
  212. font-size: 14px;
  213. color: rgba(255, 255, 255, .7);
  214. line-height: 24px;
  215. margin-left: 3px;
  216. margin-bottom: 14px;
  217. margin-top: 14px;
  218. }
  219. .menu-item {
  220. display: block;
  221. padding-bottom: 4px;
  222. padding-top: 6px;
  223. padding-left: 20px;
  224. font-size: 14px;
  225. color: @sidebar-dark-text-color;
  226. position: relative;
  227. cursor: pointer;
  228. &:hover, &.active {
  229. text-decoration: none;
  230. &::after {
  231. position: absolute;
  232. content: '';
  233. width: 6px;
  234. height: 6px;
  235. border-radius: 50%;
  236. position: absolute;
  237. left: 0;
  238. top: 50%;
  239. transform: translate(4px, -50%);
  240. background-color: @primary-color;
  241. overflow: hidden;
  242. }
  243. }
  244. &:hover {
  245. color: @sidebar-dark-hover-text-color;
  246. }
  247. &.active {
  248. color: @sidebar-dark-active-text-color;
  249. }
  250. }
  251. > .menu-item {
  252. margin-bottom: 25px;
  253. }
  254. & + & {
  255. > .menu-item {
  256. margin-top: 25px;
  257. }
  258. }
  259. }
  260. .level-2-menu-collapse {
  261. position: absolute;
  262. height: 66px;
  263. width: 12px;
  264. top: 50%;
  265. right: -12px;
  266. cursor: pointer;
  267. .level-2-menu-collapse-bg {
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. width: 100%;
  272. height: 100%;
  273. border-bottom: 8px solid transparent;
  274. border-right: none;
  275. border-left: 12px solid #EBEBEB;
  276. border-top: 8px solid transparent;
  277. z-index: 1;
  278. }
  279. .level-2-menu-collapse-icon {
  280. position: absolute;
  281. top: 0;
  282. left: 0;
  283. width: 100%;
  284. height: 100%;
  285. z-index: 2;
  286. background-color: transparent;
  287. color: #C1C1C1;
  288. }
  289. &:hover {
  290. .level-2-menu-collapse-bg {
  291. border-left-color: #DEDEDE;
  292. }
  293. .level-2-menu-collapse-icon {
  294. color: #888;
  295. }
  296. }
  297. }
  298. </style>