index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <el-scrollbar
  3. class="vab-column-bar"
  4. :class="{
  5. 'is-collapse': collapse,
  6. ['vab-column-bar-' + theme.columnStyle]: true,
  7. }"
  8. >
  9. <vab-logo style="z-index: 999" />
  10. <el-tabs v-model="tab.data" tab-position="left" @tab-click="handleTabClick">
  11. <template v-for="(item, index) in routes" :key="index + item.name">
  12. <el-tab-pane :name="item.name">
  13. <template #label>
  14. <div
  15. class="vab-column-grid"
  16. :class="{
  17. ['vab-column-grid-' + theme.columnStyle]: true,
  18. }"
  19. :title="translate(item.meta.title)"
  20. >
  21. <div>
  22. <vab-icon v-if="item.meta.icon" :icon="item.meta.icon" :is-custom-svg="item.meta.isCustomSvg" />
  23. <span v-if="translate(item.meta.title).length < 4">
  24. {{ translate(item.meta.title) }}
  25. </span>
  26. <span v-else style="font-size: var(--el-font-size-extra-small); zoom: 0.88">
  27. {{ translate(item.meta.title) }}
  28. </span>
  29. </div>
  30. </div>
  31. </template>
  32. </el-tab-pane>
  33. </template>
  34. </el-tabs>
  35. <el-menu
  36. ref="menuRef"
  37. background-color="var(--el-menu-background-color-second)"
  38. :default-active="activeMenu.data"
  39. :default-openeds="defaultOpeneds"
  40. mode="vertical"
  41. :unique-opened="uniqueOpened"
  42. >
  43. <vab-menu v-for="item in partialRoutes" :key="item.path" :item="item" />
  44. </el-menu>
  45. <div class="float-fold">
  46. <vab-fold fold="contract-left-line" unfold="contract-right-line" />
  47. </div>
  48. </el-scrollbar>
  49. </template>
  50. <script lang="ts" setup>
  51. import { defaultOpeneds, isHashRouterMode, openFirstMenu, uniqueOpened } from '/@/config'
  52. import { translate } from '/@/i18n'
  53. import { useRoutesStore } from '/@/store/modules/routes'
  54. import { useSettingsStore } from '/@/store/modules/settings'
  55. import { isExternal } from '/@/utils/validate'
  56. defineOptions({
  57. name: 'VabColumnBar',
  58. })
  59. const route = useRoute()
  60. const router = useRouter()
  61. const settingsStore = useSettingsStore()
  62. const { collapse, device, theme } = storeToRefs(settingsStore)
  63. const { foldSideBar, openSideBar } = settingsStore
  64. const routesStore = useRoutesStore()
  65. const {
  66. getTab: tab,
  67. getTabMenu: tabMenu,
  68. getActiveMenu: activeMenu,
  69. getRoutes: routes,
  70. getPartialRoutes: partialRoutes,
  71. } = storeToRefs(routesStore)
  72. const menuRef = ref<any>(null)
  73. let timer: ReturnType<typeof setInterval>
  74. const setDefaultOpeneds = () => {
  75. timer = setTimeout(() => {
  76. defaultOpeneds.forEach((item: string) => {
  77. try {
  78. menuRef.value.open(item)
  79. } catch {
  80. /* empty */
  81. }
  82. })
  83. }, 0)
  84. }
  85. const handleTabClick = () => {
  86. nextTick(() => {
  87. if (tabMenu.value.meta.target === '_blank') {
  88. if (route.path !== tabMenu.value.path) {
  89. isHashRouterMode ? window.open(`#${tabMenu.value.path}`) : window.open(tabMenu.value.path)
  90. router.push('/redirect')
  91. }
  92. } else if (isExternal(tabMenu.value.path)) {
  93. window.open(tabMenu.value.path)
  94. router.push('/redirect')
  95. } else if (openFirstMenu) router.push(tabMenu.value.redirect || tabMenu.value)
  96. setDefaultOpeneds()
  97. })
  98. }
  99. onMounted(() => {
  100. nextTick(() => {
  101. setDefaultOpeneds()
  102. if (theme.value.layout === 'column')
  103. watch(
  104. route,
  105. () => {
  106. const foldUnfold: any = document.querySelector('.left-panel .fold-unfold')
  107. const floatFold: any = document.querySelector('.float-fold')
  108. if (route.meta.noColumn && theme.value.layout === 'column') {
  109. if (device.value !== 'mobile') foldSideBar()
  110. if (foldUnfold) foldUnfold.style = 'opacity:0'
  111. if (floatFold) floatFold.style = 'opacity:0'
  112. } else {
  113. if (device.value !== 'mobile') openSideBar()
  114. if (foldUnfold) foldUnfold.style = 'opacity:1'
  115. if (floatFold) floatFold.style = 'opacity:1'
  116. }
  117. },
  118. {
  119. immediate: true,
  120. }
  121. )
  122. })
  123. })
  124. onBeforeUnmount(() => {
  125. if (timer) clearTimeout(timer)
  126. })
  127. </script>
  128. <style lang="scss" scoped>
  129. @mixin active {
  130. &:hover {
  131. color: var(--el-color-primary);
  132. background-color: var(--el-color-primary-light-9);
  133. i,
  134. svg {
  135. color: var(--el-color-primary);
  136. }
  137. }
  138. &.is-active {
  139. color: var(--el-color-primary);
  140. background-color: var(--el-color-primary-light-9);
  141. }
  142. }
  143. .vab-column-bar {
  144. position: fixed;
  145. top: 0;
  146. bottom: 0;
  147. left: 0;
  148. width: var(--el-left-menu-width);
  149. overflow: hidden;
  150. background: var(--el-color-white);
  151. border-right: 1px solid var(--el-border-color);
  152. &-vertical,
  153. &-card,
  154. &-arrow {
  155. :deep() {
  156. .el-tabs + .el-menu {
  157. left: var(--el-left-menu-width-min);
  158. width: calc(var(--el-left-menu-width) - var(--el-left-menu-width-min));
  159. border: 0;
  160. }
  161. }
  162. }
  163. &-horizontal,
  164. &-semicircle {
  165. .float-fold {
  166. left: 26.5px;
  167. }
  168. :deep() {
  169. .vab-logo-column {
  170. .logo {
  171. width: calc(var(--el-left-menu-width-min) * 1.4) !important;
  172. }
  173. .title {
  174. left: calc(var(--el-left-menu-width-min) * 1.4) !important;
  175. width: calc(var(--el-left-menu-width) - calc(var(--el-left-menu-width-min) * 1.4) - 1px);
  176. }
  177. }
  178. .el-tabs + .el-menu {
  179. left: calc(var(--el-left-menu-width-min) * 1.4);
  180. width: calc(var(--el-left-menu-width) - var(--el-left-menu-width-min) * 1.4);
  181. border: 0;
  182. }
  183. }
  184. }
  185. &-card {
  186. :deep() {
  187. .el-tabs {
  188. .el-tabs__item {
  189. padding: 5px !important;
  190. .vab-column-grid {
  191. width: calc(var(--el-left-menu-width-min) - 12px) !important;
  192. height: calc(var(--el-left-menu-width-min) - 10px) !important;
  193. margin-left: 2px;
  194. border-radius: var(--el-border-radius-base);
  195. &:hover {
  196. background: var(--el-color-primary);
  197. }
  198. }
  199. &.is-active {
  200. background: transparent !important;
  201. .vab-column-grid {
  202. background: var(--el-color-primary);
  203. }
  204. }
  205. }
  206. }
  207. .el-tabs + .el-menu {
  208. left: calc(var(--el-left-menu-width-min) + 10px);
  209. width: calc(var(--el-left-menu-width) - var(--el-left-menu-width-min) - 20px);
  210. }
  211. .el-sub-menu .el-sub-menu__title,
  212. .el-menu-item {
  213. min-width: 180px;
  214. margin-bottom: 5px;
  215. border-radius: var(--el-border-radius-base);
  216. }
  217. }
  218. }
  219. &-arrow {
  220. :deep() {
  221. .el-tabs {
  222. .el-tabs__item {
  223. &.is-active {
  224. background: transparent !important;
  225. .vab-column-grid {
  226. background: transparent !important;
  227. &:after {
  228. position: absolute;
  229. right: -1px;
  230. width: 0;
  231. height: 0;
  232. overflow: hidden;
  233. content: '';
  234. border-color: transparent var(--el-color-white) transparent transparent;
  235. border-style: solid dashed dashed;
  236. border-width: 8px;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. .el-tabs + .el-menu {
  243. left: calc(var(--el-left-menu-width-min) + 10px);
  244. width: calc(var(--el-left-menu-width) - var(--el-left-menu-width-min) - 20px);
  245. }
  246. .el-sub-menu .el-sub-menu__title,
  247. .el-menu-item {
  248. min-width: 180px;
  249. margin-bottom: 5px;
  250. border-radius: var(--el-border-radius-base);
  251. }
  252. }
  253. }
  254. &-semicircle {
  255. :deep() {
  256. .el-tabs {
  257. .el-tabs__item {
  258. &.is-active {
  259. border-top-left-radius: 99px;
  260. border-bottom-left-radius: 99px;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. .vab-column-grid {
  267. display: flex;
  268. align-items: center;
  269. width: var(--el-left-menu-width-min);
  270. overflow: hidden;
  271. text-align: center;
  272. text-overflow: ellipsis;
  273. word-break: break-all;
  274. white-space: nowrap;
  275. &-vertical,
  276. &-card,
  277. &-arrow {
  278. justify-content: center;
  279. height: var(--el-left-menu-width-min);
  280. > div {
  281. svg,
  282. [class*='ri-'] {
  283. display: block;
  284. height: 20px;
  285. }
  286. }
  287. }
  288. &-horizontal,
  289. &-semicircle {
  290. justify-content: left;
  291. width: calc(var(--el-left-menu-width-min) * 1.4);
  292. height: calc(var(--el-left-menu-width-min) / 1.4);
  293. padding-left: var(--el-padding);
  294. svg,
  295. [class*='ri-'] {
  296. margin-right: 3px;
  297. }
  298. }
  299. }
  300. :deep() {
  301. * {
  302. transition: var(--el-transition);
  303. }
  304. .el-scrollbar__wrap {
  305. overflow-x: hidden;
  306. }
  307. .el-tabs {
  308. position: fixed;
  309. z-index: 9999;
  310. .el-tabs__header.is-left {
  311. margin-right: 0 !important;
  312. .el-tabs__nav-wrap.is-left {
  313. margin-right: 0 !important;
  314. background: var(--el-menu-background-color);
  315. .el-tabs__nav-scroll {
  316. height: 100%;
  317. overflow-y: auto;
  318. &::-webkit-scrollbar {
  319. width: 0;
  320. height: 0;
  321. }
  322. }
  323. }
  324. }
  325. .el-tabs__nav {
  326. height: calc(var(--vh, 1vh) * 100 - var(--el-logo-height));
  327. background: var(--el-menu-background-color);
  328. }
  329. .el-tabs__item {
  330. height: auto;
  331. padding: 0;
  332. color: var(--el-color-white);
  333. &.is-active {
  334. margin-right: -1px;
  335. background: var(--el-color-primary);
  336. > .vab-column-grid {
  337. margin-right: 1px;
  338. }
  339. }
  340. }
  341. }
  342. .el-tabs__active-bar.is-left,
  343. .el-tabs--left .el-tabs__nav-wrap.is-left::after {
  344. display: none;
  345. }
  346. .el-menu {
  347. margin-top: 10px;
  348. border: 0;
  349. .el-menu-item,
  350. .el-sub-menu__title {
  351. height: var(--el-menu-item-height);
  352. overflow: hidden;
  353. line-height: var(--el-menu-item-height);
  354. text-overflow: ellipsis;
  355. white-space: nowrap;
  356. @include active;
  357. }
  358. }
  359. }
  360. &.is-collapse {
  361. :deep() {
  362. width: 0;
  363. }
  364. }
  365. }
  366. .float-fold {
  367. position: fixed;
  368. bottom: 13px;
  369. left: 14px;
  370. z-index: 9999;
  371. width: 34px;
  372. height: 34px;
  373. line-height: 34px;
  374. text-align: center;
  375. background: var(--el-color-primary);
  376. border-radius: var(--el-border-radius-base);
  377. :deep() {
  378. .fold-unfold,
  379. .ri-user-heart-line {
  380. font-size: var(--el-font-size-extra-large);
  381. color: var(--el-color-white);
  382. cursor: pointer;
  383. }
  384. }
  385. }
  386. </style>