index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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">
  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="quitClick">
  30. <icon class="list-icon login-out-icon"></icon>
  31. <text>退出登录</text>
  32. </view>
  33. </view>
  34. <CustomTabBar></CustomTabBar>
  35. </view>
  36. </template>
  37. <script setup>
  38. import {logout} from '@/api/login.js'
  39. import {myInfo} from '@/api/my.js'
  40. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  41. import {getCurrentInstance} from 'vue';
  42. import {onLoad} from '@dcloudio/uni-app';
  43. import {getAuth} from '@/utils/auth.js';
  44. import {reactive,ref} from "vue";
  45. import { toast } from "../../utils/common";
  46. let loginFlag = ref(false);
  47. let myInfoData = reactive({
  48. userImg: 'static/images/my/head-unlogin-img.png',
  49. userName: '',
  50. credit: '',
  51. vipFlag: '',
  52. });
  53. const quitClick = () => {
  54. uni.showModal({
  55. title: '提示',
  56. content: '你确定要执行这个操作吗?',
  57. success: (res) => {
  58. if (res.confirm) {
  59. quit();
  60. } else if (res.cancel) {
  61. console.log('用户点击了取消');
  62. }
  63. }
  64. });
  65. }
  66. const quit = () => {
  67. uni.removeStorage({
  68. key: 'Mta-Auth',
  69. success: function(res) {
  70. console.log('success');
  71. uni.navigateTo({
  72. url: '/pages/login/index'
  73. });
  74. }
  75. });
  76. }
  77. // 订单
  78. function orderClick(){
  79. uni.navigateTo({
  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. if (getAuth()) {
  128. // 已登录
  129. loginFlag.value = true;
  130. console.log(loginFlag.value,'已登录');
  131. getMyInfo();
  132. } else {
  133. loginFlag.value = false;
  134. myInfoData.userName = '游客';
  135. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  136. console.log(loginFlag.value,'未登录');
  137. }
  138. }
  139. onLoad((options) => {
  140. myGetAuth();
  141. const instance = getCurrentInstance();
  142. // console.log(instance.appContext.config.globalProperties,'instance.appContext.config.globalProperties')
  143. })
  144. </script>