AccountCard.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <view class="account-card">
  3. <!-- 折叠/展开按钮 -->
  4. <button class="collapse-btn" @click="toggleExpand">
  5. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
  6. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  7. :class="['chevron-icon', { expanded: isExpanded }]">
  8. <path d="M6 15l6 -6l6 6" />
  9. </svg>
  10. </button>
  11. <!-- 标签区域 -->
  12. <view class="labels-container">
  13. <view class="labels">
  14. <template v-for="(label, index) in account.labels" :key="index">
  15. <view v-if="label" class="label-badge">
  16. {{ label }}
  17. </view>
  18. </template>
  19. </view>
  20. <view class="account-number"># {{ account.accountNumber }}</view>
  21. <view class="account-nickname">{{ nickName }}</view>
  22. </view>
  23. <!-- 主要内容区域(余额和操作按钮) -->
  24. <view class="main-content">
  25. <!-- 余额 -->
  26. <view class="balance">
  27. <text class="balance-number">{{ balanceInteger }}</text>
  28. <text class="balance-decimal">{{ balanceDecimal }} {{ account.currency }}</text>
  29. </view>
  30. <!-- 移动端圆形按钮组(≤1100px显示) -->
  31. <view class="mobile-buttons">
  32. <!-- 交易 -->
  33. <view class="circle-btn" @click="handleAction('trade')">
  34. <view class="circle-icon">
  35. <cwg-icon name="crm-trade" :size="16" color="#2e3a47" />
  36. </view>
  37. <text class="circle-label" v-t="'Shop.Index.Transaction'" />
  38. </view>
  39. <!-- 入金(带限制包装,此处简化) -->
  40. <view class="circle-btn" @click="toDeposit" v-if="!isDemo">
  41. <view class="circle-icon">
  42. <cwg-icon name="crm-deposit" :size="16" color="#2e3a47" />
  43. </view>
  44. <text class="circle-label" v-t="'Home.page_customer.item2'" />
  45. </view>
  46. <!-- 出金 -->
  47. <view class="circle-btn" @click="toWithdraw" v-if="!isDemo">
  48. <view class="circle-icon">
  49. <cwg-icon name="crm-withdraw" :size="16" color="#2e3a47" />
  50. </view>
  51. <text class="circle-label" v-t="'Home.page_customer.item3'" />
  52. </view>
  53. <!-- 转账 -->
  54. <view class="circle-btn" @click="toTransfer" v-if="!isDemo">
  55. <view class="circle-icon">
  56. <cwg-icon name="crm-transfer" :size="16" color="#2e3a47" />
  57. </view>
  58. <text class="circle-label" v-t="'Custom.Index.Transfer'" />
  59. </view>
  60. <!-- 更多(三点) -->
  61. <cwg-dropdown @open="onOpen" @close="onClose" :menu-list="customMenuList"
  62. @menuClick="handleCustomClick">
  63. <view class="circle-btn">
  64. <view class="circle-icon">
  65. <cwg-icon name="crm-ellipsis-vertical" :size="16" color="#2e3a47" />
  66. </view>
  67. <text class="circle-label" v-t="'Latest.More'" />
  68. </view>
  69. </cwg-dropdown>
  70. </view>
  71. <!-- 桌面端按钮组(>1100px显示) -->
  72. <view class="desktop-buttons">
  73. <view class="action-btn primary" @click="handleAction('trade')">
  74. <span class="btn-icon">
  75. <cwg-icon name="crm-trade" :size="16" color="#fff" />
  76. </span>
  77. <text v-t="'Shop.Index.Transaction'" />
  78. </view>
  79. <view class="action-btn" @click="toDeposit" v-if="!isDemo">
  80. <span class="btn-icon">
  81. <cwg-icon name="crm-deposit" :size="16" color="#2e3a47" />
  82. </span>
  83. <text v-t="'Home.page_customer.item2'" />
  84. </view>
  85. <view class="action-btn" @click="toWithdraw" v-if="!isDemo">
  86. <span class="btn-icon">
  87. <cwg-icon name="crm-withdraw" :size="16" color="#2e3a47" />
  88. </span>
  89. <text v-t="'Home.page_customer.item3'" />
  90. </view>
  91. <view class="action-btn" @click="toTransfer" v-if="!isDemo">
  92. <span class="btn-icon">
  93. <cwg-icon name="crm-transfer" :size="16" color="#2e3a47" />
  94. </span>
  95. <text v-t="'Custom.Index.Transfer'" />
  96. </view>
  97. <cwg-dropdown @open="onOpen" @close="onClose" :menu-list="customMenuList"
  98. @menuClick="handleCustomClick">
  99. <view class="action-btn icon-only">
  100. <cwg-icon name="crm-ellipsis-vertical" :size="16" color="#2e3a47" />
  101. </view>
  102. </cwg-dropdown>
  103. </view>
  104. </view>
  105. <view ref="infoBottomRef" class="info-bottom" :style="{
  106. height: isExpanded ? infoBottomHeight + 'px' : '0px',
  107. transition: 'height 281ms cubic-bezier(0.4, 0, 0.2, 1)'
  108. }">
  109. <!-- 底部信息区域(折叠时隐藏) -->
  110. <view class="info-section">
  111. <view class="info-column">
  112. <cwg-label-line-value :label="t('Label.Leverage')" :value="account.actualLeverage" />
  113. <cwg-label-line-value label="浮动盈/亏" :value="account.floatingPL" />
  114. <cwg-label-line-value :label="t('Label.Balance')" :value="account.balanceWithSymbol" />
  115. </view>
  116. <view class="info-column">
  117. <cwg-label-line-value :label="t('Label.Equity')" :value="account.equityWithSymbol" />
  118. <cwg-label-line-value :label="t('Label.Credit')" :value="account.creditWithSymbol" />
  119. <cwg-label-line-value label="平台" :value="account.platform" />
  120. </view>
  121. </view>
  122. <!-- 额外操作行(服务器、登录、更改密码,折叠时隐藏) -->
  123. <view class="extra-actions">
  124. <!-- 登录复制行 -->
  125. <view class="copy-row">
  126. <span class="label">{{ account.platform }} 登陆</span>
  127. <span class="value">{{ account.login }}</span>
  128. <view class="copy-btn" @click="copy(account.login)">
  129. <cwg-icon name="copy" :size="16" color="#2e3a47" />
  130. </view>
  131. </view>
  132. <!-- 更改交易密码按钮 -->
  133. <view class="change-password-btn" @click="handleAction('changePassword1')" v-if="!isDemo">
  134. <span class="btn-icon">
  135. <cwg-icon name="crm-xg" :size="16" color="#2e3a47" />
  136. </span>
  137. 更改交易密码
  138. </view>
  139. </view>
  140. </view>
  141. <!-- 通知区域(预留) -->
  142. <view class="notificators"></view>
  143. <TerminalDialog v-model:visible="terminalDialogVisible" />
  144. <!-- <TerminalNickNameDialog v-model:visible="terminalNickNameDialogVisible" :account="account"
  145. @save="saveNickName" /> -->
  146. <TerminalChangePasswordDialog v-model:visible="terminalChangePasswordDialogVisible" :pwdType="pwdType"
  147. :account="account" />
  148. <TerminalInfoDialog v-model:visible="terminalInfoDialogVisible" :accountNumber="accountInfo.login"
  149. :form="accountInfo" :fieldList="fieldList" />
  150. </view>
  151. </template>
  152. <script setup lang="ts">
  153. import { ref, computed, onMounted, nextTick, onBeforeUnmount } from 'vue';
  154. import useRouter from "@/hooks/useRouter";
  155. const router = useRouter();
  156. import { useI18n } from 'vue-i18n';
  157. const { t } = useI18n();
  158. import TerminalDialog from './TerminalDialog.vue'
  159. import TerminalChangePasswordDialog from './TerminalChangePasswordDialog.vue'
  160. import TerminalInfoDialog from './TerminalInfoDialog.vue'
  161. const props = defineProps<{
  162. account: Account;
  163. }>();
  164. const accountInfo = ref(props.account)
  165. // 定义账户数据类型
  166. export interface Account {
  167. labels: string[]; // 标签数组,如 ['真实', 'MT4', 'Standard']
  168. accountNumber: string; // 账号,如 '85319215'
  169. nickName: string; // 昵称,如 '标准账户'
  170. balance: number; // 余额数字
  171. currency: string; // 货币,如 'USD'
  172. actualLeverage: string; // 实际杠杆,如 '1:2000'
  173. maxLeverage: string; // 调整杠杆,如 '1:2000'
  174. floatingPL: string; // 浮动盈亏,如 '0.00 USD'
  175. creditWithSymbol: string; // 可用保证金,如 '0.00 USD'
  176. equityWithSymbol: string; // 净值,如 '0.00 USD'
  177. platform: string; // 平台,如 'MT4'
  178. server: string; // 服务器,如 'Exness-Real28'
  179. login: string; // 登录名,如 '85319215'
  180. balanceWithSymbol: string; // 余额,如 '85319215'
  181. }
  182. const isDemo = computed(() => accountInfo.value.listType == 'demo')
  183. const fieldList = ref([
  184. { label: '账户类型', key: 'nickname', copyable: false },
  185. { label: t('Label.Leverage'), key: 'actualLeverage', copyable: false },
  186. { label: '浮动盈/亏', key: 'floatingPL', copyable: false },
  187. { label: t('Label.Balance'), key: 'balanceWithSymbol', copyable: false },
  188. { label: t('Label.Equity'), key: 'equityWithSymbol', copyable: false },
  189. { label: t('Label.Credit'), key: 'creditWithSymbol', copyable: false },
  190. { label: '平台', key: 'platform', copyable: false },
  191. { label: '账号', key: 'login', copyable: true }
  192. ])
  193. const nickName = ref(accountInfo.value.nickName)
  194. const infoBottomRef = ref(null);
  195. const infoBottomHeight = ref(0);
  196. // 测量高度
  197. const updateSubmenuHeight = () => {
  198. const el = infoBottomRef.value.$el;
  199. if (el) {
  200. // 获取内容实际高度(可能需要暂时移除过渡影响)
  201. const height = el.scrollHeight || el.offsetHeight;
  202. if (height > 0) {
  203. infoBottomHeight.value = height;
  204. }
  205. }
  206. };
  207. // 折叠状态
  208. const isExpanded = ref(false);
  209. // 切换折叠
  210. const toggleExpand = () => {
  211. isExpanded.value = !isExpanded.value;
  212. if (isExpanded.value) {
  213. nextTick(() => {
  214. updateSubmenuHeight();
  215. });
  216. }
  217. };
  218. const terminalDialogVisible = ref(false)
  219. const terminalChangePasswordDialogVisible = ref(false)
  220. const terminalInfoDialogVisible = ref(false)
  221. const pwdType = ref(1)
  222. // 处理按钮操作
  223. const handleAction = (type: string) => {
  224. console.log(type == 'info', type, 'info');
  225. switch (type) {
  226. case 'trade':
  227. terminalDialogVisible.value = true
  228. break;
  229. case 'changePassword1':
  230. pwdType.value = 1
  231. terminalChangePasswordDialogVisible.value = true
  232. break;
  233. case 'changePassword2':
  234. pwdType.value = 2
  235. terminalChangePasswordDialogVisible.value = true
  236. break;
  237. case 'info':
  238. console.log(type);
  239. terminalInfoDialogVisible.value = true
  240. break;
  241. default:
  242. break;
  243. }
  244. };
  245. const customMenuList = computed(() => !isDemo.value ? [{ label: '修改交易密码', type: 'changePassword1' }, { label: '修改投资者密码', type: 'changePassword2' }, { label: '账户信息', type: 'info' }] : [{ label: '账户信息', type: 'info' }])
  246. const handleCustomClick = (item, index) => {
  247. handleAction(item.value.type)
  248. }
  249. // 复制文本
  250. const copy = (text: string) => {
  251. uni.setClipboardData({ data: text });
  252. };
  253. // 按钮对应的操作方法
  254. const toDeposit = () => {
  255. router.push(`/pages/customer/deposit?login=${accountInfo.value.login}&type=${accountInfo.value.type}&balance=${accountInfo.value.balance}&currency=${accountInfo.value.currency}`)
  256. }
  257. const toWithdraw = () => {
  258. router.push(`/pages/customer/withdrawal?login=${accountInfo.value.login}&type=${accountInfo.value.type}&balance=${accountInfo.value.balance}&currency=${accountInfo.value.currency}`)
  259. }
  260. const toTransfer = () => {
  261. router.push(`/pages/customer/transfer?login=${accountInfo.value.login}&type=${accountInfo.value.type}&balance=${accountInfo.value.balance}&currency=${accountInfo.value.currency}`)
  262. }
  263. // 格式化余额,拆分为整数和小数部分
  264. const balanceInteger = computed(() => {
  265. return Math.floor(accountInfo.value.balance).toString();
  266. });
  267. const balanceDecimal = computed(() => {
  268. const parts = accountInfo.value.balance.toFixed(2).split('.');
  269. return parts[1] ? '.' + parts[1] : '.00';
  270. });
  271. // 在组件挂载后初始化高度
  272. onMounted(() => {
  273. nextTick(() => {
  274. updateSubmenuHeight();
  275. });
  276. window.addEventListener('resize', handleResize);
  277. isExpanded.value = accountInfo.value.isExpanded;
  278. });
  279. // 监听窗口 resize
  280. const handleResize = () => {
  281. if (isExpanded.value) {
  282. updateSubmenuHeight();
  283. }
  284. };
  285. onBeforeUnmount(() => {
  286. window.removeEventListener('resize', handleResize);
  287. });
  288. </script>
  289. <style scoped lang="scss">
  290. @import '@/uni.scss';
  291. .account-card {
  292. border-radius: px2rpx(16);
  293. padding: px2rpx(16);
  294. margin-bottom: px2rpx(16);
  295. position: relative;
  296. border: 1px solid rgba(108, 133, 149, 0.12);
  297. color: #2e3a47;
  298. .collapse-btn {
  299. position: absolute;
  300. top: px2rpx(12);
  301. right: px2rpx(12);
  302. background: transparent;
  303. border: none;
  304. padding: 0;
  305. cursor: pointer;
  306. color: #6c8595;
  307. width: px2rpx(32);
  308. height: px2rpx(32);
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. .chevron-icon {
  313. transition: transform 0.3s;
  314. &.expanded {
  315. transform: rotate(180deg);
  316. }
  317. }
  318. }
  319. .labels-container {
  320. display: flex;
  321. align-items: center;
  322. flex-wrap: wrap;
  323. gap: px2rpx(8);
  324. margin-bottom: px2rpx(16);
  325. padding-right: px2rpx(40); // 为折叠按钮留出空间
  326. .labels {
  327. display: flex;
  328. gap: px2rpx(8);
  329. }
  330. .label-badge {
  331. background-color: rgba(108, 133, 149, 0.08);
  332. border-radius: px2rpx(4);
  333. padding: px2rpx(4) px2rpx(8);
  334. font-size: px2rpx(12);
  335. color: #6c8595;
  336. font-weight: 500;
  337. }
  338. .account-number {
  339. font-size: px2rpx(18);
  340. font-weight: 600;
  341. line-height: 1.3;
  342. }
  343. .account-nickname {
  344. font-size: px2rpx(14);
  345. color: #6c8595;
  346. }
  347. }
  348. .main-content {
  349. .balance {
  350. margin-bottom: px2rpx(16);
  351. .balance-number {
  352. font-size: px2rpx(32);
  353. font-weight: 700;
  354. }
  355. .balance-decimal {
  356. font-size: px2rpx(16);
  357. color: #6c8595;
  358. margin-left: px2rpx(4);
  359. }
  360. }
  361. // 移动端按钮组(默认显示)
  362. .mobile-buttons {
  363. display: flex;
  364. justify-content: center;
  365. gap: px2rpx(0);
  366. margin-bottom: px2rpx(16);
  367. flex-wrap: wrap;
  368. .circle-btn {
  369. display: flex;
  370. flex-direction: column;
  371. align-items: center;
  372. cursor: pointer;
  373. width: px2rpx(64);
  374. .circle-icon {
  375. width: px2rpx(48);
  376. height: px2rpx(48);
  377. border-radius: 50%;
  378. background-color: #f5f7f9;
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. color: #2e3a47;
  383. transition: background-color 0.2s;
  384. &:hover {
  385. background-color: #e9ecef;
  386. }
  387. svg {
  388. width: px2rpx(24);
  389. height: px2rpx(24);
  390. }
  391. }
  392. .circle-label {
  393. font-size: px2rpx(12);
  394. margin-top: px2rpx(4);
  395. color: #6c8595;
  396. }
  397. }
  398. }
  399. // 桌面端按钮组(默认隐藏,屏幕>1100px时显示)
  400. .desktop-buttons {
  401. display: none;
  402. .action-btn {
  403. background: transparent;
  404. border: 1px solid rgba(108, 133, 149, 0);
  405. border-radius: px2rpx(8);
  406. padding: px2rpx(8) px2rpx(20);
  407. font-size: px2rpx(14);
  408. color: #2e3a47;
  409. display: inline-flex;
  410. align-items: center;
  411. justify-content: center;
  412. gap: px2rpx(8);
  413. cursor: pointer;
  414. transition: all 0.2s;
  415. height: px2rpx(40);
  416. box-sizing: border-box;
  417. background-color: rgba(108, 133, 149, 0.08);
  418. &.primary {
  419. background-color: var(--color-navy-700);
  420. color: #fff;
  421. svg {
  422. stroke: #fff;
  423. }
  424. &:hover {
  425. background-color: var(--color-navy-600);
  426. }
  427. }
  428. &:hover {
  429. border: 1px solid rgba(108, 133, 149, 0.2);
  430. }
  431. .btn-icon {
  432. display: flex;
  433. align-items: center;
  434. svg {
  435. width: px2rpx(18);
  436. height: px2rpx(18);
  437. }
  438. }
  439. &.icon-only {
  440. padding: px2rpx(8);
  441. }
  442. }
  443. }
  444. }
  445. .info-section {
  446. display: flex;
  447. gap: px2rpx(24);
  448. padding: px2rpx(16) 0;
  449. border-top: 1px solid rgba(108, 133, 149, 0.12);
  450. border-bottom: 1px solid rgba(108, 133, 149, 0.12);
  451. margin: px2rpx(16) 0;
  452. .info-column {
  453. flex: 1;
  454. display: flex;
  455. flex-direction: column;
  456. gap: px2rpx(12);
  457. }
  458. .info-item {
  459. display: flex;
  460. justify-content: space-between;
  461. align-items: flex-end;
  462. font-size: px2rpx(14);
  463. .label {
  464. color: #6c8595;
  465. }
  466. .line {
  467. flex: 1;
  468. height: 1px;
  469. border-top: 1px dashed rgba(108, 133, 149, 0.5);
  470. margin-bottom: px2rpx(1);
  471. }
  472. .value {
  473. font-weight: 500;
  474. color: #2e3a47;
  475. }
  476. }
  477. }
  478. @media screen and (max-width: 768px) {
  479. .info-section {
  480. flex-direction: column;
  481. gap: px2rpx(12);
  482. }
  483. }
  484. .extra-actions {
  485. display: flex;
  486. align-items: center;
  487. gap: px2rpx(8);
  488. margin-bottom: px2rpx(12);
  489. .copy-row {
  490. display: flex;
  491. align-items: center;
  492. gap: px2rpx(8);
  493. font-size: px2rpx(14);
  494. .label {
  495. color: #6c8595;
  496. min-width: px2rpx(70);
  497. }
  498. .value {
  499. flex: 1;
  500. color: #2e3a47;
  501. font-family: monospace;
  502. }
  503. .copy-btn {
  504. background: transparent;
  505. border: 1px solid rgba(108, 133, 149, 0);
  506. padding: 0;
  507. cursor: pointer;
  508. color: #6c8595;
  509. width: px2rpx(32);
  510. height: px2rpx(32);
  511. display: flex;
  512. align-items: center;
  513. justify-content: center;
  514. box-sizing: border-box;
  515. svg {
  516. width: px2rpx(20);
  517. height: px2rpx(20);
  518. }
  519. &:hover {
  520. background-color: rgba(108, 133, 149, 0.05);
  521. border: 1px solid rgba(108, 133, 149, 0.2);
  522. }
  523. }
  524. }
  525. .change-password-btn {
  526. background: transparent;
  527. box-sizing: border-box;
  528. border: 1px solid rgba(108, 133, 149, 0);
  529. border-radius: px2rpx(8);
  530. padding: px2rpx(8) px2rpx(16);
  531. font-size: px2rpx(14);
  532. color: #2e3a47;
  533. display: inline-flex;
  534. gap: px2rpx(8);
  535. cursor: pointer;
  536. margin: 0;
  537. // transition: all 0.2s;
  538. .btn-icon svg {
  539. width: px2rpx(16);
  540. height: px2rpx(16);
  541. }
  542. &:hover {
  543. background-color: rgba(108, 133, 149, 0.05);
  544. border: 1px solid rgba(108, 133, 149, 0.2);
  545. }
  546. }
  547. }
  548. .info-bottom {
  549. overflow: hidden;
  550. }
  551. .notificators {
  552. // 预留通知区域
  553. }
  554. }
  555. // 响应式:屏幕宽度 > 1100px 时,隐藏移动端按钮,显示桌面端按钮
  556. @media screen and (min-width: 1100px) {
  557. .account-card {
  558. .main-content {
  559. .mobile-buttons {
  560. display: none;
  561. }
  562. .desktop-buttons {
  563. display: flex;
  564. gap: px2rpx(8);
  565. justify-content: flex-end;
  566. }
  567. }
  568. }
  569. }
  570. </style>