left-window.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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: 'Home.msg.Custom', icon: 'crm-house',
  43. children: [
  44. { path: '/pages/customer/index', label: 'Custom.Index.AccountList', icon: 'icon-client' },
  45. { path: '/pages/customer/deposit', label: 'Home.page_customer.item2', icon: 'icon-deposit' },
  46. { path: '/pages/customer/withdrawal', label: 'Home.page_customer.item3', icon: 'icon-withdrawal' },
  47. { path: '/pages/customer/payment-history', label: 'Home.page_customer.item4', icon: 'icon-payment' },
  48. { path: '/pages/customer/transfer', label: 'Home.page_customer.item5', icon: 'icon-transfer' },
  49. { path: '/pages/customer/recording-history', label: 'Home.page_customer.item7', icon: 'icon-application' }
  50. ]
  51. },
  52. {
  53. isOpenMenu: false,
  54. path: '/pages/ib/index', label: 'Home.msg.Ib', icon: 'crm-users',
  55. children: [
  56. { path: '/pages/ib/index', label: 'Home.page_ib.item1', icon: 'icon-client' },
  57. { path: '/pages/ib/customer', label: 'Home.page_ib.item2', icon: 'icon-deposit' },
  58. { path: '/pages/ib/report', label: 'Home.page_ib.item3', icon: 'icon-withdrawal' },
  59. { path: '/pages/ib/transfer', label: 'Home.page_ib.item4', icon: 'icon-payment' },
  60. { path: '/pages/ib/withdraw', label: 'Home.page_ib.item5', icon: 'icon-transfer' },
  61. { path: '/pages/ib/agent-transfer', label: 'Home.page_ib.item9', icon: 'icon-transfer' },
  62. { path: '/pages/ib/recording', label: 'Home.page_ib.item7', icon: 'icon-application' }
  63. ]
  64. },
  65. {
  66. path: '/pages/analytics/analystViews', isOpenMenu: false, label: 'News.News', icon: 'crm-chart-area',
  67. children: [
  68. { path: '/pages/analytics/analystViews', label: 'News.Announcement', icon: 'icon-application' },
  69. { path: '/pages/analytics/news', label: 'News.NewsInformation', icon: 'icon-application' },
  70. { path: `https://www.${Config.host}.com/${locale.value}/economic-calendar`, label: 'News.FinancialCalendar', icon: 'icon-application', isExternal: true },
  71. ]
  72. },
  73. {
  74. path: '/pages/customer/withdrawal', isOpenMenu: false, label: 'Downloadpage.item1', icon: 'crm-download',
  75. children: []
  76. },
  77. {
  78. path: '/pages/customer/support', isOpenMenu: false, label: 'Downloadpage.item16', icon: 'crm-headset',
  79. children: []
  80. },
  81. {
  82. path: '/pages/customer/support', isOpenMenu: false, label: '设置', icon: 'crm-headset',
  83. children: [
  84. { path: '/pages/mine/info?type=1', isOpenMenu: false, label: 'PersonalManagement.Title.PersonalInformation', icon: 'crm-headset' },
  85. { path: '/pages/mine/info?type=2', isOpenMenu: false, label: 'PersonalManagement.Title.BankInformation', icon: 'crm-headset' },
  86. { path: '/pages/mine/info?type=3', isOpenMenu: false, label: 'PersonalManagement.Title.FileManagement', icon: 'crm-headset' },
  87. { path: '/pages/mine/info?type=4', isOpenMenu: false, label: 'PersonalManagement.Title.SecurityCenter', icon: 'crm-headset' },
  88. ]
  89. },
  90. ]);
  91. const submenuRefs = ref<any[]>([]);
  92. const measureHeight = (element: HTMLElement): number => {
  93. const originalDisplay = element.style.display;
  94. const originalPosition = element.style.position;
  95. const originalVisibility = element.style.visibility;
  96. const originalWidth = element.style.width;
  97. element.style.display = 'block';
  98. element.style.position = 'absolute';
  99. element.style.visibility = 'hidden';
  100. element.style.width = '100%';
  101. const height = element.scrollHeight || element.offsetHeight;
  102. element.style.display = originalDisplay;
  103. element.style.position = originalPosition;
  104. element.style.visibility = originalVisibility;
  105. element.style.width = originalWidth;
  106. return height;
  107. };
  108. const updateSubmenuHeight = (index: number) => {
  109. const refs = submenuRefs.value;
  110. if (refs && refs[index]) {
  111. const el = refs[index].$el || refs[index];
  112. const height = measureHeight(el);
  113. if (height > 0) {
  114. menu.value[index].submenuHeight = height;
  115. }
  116. }
  117. };
  118. function handleClick(index: number) {
  119. if (!menu.value[index].children || menu.value[index].children.length == 0) {
  120. router.push(menu.value[index].path);
  121. return;
  122. }
  123. menu.value[index].isOpenMenu = !menu.value[index].isOpenMenu;
  124. }
  125. watch(route, () => {
  126. const currentPath = route.path;
  127. menu.value.forEach((item, index) => {
  128. if (item.children) {
  129. const isActive = item.children.some(child => child.path.includes(currentPath));
  130. menu.value[index].isOpenMenu = isActive;
  131. if (isActive) {
  132. nextTick(() => {
  133. updateSubmenuHeight(index);
  134. });
  135. }
  136. }
  137. });
  138. }, { immediate: true })
  139. // 添加窗口大小变化监听
  140. const handleResize = () => {
  141. menu.value.forEach((item, index) => {
  142. if (item.children) {
  143. updateSubmenuHeight(index);
  144. }
  145. });
  146. };
  147. onMounted(() => {
  148. nextTick(() => {
  149. menu.value.forEach((item, index) => {
  150. if (item.children) {
  151. updateSubmenuHeight(index);
  152. }
  153. });
  154. });
  155. // 添加窗口resize监听
  156. window.addEventListener('resize', handleResize);
  157. });
  158. // 组件卸载时移除监听
  159. onBeforeUnmount(() => {
  160. window.removeEventListener('resize', handleResize);
  161. });
  162. </script>
  163. <style scoped lang="scss">
  164. @import "@/uni.scss";
  165. .cwg-sidebar {
  166. width: 100%;
  167. color: #6c8595;
  168. height: calc(100vh - 56px);
  169. overflow: auto;
  170. display: flex;
  171. flex-direction: column;
  172. align-items: center;
  173. padding: px2rpx(8);
  174. padding-top: px2rpx(20);
  175. box-sizing: border-box;
  176. gap: px2rpx(8);
  177. border-right: 1px solid rgba(108, 133, 149, 0.12);
  178. .logo {
  179. width: px2rpx(54);
  180. }
  181. .submenu-box {
  182. width: 100%;
  183. height: 0;
  184. overflow: hidden;
  185. }
  186. .menu {
  187. width: 100%;
  188. position: relative;
  189. display: flex;
  190. flex-direction: column;
  191. align-items: center;
  192. box-sizing: border-box;
  193. }
  194. .menu-item {
  195. width: 100%;
  196. height: px2rpx(40);
  197. cursor: pointer;
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. gap: px2rpx(8);
  202. padding: px2rpx(10);
  203. box-sizing: border-box;
  204. font-size: 14px;
  205. .menu-label {
  206. flex: 1;
  207. }
  208. &:hover {
  209. background: rgba(108, 133, 149, 0.12) !important;
  210. border: 1px solid rgb(145, 163, 176) !important;
  211. border-radius: px2rpx(4);
  212. }
  213. .expanded .icon {
  214. transform: rotate(180deg);
  215. }
  216. }
  217. }
  218. @media screen and (max-width: 1100px) {
  219. .cwg-sidebar:not(:hover) .menu-label,
  220. .cwg-sidebar:not(:hover) .submenu-box,
  221. .cwg-sidebar:not(:hover) .chevron-icon {
  222. display: none;
  223. }
  224. .cwg-sidebar:hover .menu-label,
  225. .cwg-sidebar:hover .submenu-box,
  226. .cwg-sidebar:hover .chevron-icon {
  227. display: block;
  228. }
  229. }
  230. </style>