left-window.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. // 客户管理
  66. { path: '/pages/ib/customer', label: 'Home.page_ib.item2', icon: 'icon-deposit' },
  67. //代理管理
  68. { path: '/pages/ib/subsList', label: 'Home.page_ib.item12', icon: 'icon-deposit' },
  69. // 信号源列表
  70. { path: '/pages/ib/agentList', label: 'Home.page_ib.item11', icon: 'icon-deposit' },
  71. // 账户管理
  72. { path: '/pages/ib/accountList', label: 'Home.page_ib.item10', icon: 'icon-deposit' },
  73. { path: '/pages/ib/report', label: 'Home.page_ib.item3', icon: 'icon-withdrawal' },
  74. { path: '/pages/ib/transfer', label: 'Home.page_ib.item4', icon: 'icon-payment' },
  75. { path: '/pages/ib/withdraw', label: 'Home.page_ib.item5', icon: 'icon-transfer' },
  76. { path: '/pages/ib/agent-transfer', label: 'Home.page_ib.item9', icon: 'icon-transfer' },
  77. { path: '/pages/ib/recording', label: 'Home.page_ib.item7', icon: 'icon-application' },
  78. ],
  79. },
  80. {
  81. path: '/pages/analytics/analystViews', isOpenMenu: false, label: 'News.News', icon: 'crm-chart-area',
  82. children: [
  83. { path: '/pages/analytics/analystViews', label: 'News.Announcement', icon: 'icon-application' },
  84. { path: '/pages/analytics/news', label: 'News.NewsInformation', icon: 'icon-application' },
  85. {
  86. path: `https://www.${Config.host}.com/${locale.value}/economic-calendar`,
  87. label: 'News.FinancialCalendar',
  88. icon: 'icon-application',
  89. isExternal: true,
  90. },
  91. ],
  92. },
  93. {
  94. path: '/pages/customer/withdrawal', isOpenMenu: false, label: 'Downloadpage.item1', icon: 'crm-download',
  95. children: [],
  96. },
  97. {
  98. path: '/pages/common/chat', isOpenMenu: false, label: 'Downloadpage.item16', icon: 'crm-headset',
  99. children: [],
  100. type: 'chat',
  101. },
  102. {
  103. path: '/pages/customer/support', isOpenMenu: false, label: 'Custom.Index.Settings', icon: 'crm-sz',
  104. children: [
  105. {
  106. path: '/pages/mine/info?type=1',
  107. isOpenMenu: false,
  108. label: 'PersonalManagement.Title.PersonalInformation',
  109. icon: 'crm-headset',
  110. },
  111. {
  112. path: '/pages/mine/info?type=2',
  113. isOpenMenu: false,
  114. label: 'PersonalManagement.Title.BankInformation',
  115. icon: 'crm-headset',
  116. },
  117. {
  118. path: '/pages/mine/info?type=3',
  119. isOpenMenu: false,
  120. label: 'PersonalManagement.Title.FileManagement',
  121. icon: 'crm-headset',
  122. },
  123. {
  124. path: '/pages/mine/info?type=4',
  125. isOpenMenu: false,
  126. label: 'PersonalManagement.Title.SecurityCenter',
  127. icon: 'crm-headset',
  128. },
  129. { path: '/pages/common/notice', isOpenMenu: false, label: 'News.Notice', icon: 'crm-headset' },
  130. ],
  131. },
  132. ])
  133. const submenuRefs = ref<any[]>([])
  134. const measureHeight = (element: HTMLElement): number => {
  135. const originalDisplay = element.style.display
  136. const originalPosition = element.style.position
  137. const originalVisibility = element.style.visibility
  138. const originalWidth = element.style.width
  139. element.style.display = 'block'
  140. element.style.position = 'absolute'
  141. element.style.visibility = 'hidden'
  142. element.style.width = '100%'
  143. const height = element.scrollHeight || element.offsetHeight
  144. element.style.display = originalDisplay
  145. element.style.position = originalPosition
  146. element.style.visibility = originalVisibility
  147. element.style.width = originalWidth
  148. return height
  149. }
  150. const updateSubmenuHeight = (index: number) => {
  151. const refs = submenuRefs.value
  152. if (refs && refs[index]) {
  153. const el = refs[index].$el || refs[index]
  154. const height = measureHeight(el)
  155. if (height > 0) {
  156. menu.value[index].submenuHeight = height
  157. }
  158. }
  159. }
  160. function handleClick(index: number) {
  161. if (!menu.value[index].children || menu.value[index].children.length == 0) {
  162. // #ifdef H5
  163. if (menu.value[index].type === 'chat') {
  164. if (window.LiveChatWidget) {
  165. window.LiveChatWidget.call('maximize')
  166. }
  167. } else {
  168. router.push(menu.value[index].path)
  169. }
  170. // #endif
  171. // #ifdef APP-VUE
  172. router.push(menu.value[index].path)
  173. // #endif
  174. return
  175. }
  176. menu.value[index].isOpenMenu = !menu.value[index].isOpenMenu
  177. }
  178. watch(route, () => {
  179. const currentPath = route.path
  180. menu.value.forEach((item, index) => {
  181. if (item.children) {
  182. const isActive = item.children.some(child => child.path.includes(currentPath))
  183. menu.value[index].isOpenMenu = isActive
  184. if (isActive) {
  185. nextTick(() => {
  186. updateSubmenuHeight(index)
  187. })
  188. }
  189. }
  190. })
  191. }, { immediate: true })
  192. // 添加窗口大小变化监听
  193. const handleResize = () => {
  194. menu.value.forEach((item, index) => {
  195. if (item.children) {
  196. updateSubmenuHeight(index)
  197. }
  198. })
  199. }
  200. onMounted(() => {
  201. nextTick(() => {
  202. menu.value.forEach((item, index) => {
  203. if (item.children) {
  204. updateSubmenuHeight(index)
  205. }
  206. })
  207. })
  208. // 添加窗口resize监听
  209. window.addEventListener('resize', handleResize)
  210. })
  211. // 组件卸载时移除监听
  212. onBeforeUnmount(() => {
  213. window.removeEventListener('resize', handleResize)
  214. })
  215. </script>
  216. <style scoped lang="scss">
  217. @import "@/uni.scss";
  218. .cwg-sidebar {
  219. width: 100%;
  220. color: #6c8595;
  221. height: calc(100vh - 56px);
  222. overflow: auto;
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. padding: px2rpx(8);
  227. padding-top: px2rpx(20);
  228. box-sizing: border-box;
  229. gap: px2rpx(8);
  230. border-right: 1px solid rgba(108, 133, 149, 0.12);
  231. .logo {
  232. width: px2rpx(54);
  233. }
  234. .submenu-box {
  235. width: 100%;
  236. height: 0;
  237. overflow: hidden;
  238. }
  239. .menu {
  240. width: 100%;
  241. position: relative;
  242. display: flex;
  243. flex-direction: column;
  244. align-items: center;
  245. box-sizing: border-box;
  246. }
  247. .menu-item {
  248. width: 100%;
  249. height: px2rpx(40);
  250. cursor: pointer;
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. gap: px2rpx(8);
  255. padding: px2rpx(10);
  256. box-sizing: border-box;
  257. font-size: 14px;
  258. .menu-label {
  259. flex: 1;
  260. }
  261. &:hover {
  262. background: rgba(108, 133, 149, 0.12) !important;
  263. border: 1px solid rgb(145, 163, 176) !important;
  264. border-radius: px2rpx(4);
  265. }
  266. .expanded .icon {
  267. transform: rotate(180deg);
  268. }
  269. }
  270. }
  271. @media screen and (max-width: 1100px) {
  272. .cwg-sidebar:not(:hover) .menu-label,
  273. .cwg-sidebar:not(:hover) .submenu-box,
  274. .cwg-sidebar:not(:hover) .chevron-icon {
  275. display: none;
  276. }
  277. .cwg-sidebar:hover .menu-label,
  278. .cwg-sidebar:hover .submenu-box,
  279. .cwg-sidebar:hover .chevron-icon {
  280. display: block;
  281. }
  282. }
  283. </style>