index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="ezy-my-page">
  3. <view class="my-head-box">
  4. <icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.userImg + ')'}"></icon>
  5. <view class="head-content-box">
  6. <text>{{myInfoData.userName}}</text>
  7. <view class="jf-box" v-if="loginFlag">
  8. <icon class="jf-icon"></icon>
  9. <text class="jf-text" >{{myInfoData.credit}}</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view :class="loginFlag && myInfoData.vipFlag?'hyqy-box':'hyqy-disabled-box'">
  14. <view class="hyqy-btn" @click="hyqyBtn" v-if="!myInfoData.vipFlag"></view>
  15. </view>
  16. <view class="my-list-box">
  17. <view class="list-row">
  18. <icon class="list-icon tel-icon"></icon>
  19. <text>手机号码</text>
  20. </view>
  21. <view class="list-row" @click="checkWrong">
  22. <icon class="list-icon error-icon"></icon>
  23. <text>我的错题</text>
  24. </view>
  25. <view class="list-row" @click="orderClick">
  26. <icon class="list-icon order-icon"></icon>
  27. <text>我的订单</text>
  28. </view>
  29. <view class="list-row" @click="exitLogin">
  30. <icon class="list-icon login-out-icon"></icon>
  31. <text>退出登录</text>
  32. </view>
  33. </view>
  34. <CustomTabBar></CustomTabBar>
  35. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  36. </view>
  37. </template>
  38. <script setup>
  39. import cacheManager from '@/utils/cacheManager.js';
  40. import {logout} from '@/api/login.js'
  41. import {myInfo} from '@/api/my.js'
  42. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  43. import {getCurrentInstance} from 'vue';
  44. import {onLoad} from '@dcloudio/uni-app';
  45. import {reactive,ref} from "vue";
  46. import { toast } from "../../utils/common";
  47. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  48. import {MESSAGE_VISITER_TO_LOGIN} from "@/utils/constant.js"
  49. const tipContent = '你确定要执行这个操作吗?';
  50. let loginFlag = ref(false);
  51. let myInfoData = reactive({
  52. userImg: 'static/images/my/head-unlogin-img.png',
  53. userName: '',
  54. credit: '',
  55. vipFlag: '',
  56. });
  57. const exitDialogRef = ref(null);
  58. const exitLogin = () => {
  59. exitDialogRef.value.handleShow();
  60. }
  61. const wrongBtn = () => {
  62. toast(MESSAGE_VISITER_TO_LOGIN);
  63. uni.navigateTo({
  64. url: '/pages/login/index'
  65. });
  66. }
  67. const exitBtn = () => {
  68. cacheManager.clearAll();
  69. uni.navigateTo({
  70. url: '/pages/login/index'
  71. });
  72. }
  73. // 订单
  74. function orderClick(){
  75. uni.navigateTo({
  76. url: '/pages/pay/order'
  77. });
  78. }
  79. // 获取用户数据
  80. function getMyInfo(){
  81. myInfo({}).then(res => {
  82. getUserImg(res.data.growth)
  83. myInfoData.userName = res.data.userName;
  84. myInfoData.credit = res.data.credit;
  85. myInfoData.vipFlag = res.data.vipFlag;
  86. })
  87. }
  88. // 获取用户头像
  89. function getUserImg(data){
  90. switch (data) {
  91. case 0:
  92. myInfoData.userImg = 'static/images/my/head-img0.png'
  93. break;
  94. case 10:
  95. myInfoData.userImg = 'static/images/my/head-img1.png'
  96. break;
  97. case 20:
  98. myInfoData.userImg = 'static/images/my/head-img2.png'
  99. break;
  100. case 50:
  101. myInfoData.userImg = 'static/images/my/head-img30.png'
  102. break;
  103. default:
  104. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  105. break;
  106. }
  107. }
  108. // 会员权益按钮
  109. function hyqyBtn(){
  110. if(loginFlag.value){
  111. uni.redirectTo({
  112. url: '/pages/pay/svip'
  113. })
  114. }else{
  115. toast("当前为游客模式请登录!")
  116. uni.redirectTo({
  117. url: '/pages/login/index'
  118. })
  119. }
  120. }
  121. // 判断是否是游客
  122. function myGetAuth(){
  123. let LocalStorage = cacheManager.get('auth');
  124. if (LocalStorage) {
  125. // 非游客
  126. loginFlag.value = true;
  127. // console.log(loginFlag.value,'非游客');
  128. getMyInfo();
  129. } else {
  130. loginFlag.value = false;
  131. myInfoData.userName = '游客';
  132. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  133. // console.log(loginFlag.value,'游客');
  134. }
  135. }
  136. onLoad((options) => {
  137. myGetAuth();
  138. const instance = getCurrentInstance();
  139. // console.log(instance.appContext.config.globalProperties,'instance.appContext.config.globalProperties')
  140. })
  141. function checkWrong() {
  142. uni.redirectTo({
  143. url: '/pages/wrong/index'
  144. })
  145. }
  146. </script>