index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. const tipContent = '你确定要执行这个操作吗?';
  49. let loginFlag = ref(false);
  50. let myInfoData = reactive({
  51. userImg: 'static/images/my/head-unlogin-img.png',
  52. userName: '',
  53. credit: '',
  54. vipFlag: '',
  55. });
  56. const exitDialogRef = ref(null);
  57. const exitLogin = () => {
  58. exitDialogRef.value.handleShow();
  59. }
  60. const exitBtn = () => {
  61. cacheManager.clearAll();
  62. uni.navigateTo({
  63. url: '/pages/login/index'
  64. });
  65. }
  66. // 订单
  67. function orderClick(){
  68. uni.navigateTo({
  69. url: '/pages/pay/order'
  70. });
  71. }
  72. // 获取用户数据
  73. function getMyInfo(){
  74. myInfo({}).then(res => {
  75. getUserImg(res.data.growth)
  76. myInfoData.userName = res.data.userName;
  77. myInfoData.credit = res.data.credit;
  78. myInfoData.vipFlag = res.data.vipFlag;
  79. })
  80. }
  81. // 获取用户头像
  82. function getUserImg(data){
  83. switch (data) {
  84. case 0:
  85. myInfoData.userImg = 'static/images/my/head-img0.png'
  86. break;
  87. case 10:
  88. myInfoData.userImg = 'static/images/my/head-img1.png'
  89. break;
  90. case 20:
  91. myInfoData.userImg = 'static/images/my/head-img2.png'
  92. break;
  93. case 50:
  94. myInfoData.userImg = 'static/images/my/head-img30.png'
  95. break;
  96. default:
  97. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  98. break;
  99. }
  100. }
  101. // 会员权益按钮
  102. function hyqyBtn(){
  103. if(loginFlag.value){
  104. uni.redirectTo({
  105. url: '/pages/pay/svip'
  106. })
  107. }else{
  108. toast("当前为游客模式请登录!")
  109. uni.redirectTo({
  110. url: '/pages/login/index'
  111. })
  112. }
  113. }
  114. // 判断是否是游客
  115. function myGetAuth(){
  116. let LocalStorage = cacheManager.get('auth');
  117. if (LocalStorage) {
  118. // 非游客
  119. loginFlag.value = true;
  120. // console.log(loginFlag.value,'非游客');
  121. getMyInfo();
  122. } else {
  123. loginFlag.value = false;
  124. myInfoData.userName = '游客';
  125. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  126. // console.log(loginFlag.value,'游客');
  127. }
  128. }
  129. onLoad((options) => {
  130. myGetAuth();
  131. const instance = getCurrentInstance();
  132. // console.log(instance.appContext.config.globalProperties,'instance.appContext.config.globalProperties')
  133. })
  134. </script>