mine.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <route lang="json5">
  2. {
  3. layout: 'tabbar',
  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(() => !!userStore.token)
  26. // 获取用户信息
  27. const userInfo = computed(() => userStore.userInfo)
  28. const groupList = ref([
  29. { name: t('mine.group.toPay'), url: `/pages/myOrders/myOrders`, type: 1, icon: '/static/icons/to-pay.png' },
  30. { name: t('mine.group.success'), url: `/pages/myOrders/myOrders`, type: 2, icon: '/static/icons/success.png' },
  31. { name: t('mine.group.failed'), url: `/pages/myOrders/myOrders`, type: 3, icon: '/static/icons/failed.png' },
  32. { name: t('mine.group.reward'), url: `/pages/myOrders/myOrders`, type: 4, icon: '/static/icons/reward.png' },
  33. ])
  34. const menuList = ref([
  35. { name: t('mine.menu.profile'), url: '/pages/mine/myProfile', icon: '/static/icons/my-profile.png' },
  36. { name: t('mine.menu.address'), url: '/pages/mine/addressBook', icon: '/static/icons/address-book.png' },
  37. { name: t('mine.menu.share'), url: '/pages/mine/share', icon: '/static/icons/share.png' },
  38. { name: t('mine.menu.favorite'), url: '/pages/mine/myFavorite', icon: '/static/icons/my-favorite.png' },
  39. { name: t('mine.menu.chat'), icon: '/static/icons/live-chat.png' },
  40. { name: t('mine.menu.activity'), url: '/pages/referEarn/referEarn', icon: '/static/icons/activity-group.png' },
  41. ])
  42. function menuClick(item: any) {
  43. if (item.url) {
  44. toPage(item.url)
  45. }
  46. else {
  47. openWhatsApp()
  48. }
  49. }
  50. // 跳转whatsapp
  51. function openWhatsApp() {
  52. // 判断手机是否安装whatsapp
  53. // pname:Android 需要查询的包名 action:ios 需要查询的 URL Scheme
  54. // installed ture:安装 false:未安装
  55. const installed = plus.runtime.isApplicationExist({
  56. pname: 'com.whatsapp',
  57. action: 'whatsapp://',
  58. })
  59. // 电话号码
  60. const phoneNumber = '+8615058371889'
  61. // whatsapp 联系人聊天页面链接
  62. const whatsappUrl = `whatsapp://send?phone=${phoneNumber}`
  63. // whatsapp包名
  64. const pname = 'com.whatsapp'
  65. // 判断手机系统,走不同方法
  66. if (plus.os.name === 'Android') {
  67. if (installed) {
  68. // 手机已安装 直接跳转
  69. plus.runtime.openURL(whatsappUrl)
  70. }
  71. else {
  72. // 手机未安装,跳转到手机商城并搜索whatsapp (国内目前搜不到)
  73. plus.nativeUI.actionSheet(
  74. {
  75. title: '选择应用',
  76. cancel: '取消',
  77. buttons: [{ title: '应用市场' }],
  78. },
  79. ({ index }) => {
  80. switch (index) {
  81. case 1:
  82. plus.runtime.openURL(
  83. `market://details?id=${pname}`,
  84. () => {
  85. // 手机没有应用市场
  86. plus.nativeUI.alert('本机未安装指定的应用')
  87. },
  88. )
  89. }
  90. },
  91. )
  92. }
  93. }
  94. }
  95. const walletInfo = ref<any>({})
  96. async function getWalletInfo() {
  97. // 获取钱包信息-查询余额
  98. const res = await getWalletAccountInfo()
  99. console.log(res)
  100. walletInfo.value = res?.data
  101. }
  102. onShow(() => {
  103. getWalletInfo()
  104. })
  105. onLoad(() => {
  106. // 页面加载时的逻辑
  107. userStore.getUserInfo()
  108. })
  109. </script>
  110. <template>
  111. <view
  112. class="flex items-center justify-between bg-[rgba(var(--wot-color-theme-rgb),0.3)] pb-72rpx pl-24rpx pr-54rpx"
  113. :style="{ paddingTop: `${safeAreaInsets?.top + 24}px` }"
  114. >
  115. <view class="flex items-center">
  116. <wd-img
  117. width="96rpx"
  118. height="96rpx"
  119. round
  120. :src="isLoggedIn ? userInfo?.headPic : '/static/images/default-avatar.png'"
  121. />
  122. <!-- 已登录 -->
  123. <view v-if="isLoggedIn" class="ml-24rpx text-32rpx font-bold">
  124. {{ userInfo?.name || userInfo?.username || 'User' }}
  125. </view>
  126. <!-- 未登录 -->
  127. <view v-else class="ml-24rpx flex items-center">
  128. <wd-button size="small" custom-class="mr-20rpx! bg-transparent!" plain @click="toPage('/pages/register/register')">
  129. {{ $t('mine.auth.register') }}
  130. </wd-button>
  131. <wd-button size="small" @click="toPage('/pages/login/login')">
  132. {{ $t('mine.auth.login') }}
  133. </wd-button>
  134. </view>
  135. </view>
  136. <wd-icon name="setting" color="#3A444C" size="36rpx" @click="toPage('/pages/mine/setting')" />
  137. </view>
  138. <view class="relative rounded-tl-24rpx rounded-tr-24rpx bg-white px-24rpx pb-36rpx pt-32rpx -top-24rpx" @click="toPage('/pages/wallet/myWallet')">
  139. <view class="mb-24rpx text-32rpx">
  140. {{ $t('mine.wallet.title') }}
  141. </view>
  142. <view
  143. class="flex items-center justify-between rounded-12rpx bg-[rgba(var(--wot-color-theme-rgb),0.1)] px-16rpx py-34rpx"
  144. >
  145. <view class="flex items-center">
  146. <wd-img width="84rpx" height="84rpx" round src="/static/icons/wallet-balance.png" />
  147. <view class="ml-18rpx">
  148. <view class="mb-3px text-22rpx text-#595959">
  149. {{ $t('mine.wallet.balance') }}
  150. </view>
  151. <view class="text-44rpx text-[var(--wot-color-theme)] font-bold">
  152. {{ formatNumber(walletInfo.balance) }}
  153. </view>
  154. </view>
  155. </view>
  156. <view class="flex flex-col items-end" @click.stop="toPage('/pages/wallet/recharge')">
  157. <wd-button size="small">
  158. {{ $t('mine.wallet.recharge') }}
  159. </wd-button>
  160. </view>
  161. </view>
  162. </view>
  163. <view class="mb-24rpx bg-white px-24rpx pb-32rpx pt-26rpx">
  164. <view class="mb-24rpx flex items-center justify-between">
  165. <text class="text-32rpx">
  166. {{ $t('mine.group.title') }}
  167. </text>
  168. <view class="flex items-center" @click="toPage('/pages/myOrders/myOrders')">
  169. <text class="mr-8rpx text-22rpx text-#3A444C">
  170. {{ $t('mine.group.all') }}
  171. </text>
  172. <wd-icon name="chevron-right" size="28rpx" />
  173. </view>
  174. </view>
  175. <view class="grid grid-cols-4 gap-24rpx">
  176. <view v-for="(item, index) in groupList" :key="index" class="flex flex-col items-center" @click="toPage(item.url, { type: item.type })">
  177. <wd-img width="48rpx" height="48rpx" :src="item.icon" />
  178. <view class="mt-24rpx text-22rpx text-#3A444C">
  179. {{ item.name }}
  180. </view>
  181. </view>
  182. </view>
  183. </view>
  184. <view class="grid grid-cols-3 gap-48rpx bg-white py-65rpx">
  185. <view v-for="(item, index) in menuList" :key="index" class="flex flex-col items-center" @click="menuClick(item)">
  186. <wd-img width="48rpx" height="48rpx" :src="item.icon" />
  187. <view class="mt-24rpx text-22rpx text-#3A444C">
  188. {{ item.name }}
  189. </view>
  190. </view>
  191. </view>
  192. </template>