index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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, getUserIdentity } 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 exitBtn = () => {
  66. cacheManager.clearAll();
  67. uni.redirectTo({
  68. url: '/pages/login/index'
  69. });
  70. }
  71. // 关于我们
  72. function aboutClick(){
  73. uni.redirectTo({
  74. url: '/pages/my/aboutPage'
  75. });
  76. }
  77. // 订单
  78. function orderClick(){
  79. uni.redirectTo({
  80. url: '/pages/pay/order'
  81. });
  82. }
  83. // 获取用户数据
  84. function getMyInfo(){
  85. myInfo({}).then(res => {
  86. getUserImg(res.data.growth)
  87. myInfoData.userName = res.data.userName;
  88. myInfoData.credit = res.data.credit;
  89. myInfoData.vipFlag = res.data.vipFlag;
  90. })
  91. }
  92. // 获取用户头像
  93. function getUserImg(data){
  94. switch (data) {
  95. case 0:
  96. myInfoData.userImg = 'static/images/my/head-img0.png'
  97. break;
  98. case 10:
  99. myInfoData.userImg = 'static/images/my/head-img1.png'
  100. break;
  101. case 20:
  102. myInfoData.userImg = 'static/images/my/head-img2.png'
  103. break;
  104. case 50:
  105. myInfoData.userImg = 'static/images/my/head-img30.png'
  106. break;
  107. default:
  108. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  109. break;
  110. }
  111. }
  112. // 会员权益按钮
  113. function hyqyBtn(){
  114. if(loginFlag.value){
  115. uni.redirectTo({
  116. url: '/pages/pay/svip'
  117. })
  118. }else{
  119. toast("当前为游客模式请登录!")
  120. uni.redirectTo({
  121. url: '/pages/login/index'
  122. })
  123. }
  124. }
  125. // 判断是否是游客
  126. function myGetAuth(){
  127. let LocalStorage = cacheManager.get('auth');
  128. if (LocalStorage) {
  129. // 非游客
  130. loginFlag.value = true;
  131. // console.log(loginFlag.value,'非游客');
  132. getMyInfo();
  133. } else {
  134. loginFlag.value = false;
  135. myInfoData.userName = '游客';
  136. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  137. // console.log(loginFlag.value,'游客');
  138. }
  139. }
  140. onLoad((options) => {
  141. myGetAuth();
  142. const instance = getCurrentInstance();
  143. // console.log(instance.appContext.config.globalProperties,'instance.appContext.config.globalProperties')
  144. })
  145. function checkWrong() {
  146. const AuthCode = getUserIdentity();
  147. if (AuthCode == 'Visitor') {
  148. toast(MESSAGE_VISITER_TO_LOGIN);
  149. uni.navigateTo({
  150. url: '/pages/login/index'
  151. });
  152. return;
  153. }
  154. uni.redirectTo({
  155. url: '/pages/wrong/index'
  156. })
  157. }
  158. </script>