mine.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <route lang="json5">
  2. {
  3. layout: 'default',
  4. needLogin: true,
  5. style: {
  6. navigationStyle: 'custom',
  7. },
  8. }
  9. </route>
  10. <script lang="ts" setup>
  11. import { getWalletAccountInfo } from '@/api/wallet'
  12. import { t } from '@/locale'
  13. import { useUserStore } from '@/store/user'
  14. import { formatNumber } from '@/utils'
  15. import { toPage } from '@/utils/page'
  16. defineOptions({
  17. name: 'Mine', // 我的
  18. })
  19. // 获取屏幕边界到安全区域距离
  20. const systemInfo = uni.getSystemInfoSync()
  21. const safeAreaInsets = systemInfo.safeAreaInsets
  22. // 用户状态管理
  23. const userStore = useUserStore()
  24. // 判断是否已登录
  25. const isLoggedIn = computed(() => {
  26. return !!userStore.token
  27. })
  28. // 获取用户信息
  29. const userInfo = computed(() => {
  30. return userStore.userInfo
  31. })
  32. const groupList = ref([
  33. { name: t('mine.group.toPay'), url: `/pages/myOrders/myOrders`, type: 1, icon: '/static/icons/to-pay.png' },
  34. { name: t('mine.group.success'), url: `/pages/myOrders/myOrders`, type: 2, icon: '/static/icons/success.png' },
  35. { name: t('mine.group.failed'), url: `/pages/myOrders/myOrders`, type: 3, icon: '/static/icons/failed.png' },
  36. { name: t('mine.group.reward'), url: `/pages/myOrders/myOrders`, type: 4, icon: '/static/icons/reward.png' },
  37. ])
  38. const menuList = ref([
  39. { name: t('mine.menu.profile'), url: '/pages/mine/myProfile', icon: '/static/icons/my-profile.png' },
  40. { name: t('mine.menu.address'), url: '/pages/mine/addressBook', icon: '/static/icons/address-book.png' },
  41. { name: t('mine.menu.share'), url: '/pages/mine/share', icon: '/static/icons/share.png' },
  42. { name: t('mine.menu.favorite'), url: '/pages/mine/myFavorite', icon: '/static/icons/my-favorite.png' },
  43. { name: t('mine.menu.chat'), url: '', icon: '/static/icons/live-chat.png' },
  44. { name: t('mine.menu.activity'), url: '/pages/referEarn/referEarn', icon: '/static/icons/activity-group.png' },
  45. ])
  46. const walletInfo = ref<any>({})
  47. async function getWalletInfo() {
  48. // 获取钱包信息-查询余额
  49. const res = await getWalletAccountInfo()
  50. console.log(res)
  51. walletInfo.value = res?.data?.balance
  52. }
  53. onShow(() => {
  54. getWalletInfo()
  55. })
  56. </script>
  57. <template>
  58. <view
  59. class="flex items-center justify-between bg-[rgba(var(--wot-color-theme-rgb),0.3)] pb-48rpx pl-24rpx pr-54rpx"
  60. :style="{ paddingTop: `${safeAreaInsets?.top + 3}px` }"
  61. >
  62. <view class="flex items-center">
  63. <wd-img
  64. width="96rpx"
  65. height="96rpx"
  66. round
  67. :src="isLoggedIn ? userInfo?.headPic : '/static/images/default-avatar.png'"
  68. />
  69. <!-- 已登录 -->
  70. <view v-if="isLoggedIn" class="ml-24rpx text-32rpx font-bold">
  71. {{ userInfo?.name || userInfo?.username || 'User' }}
  72. </view>
  73. <!-- 未登录 -->
  74. <view v-else class="ml-24rpx flex items-center">
  75. <wd-button size="small" custom-class="mr-20rpx! bg-transparent!" plain @click="toPage('/pages/register/register')">
  76. {{ $t('mine.auth.register') }}
  77. </wd-button>
  78. <wd-button size="small" @click="toPage('/pages/login/login')">
  79. {{ $t('mine.auth.login') }}
  80. </wd-button>
  81. </view>
  82. </view>
  83. <wd-icon name="setting" color="#3A444C" size="36rpx" @click="toPage('/pages/mine/setting')" />
  84. </view>
  85. <view class="relative rounded-tl-24rpx rounded-tr-24rpx bg-white px-24rpx pb-24rpx pt-28rpx -top-24rpx">
  86. <view class="mb-18rpx text-32rpx">
  87. {{ $t('mine.wallet.title') }}
  88. </view>
  89. <view
  90. class="flex items-center justify-between rounded-12rpx bg-[rgba(var(--wot-color-theme-rgb),0.1)] px-16rpx py-22rpx"
  91. >
  92. <view class="flex items-center" @click="toPage('/pages/wallet/myWallet')">
  93. <wd-img width="84rpx" height="84rpx" round src="/static/icons/wallet-balance.png" />
  94. <view class="ml-18rpx">
  95. <view class="text-22rpx text-#595959">
  96. {{ $t('mine.wallet.balance') }}
  97. </view>
  98. <view class="text-44rpx text-[var(--wot-color-theme)] font-bold">
  99. {{ formatNumber(walletInfo.balance) }}
  100. </view>
  101. </view>
  102. </view>
  103. <view class="flex flex-col items-end">
  104. <wd-button size="small" @click="toPage('/pages/wallet/recharge')">
  105. {{ $t('mine.wallet.recharge') }}
  106. </wd-button>
  107. </view>
  108. </view>
  109. </view>
  110. <view class="mb-20rpx bg-white px-24rpx pb-32rpx pt-26rpx">
  111. <view class="mb-24rpx flex items-center justify-between">
  112. <text class="text-32rpx font-bold">
  113. {{ $t('mine.group.title') }}
  114. </text>
  115. <view class="flex items-center" @click="toPage('/pages/myOrders/myOrders')">
  116. <text class="mr-8rpx text-22rpx text-#3A444C">
  117. {{ $t('mine.group.all') }}
  118. </text>
  119. <wd-icon name="chevron-right" size="28rpx" />
  120. </view>
  121. </view>
  122. <view class="grid grid-cols-4 gap-24rpx">
  123. <view v-for="(item, index) in groupList" :key="index" class="flex flex-col items-center" @click="toPage(item.url, { type: item.type })">
  124. <wd-img width="48rpx" height="48rpx" :src="item.icon" />
  125. <view class="mt-18rpx text-22rpx text-#3A444C">
  126. {{ item.name }}
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. <view class="grid grid-cols-3 gap-24rpx bg-white py-45rpx">
  132. <view v-for="(item, index) in menuList" :key="index" class="flex flex-col items-center" @click="toPage(item.url)">
  133. <wd-img width="48rpx" height="48rpx" :src="item.icon" />
  134. <view class="mt-18rpx text-22rpx text-#3A444C">
  135. {{ item.name }}
  136. </view>
  137. </view>
  138. </view>
  139. </template>