index.vue 4.5 KB

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