index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="balance-box">
  3. <view class="first-row">
  4. <view class="vip" v-if="appStore.isLogin">
  5. VIP会员<text>{{ appStore?.$userInfo?.level || 0 }}级</text>
  6. </view>
  7. <view v-else @click="toLogin">未登录</view>
  8. <view class="gold-price">
  9. <text class="text">实时金价&nbsp;</text>
  10. <up-loading-icon v-if="realGoldprice === 0"></up-loading-icon>
  11. <text class="real-price" v-else>{{ realGoldprice }}</text>
  12. </view>
  13. </view>
  14. <view class="growth">
  15. <div class="row-value">
  16. <view class="current">
  17. 成长值{{ appStore?.$userInfo?.experience || 0 }}
  18. </view>
  19. <view class="total">
  20. {{ appStore?.$userInfo?.experience || 0 }}/{{
  21. appStore?.$userInfo?.experienceCount || 0
  22. }}
  23. </view>
  24. </div>
  25. <up-line-progress
  26. :showText="false"
  27. :percentage="percentExperience"
  28. activeColor="#C99A30"
  29. ></up-line-progress>
  30. </view>
  31. <view class="wealth">
  32. <view class="item" @click="toVaultPage('vault')">
  33. <uni-icons
  34. class="item-icon"
  35. size="28"
  36. color="#CF9834"
  37. customPrefix="iconfont"
  38. type="icon-jinku"
  39. ></uni-icons>
  40. <text class="text">{{ appStore.$userInfo?.goldBalance || 0 }}g</text>
  41. </view>
  42. <view class="item" @click="toVaultPage('balance')">
  43. <uni-icons
  44. class="item-icon"
  45. size="30"
  46. color="#CF9834"
  47. customPrefix="iconfont"
  48. type="icon-qianbao"
  49. ></uni-icons>
  50. <text class="text">¥{{ appStore.$userInfo?.nowMoney || 0 }}</text>
  51. </view>
  52. <view class="item">
  53. <uni-icons
  54. class="item-icon"
  55. size="28"
  56. color="#CF9834"
  57. customPrefix="iconfont"
  58. type="icon-beikehui"
  59. ></uni-icons>
  60. <text class="text">{{ appStore.$userInfo?.integral || 0 }}</text>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script setup>
  66. import { ref, computed } from "vue";
  67. import { onLoad, onShow } from "@dcloudio/uni-app";
  68. import { useAppStore } from "@/stores/app";
  69. import useRealGoldPrice from "@/hooks/useRealGoldPrice";
  70. import { toLogin } from "@/libs/login";
  71. import { getUserInfo } from "@/api/user";
  72. const appStore = useAppStore();
  73. const { realGoldprice, fetchGoldPrice } = useRealGoldPrice("RTJ_Au");
  74. onShow(() => {
  75. fetchUserInfo();
  76. fetchGoldPrice(undefined, 3);
  77. });
  78. function toVaultPage(type) {
  79. uni.navigateTo({ url: `/pages/users/vault/index?type=${type}` })
  80. }
  81. // 获取用户信息
  82. async function fetchUserInfo() {
  83. const { data } = await getUserInfo();
  84. appStore.UPDATE_USERINFO(data);
  85. }
  86. // 计算成长值百分比
  87. const percentExperience = computed(() => {
  88. if (appStore.isLogin) {
  89. const percent = Math.floor(
  90. (appStore?.$userInfo?.experience / appStore?.$userInfo?.experienceCount) *
  91. 100
  92. );
  93. return percent > 100 ? 100 : percent;
  94. }
  95. return 0;
  96. });
  97. </script>
  98. <style lang="scss" scoped>
  99. .balance-box {
  100. margin: 25rpx 30rpx 15rpx;
  101. padding: 30rpx;
  102. background-color: #ffffff;
  103. border-radius: $uni-border-radius-default;
  104. box-shadow: 0 4rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  105. .first-row {
  106. display: flex;
  107. justify-content: space-between;
  108. align-items: center;
  109. .vip {
  110. }
  111. .gold-price {
  112. display: flex;
  113. align-items: center;
  114. .text {
  115. }
  116. .real-price {
  117. font-size: 35rpx;
  118. color: $header-color;
  119. font-weight: 600;
  120. }
  121. }
  122. }
  123. .growth {
  124. margin: 30rpx 0 30rpx;
  125. .row-value {
  126. margin: 0 0 10rpx;
  127. font-size: 20rpx;
  128. display: flex;
  129. justify-content: space-between;
  130. color: $theme-color;
  131. }
  132. }
  133. .wealth {
  134. display: flex;
  135. justify-content: space-between;
  136. .item {
  137. display: flex;
  138. align-items: center;
  139. .item-icon {
  140. margin-right: 10rpx;
  141. }
  142. .text {
  143. }
  144. }
  145. }
  146. }
  147. </style>