left-window.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="cwg-sidebar">
  3. <view class="menu" v-for="(item, index) in menu" :key="item.path">
  4. <view class="menu-item" @click="handleClick(index)">
  5. <cwg-icon :name="item.icon" :size="20" color="#6c8595" />
  6. <view class="menu-label" v-t="item.label" />
  7. <view class="chevron-icon" :class="{ 'expanded': item.isOpenMenu }">
  8. <cwg-icon v-if="item.children && item.children.length" name="crm-chevron-down" :size="20"
  9. color="#6c8595" />
  10. </view>
  11. </view>
  12. <view ref="submenuRefs" class="submenu-box" :style="{
  13. height: item.isOpenMenu ? item.submenuHeight + 'px' : '0px',
  14. transition: 'height 281ms cubic-bezier(0.4, 0, 0.2, 1)'
  15. }" :class="{ 'active': item.isOpenMenu }">
  16. <cwg-submenu v-if="item.children" :submenu-items="item.children" @submenu-click="handleSubmenuClick" />
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script lang="ts" setup>
  22. import { ref, onMounted, nextTick, watch, onBeforeUnmount } from 'vue';
  23. import useRouter from "@/hooks/useRouter";
  24. const router = useRouter();
  25. import useRoute from '@/hooks/useRoute'
  26. const route = useRoute()
  27. import Config from '@/config/index'
  28. import { useI18n } from "vue-i18n";
  29. const { t, locale } = useI18n();
  30. interface MenuItem {
  31. key: string;
  32. label: string;
  33. icon?: string;
  34. children?: MenuItem[];
  35. }
  36. const emit = defineEmits(['menu-click']);
  37. // 菜单数据
  38. const menu = ref<MenuItem[]>(
  39. [
  40. {
  41. isOpenMenu: false, submenuHeight: 0,
  42. path: '/pages/customer/index', label: 'Shop.Index.Transaction', icon: 'crm-trade',
  43. children: [
  44. { path: '/pages/customer/index', label: 'Custom.Index.AccountList', icon: 'icon-client' },
  45. { path: '/pages/customer/trade-history', label: 'Ib.Report.Tit1', icon: 'icon-transfer' },
  46. { path: '/pages/customer/trade-position', label: 'Ib.Report.Tit4', icon: 'icon-transfer' },
  47. { path: '/pages/customer/recording-history', label: 'Home.page_customer.item7', icon: 'icon-application' }
  48. ]
  49. },
  50. {
  51. isOpenMenu: false, submenuHeight: 0,
  52. path: '/pages/customer/index', label: 'Latest.PaymentWallet', icon: 'crm-payment',
  53. children: [
  54. { path: '/pages/customer/deposit', label: 'Home.page_customer.item2', icon: 'icon-deposit' },
  55. { path: '/pages/customer/withdrawal', label: 'Home.page_customer.item3', icon: 'icon-withdrawal' },
  56. { path: '/pages/customer/payment-history', label: 'Home.page_customer.item4', icon: 'icon-payment' },
  57. { path: '/pages/customer/transfer', label: 'Custom.Index.Transfer', icon: 'icon-transfer' }
  58. ]
  59. },
  60. {
  61. isOpenMenu: false,
  62. path: '/pages/ib/index', label: 'Home.msg.Ib', icon: 'crm-ib',
  63. children: [
  64. { path: '/pages/ib/index', label: 'Home.page_ib.item1', icon: 'icon-client' },
  65. { path: '/pages/ib/customer', label: 'Home.page_ib.item2', icon: 'icon-deposit' },
  66. { path: '/pages/ib/report', label: 'Home.page_ib.item3', icon: 'icon-withdrawal' },
  67. { path: '/pages/ib/transfer', label: 'Home.page_ib.item4', icon: 'icon-payment' },
  68. { path: '/pages/ib/withdraw', label: 'Home.page_ib.item5', icon: 'icon-transfer' },
  69. { path: '/pages/ib/agent-transfer', label: 'Home.page_ib.item9', icon: 'icon-transfer' },
  70. { path: '/pages/ib/recording', label: 'Home.page_ib.item7', icon: 'icon-application' }
  71. ]
  72. },
  73. {
  74. path: '/pages/analytics/analystViews', isOpenMenu: false, label: 'News.News', icon: 'crm-chart-area',
  75. children: [
  76. { path: '/pages/analytics/analystViews', label: 'News.Announcement', icon: 'icon-application' },
  77. { path: '/pages/analytics/news', label: 'News.NewsInformation', icon: 'icon-application' },
  78. { path: `https://www.${Config.host}.com/${locale.value}/economic-calendar`, label: 'News.FinancialCalendar', icon: 'icon-application', isExternal: true },
  79. ]
  80. },
  81. {
  82. path: '/pages/customer/withdrawal', isOpenMenu: false, label: 'Downloadpage.item1', icon: 'crm-download',
  83. children: []
  84. },
  85. {
  86. path: '/pages/common/chat', isOpenMenu: false, label: 'Downloadpage.item16', icon: 'crm-headset',
  87. children: [],
  88. type: 'chat'
  89. },
  90. {
  91. path: '/pages/customer/support', isOpenMenu: false, label: 'Custom.Index.Settings', icon: 'crm-sz',
  92. children: [
  93. { path: '/pages/mine/info?type=1', isOpenMenu: false, label: 'PersonalManagement.Title.PersonalInformation', icon: 'crm-headset' },
  94. { path: '/pages/mine/info?type=2', isOpenMenu: false, label: 'PersonalManagement.Title.BankInformation', icon: 'crm-headset' },
  95. { path: '/pages/mine/info?type=3', isOpenMenu: false, label: 'PersonalManagement.Title.FileManagement', icon: 'crm-headset' },
  96. { path: '/pages/mine/info?type=4', isOpenMenu: false, label: 'PersonalManagement.Title.SecurityCenter', icon: 'crm-headset' },
  97. ]
  98. },
  99. ]);
  100. const submenuRefs = ref<any[]>([]);
  101. const measureHeight = (element: HTMLElement): number => {
  102. const originalDisplay = element.style.display;
  103. const originalPosition = element.style.position;
  104. const originalVisibility = element.style.visibility;
  105. const originalWidth = element.style.width;
  106. element.style.display = 'block';
  107. element.style.position = 'absolute';
  108. element.style.visibility = 'hidden';
  109. element.style.width = '100%';
  110. const height = element.scrollHeight || element.offsetHeight;
  111. element.style.display = originalDisplay;
  112. element.style.position = originalPosition;
  113. element.style.visibility = originalVisibility;
  114. element.style.width = originalWidth;
  115. return height;
  116. };
  117. const updateSubmenuHeight = (index: number) => {
  118. const refs = submenuRefs.value;
  119. if (refs && refs[index]) {
  120. const el = refs[index].$el || refs[index];
  121. const height = measureHeight(el);
  122. if (height > 0) {
  123. menu.value[index].submenuHeight = height;
  124. }
  125. }
  126. };
  127. function handleClick(index: number) {
  128. if (!menu.value[index].children || menu.value[index].children.length == 0) {
  129. // #ifdef H5
  130. if (menu.value[index].type === 'chat') {
  131. if (window.LiveChatWidget) {
  132. window.LiveChatWidget.call("maximize");
  133. }
  134. } else {
  135. router.push(menu.value[index].path);
  136. }
  137. // #endif
  138. // #ifdef APP-VUE
  139. router.push(menu.value[index].path);
  140. // #endif
  141. return;
  142. }
  143. menu.value[index].isOpenMenu = !menu.value[index].isOpenMenu;
  144. }
  145. watch(route, () => {
  146. const currentPath = route.path;
  147. menu.value.forEach((item, index) => {
  148. if (item.children) {
  149. const isActive = item.children.some(child => child.path.includes(currentPath));
  150. menu.value[index].isOpenMenu = isActive;
  151. if (isActive) {
  152. nextTick(() => {
  153. updateSubmenuHeight(index);
  154. });
  155. }
  156. }
  157. });
  158. }, { immediate: true })
  159. // 添加窗口大小变化监听
  160. const handleResize = () => {
  161. menu.value.forEach((item, index) => {
  162. if (item.children) {
  163. updateSubmenuHeight(index);
  164. }
  165. });
  166. };
  167. onMounted(() => {
  168. nextTick(() => {
  169. menu.value.forEach((item, index) => {
  170. if (item.children) {
  171. updateSubmenuHeight(index);
  172. }
  173. });
  174. });
  175. // 添加窗口resize监听
  176. window.addEventListener('resize', handleResize);
  177. });
  178. // 组件卸载时移除监听
  179. onBeforeUnmount(() => {
  180. window.removeEventListener('resize', handleResize);
  181. });
  182. </script>
  183. <style scoped lang="scss">
  184. @import "@/uni.scss";
  185. .cwg-sidebar {
  186. width: 100%;
  187. color: #6c8595;
  188. height: calc(100vh - 56px);
  189. overflow: auto;
  190. display: flex;
  191. flex-direction: column;
  192. align-items: center;
  193. padding: px2rpx(8);
  194. padding-top: px2rpx(20);
  195. box-sizing: border-box;
  196. gap: px2rpx(8);
  197. border-right: 1px solid rgba(108, 133, 149, 0.12);
  198. .logo {
  199. width: px2rpx(54);
  200. }
  201. .submenu-box {
  202. width: 100%;
  203. height: 0;
  204. overflow: hidden;
  205. }
  206. .menu {
  207. width: 100%;
  208. position: relative;
  209. display: flex;
  210. flex-direction: column;
  211. align-items: center;
  212. box-sizing: border-box;
  213. }
  214. .menu-item {
  215. width: 100%;
  216. height: px2rpx(40);
  217. cursor: pointer;
  218. display: flex;
  219. align-items: center;
  220. justify-content: space-between;
  221. gap: px2rpx(8);
  222. padding: px2rpx(10);
  223. box-sizing: border-box;
  224. font-size: 14px;
  225. .menu-label {
  226. flex: 1;
  227. }
  228. &:hover {
  229. background: rgba(108, 133, 149, 0.12) !important;
  230. border: 1px solid rgb(145, 163, 176) !important;
  231. border-radius: px2rpx(4);
  232. }
  233. .expanded .icon {
  234. transform: rotate(180deg);
  235. }
  236. }
  237. }
  238. @media screen and (max-width: 1100px) {
  239. .cwg-sidebar:not(:hover) .menu-label,
  240. .cwg-sidebar:not(:hover) .submenu-box,
  241. .cwg-sidebar:not(:hover) .chevron-icon {
  242. display: none;
  243. }
  244. .cwg-sidebar:hover .menu-label,
  245. .cwg-sidebar:hover .submenu-box,
  246. .cwg-sidebar:hover .chevron-icon {
  247. display: block;
  248. }
  249. }
  250. </style>