index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div :class="{ 'has-logo': showLogo }">
  3. <div class="sidebar_box_bottom">
  4. <div class="arrow-icon_left" @click="arrowBack" @mousedown="handleMouseDown" @mouseup="handleMouseUp">
  5. <el-icon size="60" :color="getShowLeft ? '#0077fa' : 'rgb(0, 51, 115)'">
  6. <ArrowLeft />
  7. </el-icon>
  8. <div class="white_box_left">
  9. <el-icon size="30" :color="getShowLeft ? '#ffffff' : 'rgb(87, 94, 113)'">
  10. <ArrowLeftBold />
  11. </el-icon>
  12. </div>
  13. <div class="white_box_left_il">
  14. <el-icon size="22" :color="getShowLeft ? 'rgb(25, 148, 219)' : 'rgb(10, 61, 105)'">
  15. <CaretLeft />
  16. </el-icon>
  17. </div>
  18. </div>
  19. <div class="tag-style" ref="tagBox">
  20. <div class="menu_bottom_box" ref="scrollWrapper">
  21. <div class="item_box_sidebar" v-for="(item, index) in filteredArray" :key="item.path + index" :id="item.path">
  22. <div @click="goBack(item.path)">
  23. <div class="img_box_item" :class="getPathUrl(item.path) ? 'activate_img_sidebar' : ''">
  24. <svg class="energy_box_icon" aria-hidden="true">
  25. <defs>
  26. <linearGradient id="myGradient" x1="0%" y1="100%" x2="0%" y2="0%">
  27. <stop offset="0%" stop-color="rgb(20, 188, 244)" />
  28. <stop offset="4%" stop-color="rgba(184, 225, 239, 1)" />
  29. <stop offset="100%" stop-color="#ffffff" />
  30. </linearGradient>
  31. <linearGradient id="activate_Gradient" x1="0%" y1="100%" x2="0%" y2="0%">
  32. <stop offset="0%" stop-color="#b68231" />
  33. <stop offset="1%" stop-color="rgb(182, 130, 49)" />
  34. <stop offset="100%" stop-color="#ffffff" />
  35. </linearGradient>
  36. </defs>
  37. <use :xlink:href="iconName(item.meta.icon)"
  38. :fill="getPathUrl(item.path) ? `url('#activate_Gradient')` : `url('#myGradient')`" />
  39. </svg>
  40. </div>
  41. <span class="title_sidebar">{{ item.meta.title }}</span>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="arrow-icon_right" @click="arrowForward" @mousedown="handleMouseDownRight"
  47. @mouseup="handleMouseUpRight">
  48. <el-icon size="60" :color="getShowRight ? '#0077fa' : 'rgb(0, 51, 115)'">
  49. <ArrowRight />
  50. </el-icon>
  51. <div class="white_box">
  52. <el-icon size="30" :color="getShowRight ? '#ffffff' : 'rgb(87, 94, 113)'">
  53. <ArrowRightBold />
  54. </el-icon>
  55. </div>
  56. <div class="white_box_il">
  57. <el-icon size="22" :color="getShowRight ? 'rgb(25, 148, 219)' : 'rgb(10, 61, 105)'">
  58. <CaretRight />
  59. </el-icon>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script setup>
  66. import SidebarItem from './SidebarItem'
  67. import variables from '@/assets/styles/variables.module.scss'
  68. import useAppStore from '@/store/modules/app'
  69. import useSettingsStore from '@/store/modules/settings'
  70. import usePermissionStore from '@/store/modules/permission'
  71. const tabScroll = ref(0); // 移动的距离
  72. const showButton = ref(false); // 标签左右两侧箭头是否显示
  73. const tagBox = ref(null)
  74. const scrollWrapper = ref(null)
  75. const route = useRoute();
  76. const router = useRouter();
  77. const appStore = useAppStore()
  78. const settingsStore = useSettingsStore()
  79. const permissionStore = usePermissionStore()
  80. const sidebarRouters = computed(() => permissionStore.sidebarRouters);
  81. const filteredArray = ref([])
  82. sidebarRouters.value.forEach((item) => {
  83. if (item.redirect == "noRedirect") {
  84. filteredArray.value = item.children.filter(obj => obj.hasOwnProperty('meta'));
  85. }
  86. })
  87. const showLogo = computed(() => settingsStore.sidebarLogo);
  88. const sideTheme = computed(() => settingsStore.sideTheme);
  89. const theme = computed(() => settingsStore.theme);
  90. const isCollapse = computed(() => !appStore.sidebar.opened);
  91. const getShowLeft = computed(() => {
  92. if (tabScroll.value == 0) {
  93. return false
  94. } else {
  95. return true
  96. }
  97. });
  98. const getShowRight = computed(() => {
  99. // 内容的宽度
  100. if (scrollWrapper.value) {
  101. let navSize = scrollWrapper.value.scrollWidth;
  102. let boxWidth = tagBox.value.scrollWidth
  103. let width = navSize - boxWidth
  104. if (tabScroll.value == width) {
  105. return false
  106. } else {
  107. return true
  108. }
  109. }
  110. });
  111. // 获取菜单背景色
  112. const getMenuBackground = computed(() => {
  113. if (settingsStore.isDark) {
  114. return 'var(--sidebar-bg)';
  115. }
  116. return sideTheme.value === 'theme-dark' ? variables.menuBg : variables.menuLightBg;
  117. });
  118. // 获取菜单文字颜色
  119. const getMenuTextColor = computed(() => {
  120. if (settingsStore.isDark) {
  121. return 'var(--sidebar-text)';
  122. }
  123. return sideTheme.value === 'theme-dark' ? variables.menuText : variables.menuLightText;
  124. });
  125. function getPathUrl(pathUrl) {
  126. const { meta, path } = route;
  127. let arrUrl = path.split("/system/")
  128. let arril = ''
  129. if (arrUrl.length > 1) {
  130. arril = arrUrl[1];
  131. } else {
  132. arril = arrUrl[0];
  133. }
  134. if (arril == '/index' && pathUrl == '/') {
  135. return true
  136. } else {
  137. if (arril == pathUrl) {
  138. return true
  139. }
  140. }
  141. }
  142. function iconName(iconClass) {
  143. return `#icon-${iconClass}`
  144. }
  145. function goBack(event) {
  146. let path = '/system/' + event
  147. if (event == "/") {
  148. router.push("/index");
  149. } else {
  150. router.push({ path: path || "/" });
  151. }
  152. }
  153. const timeTag = ref(null)
  154. const isLongPress = ref(false);
  155. // 向右
  156. function arrowBack() {
  157. if (tabScroll.value > 0 && !isLongPress.value) {
  158. let diffWidth = tabScroll.value - 100;
  159. if (diffWidth > 100) {
  160. tabScroll.value = diffWidth;
  161. } else {
  162. tabScroll.value = 0;// 否则移动到开始位置
  163. }
  164. scrollWrapper.value.scrollLeft = tabScroll.value
  165. }
  166. }
  167. function handleMouseDown() {
  168. timeTag.value = setInterval(() => {
  169. isLongPress.value = true;
  170. handleLongPress();
  171. }, 200)
  172. }
  173. function handleMouseUp() {
  174. clearInterval(timeTag.value)
  175. if (!isLongPress.value) {
  176. arrowBack(); // 如果不是长按,则处理点击逻辑
  177. }
  178. tabScroll.value = tabScroll.value + 100
  179. isLongPress.value = false
  180. }
  181. function handleLongPress() {
  182. if (tabScroll.value > 0) {
  183. let diffWidth = tabScroll.value - 10;
  184. if (diffWidth > 10) {
  185. tabScroll.value = diffWidth;
  186. } else {
  187. tabScroll.value = 0;// 否则移动到开始位置
  188. }
  189. scrollWrapper.value.scrollLeft = tabScroll.value
  190. }
  191. }
  192. // 向左
  193. const timeTagil = ref(null)
  194. const isLongPressil = ref(false);
  195. function arrowForward() {
  196. let scrollWidth = scrollWrapper.value.scrollWidth; //内容宽度
  197. let boxWidth = tagBox.value.scrollWidth
  198. if (tabScroll.value < (scrollWidth - boxWidth) && !isLongPressil.value) {
  199. let diffWidth = tabScroll.value + 100;
  200. if (diffWidth < scrollWidth) {
  201. if ((diffWidth + 100) > (scrollWidth - boxWidth)) {
  202. tabScroll.value = (scrollWidth - boxWidth)
  203. } else {
  204. tabScroll.value = diffWidth
  205. }
  206. } else {
  207. tabScroll.value = scrollWidth
  208. }
  209. scrollWrapper.value.scrollLeft = tabScroll.value
  210. }
  211. }
  212. function handleMouseDownRight() {
  213. timeTagil.value = setInterval(() => {
  214. isLongPressil.value = true;
  215. handleLongPressil();
  216. }, 200)
  217. }
  218. function handleMouseUpRight() {
  219. clearInterval(timeTagil.value)
  220. if (!isLongPressil.value) {
  221. arrowForward(); // 如果不是长按,则处理点击逻辑
  222. }
  223. tabScroll.value = tabScroll.value - 100
  224. isLongPressil.value = false
  225. }
  226. function handleLongPressil() {
  227. let scrollWidth = scrollWrapper.value.scrollWidth; //内容宽度
  228. let boxWidth = tagBox.value.scrollWidth
  229. if (tabScroll.value < (scrollWidth - boxWidth)) {
  230. let diffWidth = tabScroll.value + 10;
  231. if (diffWidth < scrollWidth) {
  232. if ((diffWidth + 10) > (scrollWidth - boxWidth)) {
  233. tabScroll.value = (scrollWidth - boxWidth)
  234. } else {
  235. tabScroll.value = diffWidth
  236. }
  237. } else {
  238. tabScroll.value = scrollWidth
  239. }
  240. scrollWrapper.value.scrollLeft = tabScroll.value
  241. }
  242. }
  243. // 生命周期
  244. onMounted(() => {
  245. const { meta, path } = route;
  246. let arrUrl = path.split("/system/")
  247. let arril = ''
  248. if (arrUrl.length > 1) {
  249. arril = arrUrl[1];
  250. } else {
  251. arril = arrUrl[0];
  252. }
  253. const targetElement = document.getElementById(`${arril}`);
  254. if (targetElement) {
  255. targetElement.scrollIntoView({ behavior: 'auto' });
  256. }
  257. nextTick(() => {
  258. let scrollTime = setInterval(() => {
  259. let navSize = scrollWrapper.value.scrollLeft;
  260. let boxWidth = tagBox.value.scrollLeft
  261. tabScroll.value = navSize;
  262. clearInterval(scrollTime)
  263. })
  264. })
  265. });
  266. </script>
  267. <style lang="scss" scoped>
  268. .el-menu--horizontal {
  269. justify-content: center;
  270. }
  271. .has-logo {
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. }
  276. .sidebar_box_bottom {
  277. position: relative;
  278. width: fit-content;
  279. padding: 0px 30px;
  280. max-width: 50%;
  281. display: flex;
  282. align-items: center;
  283. }
  284. .arrow-icon_left {
  285. position: absolute;
  286. bottom: 0;
  287. left: -10px;
  288. cursor: pointer;
  289. }
  290. .white_box_left {
  291. position: absolute;
  292. top: 15px;
  293. left: 12px;
  294. z-index: -1;
  295. }
  296. .white_box_left_il {
  297. position: absolute;
  298. top: 19px;
  299. left: 23px;
  300. z-index: -1;
  301. }
  302. .arrow-icon_right {
  303. position: absolute;
  304. bottom: 0;
  305. right: -10px;
  306. cursor: pointer;
  307. }
  308. .white_box {
  309. position: absolute;
  310. top: 15px;
  311. right: 13px;
  312. z-index: -1;
  313. }
  314. .white_box_il {
  315. position: absolute;
  316. top: 19px;
  317. right: 23px;
  318. z-index: -1;
  319. }
  320. .sidebar_box_bottom::after {
  321. content: '';
  322. position: absolute;
  323. top: 20px;
  324. left: 0;
  325. right: 0;
  326. bottom: 0;
  327. z-index: -1;
  328. background-image: linear-gradient(to bottom, rgb(10 54 113 / 93%) 0%, rgb(0 93 191 / 70%) 100%);
  329. clip-path: polygon(0 100%, 8% 0, 92% 0, 100% 100%);
  330. }
  331. .tag-style {
  332. display: flex;
  333. align-items: center;
  334. overflow: hidden;
  335. pointer-events: all;
  336. cursor: pointer;
  337. position: relative;
  338. }
  339. .menu_bottom_box {
  340. height: 75px;
  341. display: flex;
  342. align-items: flex-end;
  343. width: 100%;
  344. overflow-x: auto;
  345. scrollbar-width: none;
  346. -ms-overflow-style: none;
  347. transition: scroll-left 0.5s ease;
  348. }
  349. .item_box_sidebar {
  350. flex: none;
  351. cursor: pointer;
  352. position: relative;
  353. display: flex;
  354. flex-direction: column;
  355. align-items: center;
  356. padding: 4px 0px;
  357. width: 100px;
  358. }
  359. .img_box_item {
  360. cursor: pointer;
  361. position: absolute;
  362. bottom: 25px;
  363. width: 60px;
  364. height: 50px;
  365. background: url("@/assets/images/pedestal.png");
  366. background-size: cover;
  367. display: flex;
  368. justify-content: center;
  369. align-items: flex-start;
  370. }
  371. .activate_img_sidebar {
  372. background: url("@/assets/images/pedestalActivate.png");
  373. background-size: cover;
  374. }
  375. .title_sidebar {
  376. color: #fff;
  377. font-size: 14px;
  378. user-select: none;
  379. }
  380. .energy_box_icon {
  381. width: 30px;
  382. height: 30px;
  383. position: relative;
  384. vertical-align: -2px;
  385. }
  386. </style>