BottomDock.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <div class="dock-wrapper"
  3. ref="dockWrapper"
  4. :class="[
  5. autoHide ? 'is-auto-hide' : 'is-always-show',
  6. customClass,
  7. { 'is-expanded': dockExpanded }
  8. ]"
  9. :style="dockStyles"
  10. @mouseleave="handleDockLeave">
  11. <div class="nav-arrow left-arrow" :class="{ 'is-disabled': !canScrollLeft, 'is-active': canScrollLeft }"
  12. @click="scrollList(-1)">
  13. <img v-if="canScrollLeft" src="@/assets/main/main-right.png" class="arrow-img left-facing" />
  14. <img v-else src="@/assets/main/main-left.png" class="arrow-img" />
  15. </div>
  16. <div class="dock-list-container" ref="listContainer" @scroll="checkScrollState">
  17. <div class="dock-list">
  18. <div v-for="(item, index) in dockItems" :key="index" class="dock-item"
  19. :class="{
  20. 'is-active': activeIndex === index,
  21. [`theme-${item.theme}`]: item.theme,
  22. 'is-breathing': waveAnimation
  23. }"
  24. :style="waveAnimation ? { animationDelay: `${index * 0.15}s` } : {}"
  25. @click="handleSelect(index, item)"
  26. @mouseenter="hoverIndex = index"
  27. @mouseleave="hoverIndex = null"
  28. >
  29. <div class="item-icon">
  30. <img v-if="item.imgUrl"
  31. :src="(activeIndex === index || hoverIndex === index) && item.activeImgUrl ? item.activeImgUrl : item.imgUrl"
  32. class="custom-icon" />
  33. <i v-else :class="item.iconClass"></i>
  34. </div>
  35. <div class="item-label">{{ item.label }}</div>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="nav-arrow right-arrow" :class="{ 'is-disabled': !canScrollRight, 'is-active': canScrollRight }"
  40. @click="scrollList(1)">
  41. <img v-if="canScrollRight" src="@/assets/main/main-right.png" class="arrow-img" />
  42. <img v-else src="@/assets/main/main-left.png" class="arrow-img left-facing" />
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. name: 'BottomDock',
  49. props: {
  50. // 是否自动隐藏 (默认 true: 悬浮升起; false: 常驻显示)
  51. autoHide: {
  52. type: Boolean,
  53. default: true
  54. },
  55. // 距离屏幕底部的偏移量 (单位 px,正数代表往上抬高)
  56. bottomOffset: {
  57. type: Number,
  58. default: 0
  59. },
  60. // 允许外部传入的自定义容器样式 (如背景色、宽度等)
  61. customStyle: {
  62. type: Object,
  63. default: () => ({})
  64. },
  65. // 允许外部传入自定义 class (支持字符串、数组、对象)
  66. customClass: {
  67. type: [String, Array, Object],
  68. default: ''
  69. },
  70. // 是否开启波浪呼吸动画
  71. waveAnimation: {
  72. type: Boolean,
  73. default: false
  74. }
  75. },
  76. data() {
  77. return {
  78. activeIndex: -1,
  79. hoverIndex: null,
  80. dockExpanded: false,
  81. canScrollLeft: false,
  82. canScrollRight: true,
  83. dockItems: [
  84. {
  85. label: '首页',
  86. imgUrl: require('@/assets/main/dock-home.png'),
  87. activeImgUrl: require('@/assets/main/dock-home-hover.png'),
  88. route: '/home',
  89. theme: 'blue',
  90. },
  91. {
  92. label: '状态监控',
  93. imgUrl: require('@/assets/main/dock-surve.png'),
  94. activeImgUrl: require('@/assets/main/dock-surve-hover.png'),
  95. route: '/surve',
  96. theme: 'blue',
  97. },
  98. {
  99. label: '勤务管理',
  100. imgUrl: require('@/assets/main/dock-security.png'),
  101. activeImgUrl: require('@/assets/main/dock-security-hover.png'),
  102. route: '/security',
  103. theme: 'gold',
  104. },
  105. {
  106. label: '干线协调',
  107. imgUrl: require('@/assets/main/dock-coor.png'),
  108. activeImgUrl: require('@/assets/main/dock-coor-hover.png'),
  109. route: '/trunk',
  110. theme: 'blue',
  111. },
  112. {
  113. label: '数据分析',
  114. imgUrl: require('@/assets/main/dock-watch.png'),
  115. activeImgUrl: require('@/assets/main/dock-watch-hover.png'),
  116. route: '/watch',
  117. theme: 'blue',
  118. },
  119. {
  120. label: '系统设置',
  121. imgUrl: require('@/assets/main/dock-setting.png'),
  122. activeImgUrl: require('@/assets/main/dock-setting-hover.png'),
  123. route: '/setting',
  124. theme: 'blue',
  125. },
  126. {
  127. label: '测试1',
  128. imgUrl: require('@/assets/main/dock-home.png'),
  129. theme: 'blue',
  130. },
  131. {
  132. label: '测试2',
  133. imgUrl: require('@/assets/main/dock-surve.png'),
  134. theme: 'blue',
  135. },
  136. {
  137. label: '测试3',
  138. imgUrl: require('@/assets/main/dock-security.png'),
  139. theme: 'blue',
  140. },
  141. ]
  142. };
  143. },
  144. computed: {
  145. // 动态计算 CSS 变量和合并自定义样式
  146. dockStyles() {
  147. // 统一只传一个基础 bottom 偏移量,动画交由 CSS transform 处理
  148. return {
  149. '--dock-bottom': `${this.bottomOffset}px`,
  150. ...this.customStyle
  151. };
  152. }
  153. },
  154. watch: {
  155. $route() {
  156. this.updateActiveIndexByRoute();
  157. }
  158. },
  159. created() {
  160. this.updateActiveIndexByRoute();
  161. },
  162. mounted() {
  163. this.$nextTick(() => {
  164. this.checkScrollState();
  165. window.addEventListener('resize', this.checkScrollState);
  166. if (this.autoHide) {
  167. document.addEventListener('mousemove', this.handleGlobalMouseMove);
  168. }
  169. });
  170. },
  171. beforeDestroy() {
  172. window.removeEventListener('resize', this.checkScrollState);
  173. document.removeEventListener('mousemove', this.handleGlobalMouseMove);
  174. },
  175. methods: {
  176. updateActiveIndexByRoute() {
  177. const currentPath = this.$route?.path || '';
  178. const matchIndex = this.dockItems.findIndex(item => {
  179. return item.route && currentPath.startsWith(item.route);
  180. });
  181. if (matchIndex !== -1) {
  182. this.activeIndex = matchIndex;
  183. }
  184. },
  185. handleSelect(index, item) {
  186. if (this.activeIndex === index) return;
  187. this.activeIndex = index;
  188. if (item.route && this.$router) {
  189. this.$router.push(item.route).catch(err => {
  190. if (err.name !== 'NavigationDuplicated') {
  191. console.error('路由跳转失败:', err);
  192. }
  193. });
  194. }
  195. this.$emit('change', item);
  196. },
  197. checkScrollState() {
  198. const container = this.$refs.listContainer;
  199. if (!container) return;
  200. this.canScrollLeft = container.scrollLeft > 0;
  201. this.canScrollRight = Math.ceil(container.scrollLeft + container.clientWidth) < container.scrollWidth;
  202. },
  203. handleGlobalMouseMove(e) {
  204. if (!this.autoHide || this.dockExpanded) return;
  205. const el = this.$refs.dockWrapper;
  206. if (!el) return;
  207. const rect = el.getBoundingClientRect();
  208. // 发光线区域:居中,宽度与 CSS clamp(150px, 20vw, 250px) 一致
  209. const lineWidth = Math.min(250, Math.max(150, window.innerWidth * 0.2));
  210. const centerX = window.innerWidth / 2;
  211. const left = centerX - lineWidth / 2;
  212. const right = centerX + lineWidth / 2;
  213. // 垂直:dock 可见顶部往上延伸 30px(与 ::after 热区一致)
  214. if (e.clientX >= left && e.clientX <= right && e.clientY >= rect.top - 30) {
  215. this.dockExpanded = true;
  216. }
  217. },
  218. handleDockLeave() {
  219. this.dockExpanded = false;
  220. },
  221. scrollList(direction) {
  222. if (direction === -1 && !this.canScrollLeft) return;
  223. if (direction === 1 && !this.canScrollRight) return;
  224. const container = this.$refs.listContainer;
  225. const scrollAmount = 130;
  226. if (container) {
  227. container.scrollBy({
  228. left: direction * scrollAmount,
  229. behavior: 'smooth'
  230. });
  231. }
  232. }
  233. }
  234. };
  235. </script>
  236. <style scoped>
  237. /* ================= 整体容器布局 ================= */
  238. .dock-wrapper {
  239. display: flex !important;
  240. flex-direction: row !important;
  241. align-items: center;
  242. justify-content: center;
  243. width: 100%;
  244. height: 160px;
  245. position: fixed;
  246. left: 0;
  247. bottom: var(--dock-bottom, 0px);
  248. z-index: 9999;
  249. transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  250. background: linear-gradient(to top, rgba(0, 20, 30, 0.8) 0%, rgba(0, 20, 30, 0.01) 100%);
  251. pointer-events: auto !important;
  252. }
  253. /* === 状态 A:自动隐藏 === */
  254. .dock-wrapper.is-auto-hide {
  255. transform: translateY(calc(100% - clamp(15px, 4vh, 20px)));
  256. pointer-events: none;
  257. }
  258. .dock-wrapper.is-auto-hide.is-expanded {
  259. transform: translateY(0);
  260. pointer-events: auto;
  261. }
  262. /* 中间触发热区:只覆盖发光线范围,pointer-events 始终开启 */
  263. .dock-wrapper.is-auto-hide::after {
  264. content: '';
  265. position: absolute;
  266. top: -30px;
  267. left: 50%;
  268. transform: translateX(-50%);
  269. width: clamp(150px, 20vw, 250px);
  270. height: 60px;
  271. background: transparent;
  272. pointer-events: auto;
  273. }
  274. /* 发光的指示线自适应 */
  275. .dock-wrapper.is-auto-hide::before {
  276. content: '';
  277. position: absolute;
  278. top: 0;
  279. left: 50%;
  280. transform: translateX(-50%);
  281. /* 宽度和厚度也做一点自适应,小屏自动变短点 */
  282. width: clamp(150px, 20vw, 250px);
  283. height: clamp(3px, 0.5vh, 5px);
  284. background: rgba(0, 229, 255, 0.6);
  285. box-shadow: 0 0 10px rgba(0, 229, 255, 0.8);
  286. border-radius: 4px;
  287. transition: opacity 0.3s;
  288. pointer-events: auto;
  289. }
  290. .dock-wrapper.is-auto-hide.is-expanded::before {
  291. opacity: 0;
  292. }
  293. /* === 状态 B:常驻显示 === */
  294. .dock-wrapper.is-always-show {
  295. transform: translateY(0);
  296. }
  297. .dock-wrapper.is-always-show::before,
  298. .dock-wrapper.is-always-show::after {
  299. display: none;
  300. }
  301. /* ================= 内部列表与滚动容器 ================= */
  302. .dock-list-container {
  303. width: 750px;
  304. height: 160px;
  305. overflow-x: auto;
  306. overflow-y: hidden;
  307. white-space: nowrap;
  308. -ms-overflow-style: none;
  309. scrollbar-width: none;
  310. }
  311. .dock-list-container::-webkit-scrollbar {
  312. display: none;
  313. }
  314. .dock-list {
  315. display: flex !important;
  316. flex-direction: row !important;
  317. flex-wrap: nowrap !important;
  318. align-items: flex-end;
  319. height: 100%;
  320. width: max-content;
  321. min-width: 100%;
  322. padding-bottom: 20px;
  323. gap: 30px;
  324. }
  325. /* ================= 左右控制箭头 ================= */
  326. .nav-arrow {
  327. flex-shrink: 0;
  328. width: 40px;
  329. height: 40px;
  330. display: flex;
  331. justify-content: center;
  332. align-items: center;
  333. transition: all 0.3s;
  334. margin: 0 15px;
  335. background: transparent !important;
  336. border: none !important;
  337. }
  338. .arrow-img {
  339. width: 100%;
  340. height: 100%;
  341. object-fit: contain;
  342. }
  343. .left-facing {
  344. transform: rotate(180deg);
  345. }
  346. .nav-arrow.is-active {
  347. cursor: pointer;
  348. }
  349. .nav-arrow.is-active:hover .arrow-img {
  350. transform: scale(1.1);
  351. filter: drop-shadow(0 0 10px rgba(0, 229, 255, 0.8));
  352. }
  353. .nav-arrow.left-arrow.is-active:hover .arrow-img.left-facing {
  354. transform: rotate(180deg) scale(1.1);
  355. }
  356. .nav-arrow.is-disabled {
  357. cursor: not-allowed;
  358. opacity: 0.6;
  359. }
  360. /* ================= 单个导航项 ================= */
  361. .dock-item {
  362. flex-shrink: 0;
  363. position: relative;
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. justify-content: flex-end;
  368. cursor: pointer;
  369. width: 100px;
  370. height: 90px;
  371. transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  372. }
  373. .item-icon {
  374. font-size: 32px;
  375. color: #a0cfff;
  376. z-index: 3;
  377. margin-bottom: 5px;
  378. transition: all 0.3s;
  379. }
  380. .item-label {
  381. color: #c0c4cc;
  382. font-size: 14px;
  383. text-align: center;
  384. transition: all 0.3s;
  385. letter-spacing: 1px;
  386. }
  387. /* ================= 交互状态:悬浮与选中 ================= */
  388. .dock-item:hover {
  389. transform: translateY(-15px) scale(1.15);
  390. }
  391. .dock-item:hover .item-icon,
  392. .dock-item.is-active .item-icon {
  393. color: #ffffff;
  394. text-shadow: 0 0 15px #00e5ff;
  395. }
  396. .dock-item:hover .item-label,
  397. .dock-item.is-active .item-label {
  398. color: #ffffff;
  399. font-weight: bold;
  400. text-shadow: 0 0 8px #00e5ff;
  401. }
  402. .dock-item:hover .top-solid,
  403. .dock-item.is-active .top-solid {
  404. background: linear-gradient(135deg, rgba(0, 229, 255, 0.9), rgba(0, 115, 255, 0.9));
  405. box-shadow: 0 0 20px rgba(0, 229, 255, 0.6);
  406. }
  407. .dock-item.theme-gold.is-active .item-icon {
  408. color: #ffd700;
  409. text-shadow: 0 0 15px #ffaa00;
  410. }
  411. .dock-item.theme-gold.is-active .item-label {
  412. color: #ffd700;
  413. text-shadow: 0 0 8px #ffaa00;
  414. }
  415. .item-icon {
  416. z-index: 3;
  417. margin-bottom: 5px;
  418. transition: transform 0.3s ease, filter 0.3s ease;
  419. }
  420. .custom-icon {
  421. width: 88px;
  422. height: 64px;
  423. object-fit: contain;
  424. }
  425. .dock-item:hover .custom-icon,
  426. .dock-item.is-active .custom-icon {
  427. filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.8));
  428. }
  429. /* ================= 呼吸波浪动态效果 ================= */
  430. @keyframes breathing-wave {
  431. 0%, 100% {
  432. transform: translateY(0) scale(1);
  433. }
  434. 50% {
  435. transform: translateY(-8px) scale(1.08); /* 呼吸时轻微上浮和放大 */
  436. }
  437. }
  438. .dock-item.is-breathing {
  439. /* 动画周期设为 2.5s,无限循环,平滑过渡 */
  440. animation: breathing-wave 2.5s infinite ease-in-out;
  441. }
  442. /* 覆盖动画冲突:当鼠标悬浮或该项处于激活状态时,停止呼吸动画,采用原有的高亮放大效果 */
  443. .dock-item:hover,
  444. .dock-item.is-active {
  445. animation: none !important; /* 强制停止动画 */
  446. transform: translateY(-15px) scale(1.15) !important;
  447. }
  448. </style>