AccountCard.vue 22 KB

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