cwg-sidebar.vue 9.8 KB

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