bottomSideder.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <div v-if="isShowMenu == -1" class="bottom-side" :class="{ 'bottom-size-show': isShowMenu }">
  3. <div class="menu-container">
  4. <div class="menu-items">
  5. <template v-for="(menu, index) in currentParentRoute.children" :key="index">
  6. <FourBorderBg class="four-border-bg" v-if="!menu.hideMenu">
  7. <div class="vent-flex-row">
  8. <div class="parent-menu">
  9. {{ menu.name }}
  10. </div>
  11. <div class="vent-flex-row-wrap child-menu">
  12. <template v-for="(childMenu, childIndex) in menu.children" :key="childIndex">
  13. <template v-if="!childMenu.hideMenu">
  14. <template v-if="childMenu['ver'] == 1">
  15. <div class="child-menu-item" @click.stop="handleMenuClick(childMenu)">
  16. {{ childMenu.name }}
  17. </div>
  18. </template>
  19. <template v-else>
  20. <div class="child-menu-item-disabled" @click.stop="handleMenuClick(childMenu)" :style="{ backgroundColor: '#314671' }">
  21. {{ childMenu.name }}
  22. </div>
  23. </template>
  24. </template>
  25. </template>
  26. </div>
  27. </div>
  28. </FourBorderBg>
  29. </template>
  30. </div>
  31. <div class="vent-flex-row-between menu-button-group">
  32. <div class="vent-flex-row program-group">
  33. <template v-for="(programMenu, key) in menuModules" :key="key">
  34. <div
  35. v-if="!programMenu.title.startsWith('首页')"
  36. class="program-menu"
  37. :class="{ 'program-menu-active': currentParentRoute == programMenu }"
  38. @click="selectMenu($event, programMenu)"
  39. >{{ programMenu.title }}</div
  40. >
  41. </template>
  42. </div>
  43. <div class="setting-group">
  44. <SvgIcon class="icon-style" size="18" name="home" @click="geHome" />
  45. <SvgIcon class="icon-style" size="18" name="fixed" />
  46. <SvgIcon class="icon-style" size="18" name="enter" @click="closeMenu" />
  47. <!-- <SvgIcon class="icon-style" size="18" name="setting" />
  48. <SvgIcon class="icon-style" size="18" name="hidden" /> -->
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. <div v-else-if="isShowMenu == 0" class="menu-show-icon" :style="iconStyle" @mousedown="onDragStart">
  54. <!-- <div v-else-if="isShowMenu == 0" class="menu-show-icon"> -->
  55. <div class="icon" :class="themeIcon == 'styleTwo' ? 'icon-2' : 'icon-1'" @click="openMenu"></div>
  56. </div>
  57. </template>
  58. <script lang="ts">
  59. import { computed, defineComponent, onMounted, ref, unref } from 'vue';
  60. import type { Menu } from '/@/router/types';
  61. import FourBorderBg from '/@/components/vent/fourBorderBg.vue';
  62. import { SvgIcon } from '/@/components/Icon';
  63. import { getMenus } from '/@/router/menus';
  64. import { useGo } from '/@/hooks/web/usePage';
  65. import { useRouter } from 'vue-router';
  66. import { getActions } from '/@/qiankun/state';
  67. import { PageEnum } from '/@/enums/pageEnum';
  68. import { useGlobSetting } from '/@/hooks/setting';
  69. import { unmountMicroApps } from '/@/qiankun';
  70. import { useUserStoreWithOut } from '/@/store/modules/user';
  71. import { useAppStore } from '/@/store/modules/app';
  72. import { router } from '/@/router';
  73. import { getSavedHomeRoute } from '/@/utils/homeStyle';
  74. export default defineComponent({
  75. name: 'BottomSider',
  76. components: { FourBorderBg, SvgIcon },
  77. setup() {
  78. let menuModules = ref<Menu[]>([]);
  79. const actions = getActions();
  80. const currentParentRoute = ref<Menu>();
  81. const { currentRoute } = useRouter();
  82. const route = unref(currentRoute);
  83. const go = useGo();
  84. const glob = useGlobSetting();
  85. const isShowMenu = ref(route.path.startsWith('/cad-viewer') ? 1 : 0);
  86. const userStore = useUserStoreWithOut();
  87. // const appStore = useAppStore();
  88. // const themeIcon = appStore.getDarkMode;
  89. const themeIcon = ref('styleTwo');
  90. const appStore = useAppStore();
  91. const ICON_SIZE = 60;
  92. const iconTop = ref(0);
  93. const isDragging = ref(false);
  94. function getLayoutHeight() {
  95. const el = document.getElementById('adaptive-container');
  96. return el ? el.clientHeight : window.innerHeight;
  97. }
  98. function getScale() {
  99. return appStore.getHeightScale || 1;
  100. }
  101. function clampTop(val: number) {
  102. return Math.max(0, Math.min(getLayoutHeight() - ICON_SIZE - 5, val));
  103. }
  104. // 视口坐标 → 布局坐标
  105. function viewportToLayout(viewportVal: number) {
  106. return viewportVal / getScale();
  107. }
  108. const iconStyle = computed(() => {
  109. const top = clampTop(iconTop.value);
  110. if (isDragging.value) {
  111. return { left: '5px', top: top + 'px', transition: 'none' };
  112. }
  113. return { left: '5px', top: top + 'px', transition: 'top 0.3s ease' };
  114. });
  115. onMounted(() => {
  116. iconTop.value = clampTop(getLayoutHeight() - ICON_SIZE - 5);
  117. });
  118. const DRAG_THRESHOLD = 5;
  119. function onDragStart(e: MouseEvent) {
  120. e.preventDefault();
  121. const startX = e.clientX;
  122. const startY = e.clientY;
  123. const menuEl = (e.target as HTMLElement).closest('.menu-show-icon');
  124. const rect = menuEl!.getBoundingClientRect();
  125. const startTop = rect.top;
  126. let dragged = false;
  127. const onMove = (ev: MouseEvent) => {
  128. ev.preventDefault();
  129. const deltaY = ev.clientY - startY;
  130. const layoutTop = viewportToLayout(startTop + deltaY);
  131. if (!dragged && (Math.abs(ev.clientX - startX) > DRAG_THRESHOLD || Math.abs(deltaY) > DRAG_THRESHOLD)) {
  132. dragged = true;
  133. isDragging.value = true;
  134. }
  135. if (dragged) {
  136. iconTop.value = clampTop(layoutTop);
  137. }
  138. };
  139. const onUp = () => {
  140. if (dragged) {
  141. isDragging.value = false;
  142. const iconEl = menuEl?.querySelector('.icon');
  143. if (iconEl) {
  144. const preventClick = (e: MouseEvent) => {
  145. e.stopPropagation();
  146. e.preventDefault();
  147. iconEl.removeEventListener('click', preventClick, true);
  148. };
  149. iconEl.addEventListener('click', preventClick, true);
  150. }
  151. }
  152. document.removeEventListener('mousemove', onMove);
  153. document.removeEventListener('mouseup', onUp);
  154. };
  155. document.addEventListener('mousemove', onMove);
  156. document.addEventListener('mouseup', onUp);
  157. }
  158. function selectMenu(e: Event, programMenu) {
  159. e.stopPropagation();
  160. currentParentRoute.value = programMenu;
  161. }
  162. async function handleMenuClick(path: Menu) {
  163. if (path.path == currentRoute.value.fullPath) {
  164. return;
  165. }
  166. if (path.path.includes('sw/monitor-fanmain')) {
  167. // 上湾主风机
  168. var url = window.open('_blank') as Window; //打开一个窗口,然后用
  169. url.location = 'https://swkhmi.shendong.vip:9043/#SW_PW_NORTH'; //使这个窗口跳转到。
  170. return;
  171. }
  172. if (path.path.includes('sw/forcFan')) {
  173. // 上湾压风
  174. var url = window.open('_blank') as Window; //打开一个窗口,然后用
  175. url.location = 'https://swkhmi.shendong.vip:9043/#SW_CA'; //使这个窗口跳转到。
  176. return;
  177. }
  178. if (path.path.includes('outlink/index')) {
  179. var url = window.open('_blank') as Window; //打开一个窗口,然后用
  180. url.location = path['frameSrc']; //使这个窗口跳转到。
  181. return;
  182. }
  183. // if (currentRoute.value.path.startsWith('/micro') && currentRoute.value.path == path.path) {
  184. // router.replace(path.path);
  185. // // go(path.path);
  186. // window.history.pushState({}, '', path.path);
  187. // } else {
  188. // go(path.path);
  189. // }
  190. go(path.path);
  191. isShowMenu.value = 0;
  192. }
  193. function geHome() {
  194. if (getSavedHomeRoute()) {
  195. go(getSavedHomeRoute());
  196. } else if (userStore.getUserInfo.homePath) {
  197. go(userStore.getUserInfo.homePath);
  198. } else if (currentRoute.value.path.startsWith('/micro-need-air')) {
  199. window.history.pushState({}, '', glob.homePath || PageEnum.BASE_HOME);
  200. } else {
  201. go(glob.homePath || PageEnum.BASE_HOME);
  202. }
  203. }
  204. function closeMenu(e?: Event) {
  205. e?.stopPropagation();
  206. isShowMenu.value = 0;
  207. document.removeEventListener('click', closeMenu);
  208. }
  209. function openMenu(e: Event) {
  210. e.stopPropagation();
  211. isShowMenu.value = -1;
  212. document.addEventListener('click', closeMenu);
  213. }
  214. onMounted(async () => {
  215. menuModules.value = await getMenus();
  216. const index = menuModules.value.findIndex((menu) => menu.children && menu.children.length > 0);
  217. currentParentRoute.value = menuModules.value[index];
  218. });
  219. return {
  220. themeIcon,
  221. menuModules,
  222. isShowMenu,
  223. handleMenuClick,
  224. openMenu,
  225. closeMenu,
  226. selectMenu,
  227. go,
  228. geHome,
  229. currentParentRoute,
  230. iconStyle,
  231. isDragging,
  232. onDragStart,
  233. };
  234. },
  235. });
  236. </script>
  237. <style lang="less" scoped>
  238. @keyframes menuShow {
  239. 0% {
  240. width: 0;
  241. height: 0;
  242. }
  243. 100% {
  244. width: 480px;
  245. height: 100vh;
  246. }
  247. }
  248. .bottom-side {
  249. width: 480px;
  250. height: 100vh;
  251. position: fixed;
  252. bottom: 2px;
  253. left: 0px;
  254. z-index: 9999999;
  255. color: #fff;
  256. .menu-container {
  257. width: 480px;
  258. position: absolute;
  259. bottom: 0;
  260. // border: 1px solid #0099e6;
  261. // background-color: #06115a;
  262. border: 1px solid #0099e6;
  263. background-color: #0c1e2b;
  264. z-index: 999;
  265. max-height: 900px;
  266. .menu-items {
  267. max-height: 840px;
  268. overflow-y: auto;
  269. }
  270. .four-border-bg {
  271. margin: 5px;
  272. background-color: #ffffff00;
  273. .main-container {
  274. background-color: #ffffff00 !important;
  275. box-shadow: 0 0 3px #ffffff33 inset;
  276. backdrop-filter: none !important;
  277. }
  278. .parent-menu {
  279. width: 110px;
  280. }
  281. .child-menu {
  282. width: 330px;
  283. font-size: 13px;
  284. }
  285. .child-menu-item {
  286. width: 100px;
  287. padding: 2px 0;
  288. text-align: center;
  289. // background-color: #086193;
  290. background: linear-gradient(#0d435d, #0e729d);
  291. border-radius: 2px;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. margin: 5px;
  296. cursor: pointer;
  297. box-shadow: 0 0 3px #ffffff22 inset;
  298. &:hover {
  299. background: linear-gradient(#1d89bf, #17aeee);
  300. }
  301. }
  302. .child-menu-item-disabled {
  303. width: 100px;
  304. padding: 2px 0;
  305. border-radius: 2px;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. margin: 5px;
  310. cursor: pointer;
  311. box-shadow: 0 0 3px #ffffff22 inset;
  312. background: linear-gradient(#7b7b7b, #6b6b6b);
  313. }
  314. }
  315. }
  316. .menu-button-group {
  317. margin: 5px 0;
  318. .program-menu {
  319. // width: 90px;
  320. padding: 1px 15px;
  321. background: linear-gradient(#217aa5, #0f4f75);
  322. margin-left: 5px;
  323. text-align: center;
  324. border-radius: 2px;
  325. cursor: pointer;
  326. &:hover {
  327. background: linear-gradient(#42b7ff, #1ca0d4);
  328. }
  329. }
  330. .program-menu-active {
  331. background: linear-gradient(#42adff, #1a8cbb);
  332. }
  333. .icon-style {
  334. margin-right: 10px;
  335. &:last-child {
  336. margin-right: 5px;
  337. }
  338. }
  339. }
  340. }
  341. .bottom-size-show {
  342. animation: menuShow 0.4s;
  343. animation-iteration-count: 1;
  344. animation-fill-mode: forwards;
  345. animation-timing-function: ease-in;
  346. /* Safari and Chrome */
  347. -webkit-animation: menuShow 0.4s;
  348. -webkit-animation-iteration-count: 1;
  349. -webkit-animation-fill-mode: forwards;
  350. -webkit-animation-timing-function: ease-in;
  351. }
  352. .menu-show-icon {
  353. position: fixed;
  354. z-index: 1000000;
  355. cursor: grab;
  356. user-select: none;
  357. &:active {
  358. cursor: grabbing;
  359. }
  360. .icon {
  361. width: 60px;
  362. height: 60px;
  363. position: relative;
  364. &:before {
  365. content: '';
  366. display: block;
  367. width: 60px;
  368. height: 60px;
  369. position: absolute;
  370. background: url('/@/assets/images/vent/bottom-icon/menu-icon-inner.png') no-repeat;
  371. background-position: center;
  372. }
  373. &:after {
  374. content: '';
  375. display: block;
  376. width: 60px;
  377. height: 60px;
  378. position: absolute;
  379. animation-timing-function: ease-in;
  380. animation: fadenum 8s infinite;
  381. }
  382. @keyframes fadenum {
  383. 0% {
  384. transform: rotate(0deg);
  385. }
  386. 10% {
  387. transform: rotate(360deg);
  388. }
  389. 100% {
  390. transform: rotate(360deg);
  391. }
  392. }
  393. }
  394. .icon-1 {
  395. background-image: url('/@/assets/images/vent/bottom-icon/menu-icon-outer.png');
  396. background-position: center;
  397. &:after {
  398. background: url('/@/assets/images/vent/bottom-icon/menu-icon-center.png') no-repeat;
  399. background-position: center;
  400. }
  401. }
  402. .icon-2 {
  403. background-image: url('/@/assets/images/vent/bottom-icon/1.png');
  404. background-position: center;
  405. &:after {
  406. background: url('/@/assets/images/vent/bottom-icon/2.png') no-repeat;
  407. background-position: center;
  408. }
  409. }
  410. }
  411. </style>