my.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="ezy-my-page">
  3. <view class="icon-title-navBar-box">
  4. <view class="nav-bar-title"></view>
  5. </view>
  6. <view class="my-page-box">
  7. <view class="my-head-box">
  8. <icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
  9. <view class="head-content-box">
  10. <text>{{myInfoData.nickName}}</text>
  11. <!-- <view class="ezy-jf-box" v-if="loginFlag">
  12. <icon class="jf-icon"></icon>
  13. <text class="jf-text">{{myInfoData.credit}}</text>
  14. </view> -->
  15. </view>
  16. </view>
  17. <!-- 图 -->
  18. <view class="my-banner-img"></view>
  19. <!-- 设置 -->
  20. <view class="my-list-box">
  21. <view class="list-item" @click="yingyongshezhi">
  22. <icon class="list-icon yysz-icon"></icon>
  23. <text>应用设置</text>
  24. </view>
  25. <view v-if="appleCode=='true'&&currentPlatform=='ios' || currentPlatform=='android'" class="list-item"
  26. @click="duihuamaDuihuan">
  27. <icon class="list-icon duihuanma-icon"></icon>
  28. <text>兑换码</text>
  29. </view>
  30. <view class="list-item" @click="test">
  31. <icon class="list-icon yysz-icon"></icon>
  32. <text>test</text>
  33. </view>
  34. </view>
  35. </view>
  36. <duihuanmaDialog ref="duihuanmaDialogRef" @confirm-btn="duihuanmaBtn" title="兑换"></duihuanmaDialog>
  37. <loginComp ref="loginRef"></loginComp>
  38. <!-- 底部 -->
  39. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  40. </view>
  41. </template>
  42. <script setup>
  43. import duihuanmaDialog from "./components/duihuanmaDialog.vue"
  44. import cacheManager from '../../utils/cacheManager';
  45. import {
  46. myInfo,
  47. zhuxiao,
  48. duihuanmaCode,
  49. myCardList,
  50. commonCardList
  51. } from '@/api/my.js'
  52. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  53. import loginComp from "@/components/loginComp/index.vue"
  54. import {
  55. onLoad,
  56. onShow
  57. } from '@dcloudio/uni-app';
  58. import {
  59. reactive,
  60. ref
  61. } from "vue";
  62. let appleCode =ref(null)
  63. let currentPlatform = ref(null);
  64. let authInfo = ref(null);
  65. let loginRef = ref(null);
  66. let currentTabIndex = ref(3)
  67. let myInfoData = reactive({
  68. userImg: '',
  69. userName: '',
  70. credit: '',
  71. vipFlag: '',
  72. nickName: '',
  73. icon: '',
  74. });
  75. onShow(() => {
  76. currentTabIndex.value = 3
  77. })
  78. /***************** 测试 ******************/
  79. const testRef = ref(null)
  80. function handleTest() {
  81. testRef.value.showPopup(7)
  82. }
  83. /***************** 测试 ******************/
  84. // 获取用户数据
  85. function getMyInfo() {
  86. myInfo({}).then(res => {
  87. myInfoData.userName = res.data.userName;
  88. myInfoData.nickName = res.data.nickName;
  89. appleCode.value = res.data.appleCode.toString()
  90. if (res.data.nickName) {
  91. myInfoData.nickName = res.data.nickName;
  92. } else {
  93. myInfoData.nickName = '鹅状元';
  94. }
  95. if (res.data.icon) {
  96. myInfoData.icon = res.data.icon;
  97. } else {
  98. getUserImg(res.data.growthType)
  99. }
  100. })
  101. }
  102. // 获取用户头像
  103. function getUserImg(data) {
  104. switch (data) {
  105. case 0:
  106. myInfoData.icon = 'static/images/my/head-img0.png'
  107. break;
  108. case 1:
  109. myInfoData.icon = 'static/images/my/head-img1.png'
  110. break;
  111. case 2:
  112. myInfoData.icon = 'static/images/my/head-img2.png'
  113. break;
  114. case 3:
  115. myInfoData.icon = 'static/images/my/head-img3.png'
  116. break;
  117. default:
  118. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  119. break;
  120. }
  121. }
  122. function yingyongshezhi() {
  123. uni.navigateTo({
  124. url: '/pages/chanpinMy/myInfo'
  125. })
  126. }
  127. function duihuamaDuihuan() {
  128. // 兑换码兑换策略
  129. if (currentPlatform.value == 'ios') {
  130. // ios
  131. if (authInfo.value.youke) {
  132. // 非登录
  133. } else {
  134. // 已登录
  135. duihuanmaDialogRef.value.handleShow();
  136. }
  137. } else {
  138. // android
  139. if (authInfo.value.youke) {
  140. // 非登录 -> 去登录
  141. } else {
  142. // 已登录
  143. duihuanmaDialogRef.value.handleShow();
  144. }
  145. }
  146. }
  147. function duihuanmaBtn() {
  148. let req = {
  149. code: data
  150. }
  151. duihuanmaCode(req).then(res => {
  152. if (res.code == 0) {
  153. toast('兑换成功')
  154. const localList = cacheManager.get('auth').levelIdList || []
  155. const mergeList = [...new Set([...localList, ...res.data.levelIdList])]
  156. cacheManager.updateObject('auth', {
  157. levelIdList: mergeList
  158. })
  159. uni.redirectTo({
  160. url: '/pages/my/index'
  161. })
  162. } else {
  163. toast('兑换失败请重试或联系管理员')
  164. return false
  165. }
  166. }).catch(err => {
  167. })
  168. }
  169. onLoad((options) => {
  170. uni.hideTabBar()
  171. getAuthData();
  172. getMyInfo();
  173. isIOSorAndroid()
  174. })
  175. function isIOSorAndroid() {
  176. const systemInfo = uni.getSystemInfoSync();
  177. if (systemInfo.platform == 'ios') {
  178. currentPlatform.value = 'ios'
  179. } else {
  180. currentPlatform.value = 'android'
  181. }
  182. }
  183. function getAuthData() {
  184. authInfo.value = cacheManager.get('auth');
  185. }
  186. function test() {
  187. loginRef.value.showPopup()
  188. }
  189. </script>