index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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" @click="telClick" v-if="loginFlag">
  18. <icon class="list-icon tel-icon"></icon>
  19. <text>手机号码</text>
  20. </view>
  21. <view class="list-row" @click="checkWrong" v-if="loginFlag">
  22. <icon class="list-icon error-icon"></icon>
  23. <text>我的错题</text>
  24. </view>
  25. <view class="list-row" @click="orderClick" v-if="loginFlag">
  26. <icon class="list-icon order-icon"></icon>
  27. <text>我的订单</text>
  28. </view>
  29. <view class="list-row no-jt" @click="aboutClick">
  30. <icon class="list-icon about-icon"></icon>
  31. <text>关于我们</text>
  32. </view>
  33. <view class="list-row no-jt" @click="exitLogin">
  34. <icon class="list-icon login-out-icon"></icon>
  35. <text>退出登录</text>
  36. </view>
  37. </view>
  38. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  39. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  40. <tel-dialog @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  41. </view>
  42. </template>
  43. <script setup>
  44. import {toast,getUserIdentity} from "@/utils/common";
  45. import cacheManager from '@/utils/cacheManager.js';
  46. import {logout} from '@/api/login.js'
  47. import {myInfo} from '@/api/my.js'
  48. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  49. import {getCurrentInstance} from 'vue';
  50. import {onLoad} from '@dcloudio/uni-app';
  51. import {reactive,ref} from "vue";
  52. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue';
  53. import telDialog from './telDialog.vue'
  54. import {MESSAGE_VISITER_TO_LOGIN} from "@/utils/constant.js"
  55. const zhangId = ref(null);
  56. const nianji = ref(null);
  57. const cardId = ref(null);
  58. const tipContent = '你确定要执行这个操作吗?';
  59. let loginFlag = ref(false);
  60. let telDialogFlag = ref(false);
  61. let myInfoData = reactive({
  62. userImg: 'static/images/my/head-unlogin-img.png',
  63. userName: '',
  64. credit: '',
  65. vipFlag: '',
  66. });
  67. let routerOpt = ref(false);
  68. const exitDialogRef = ref(null);
  69. const exitLogin = () => {
  70. exitDialogRef.value.handleShow();
  71. }
  72. const exitBtn = () => {
  73. logout().then(res => {
  74. cacheManager.clearAll();
  75. uni.redirectTo({
  76. url: '/pages/login/index'
  77. });
  78. }).catch(err => {
  79. toast('退出登录失败,请稍后重试')
  80. })
  81. }
  82. // 手机号码
  83. function telClick(){
  84. telDialogFlag.value = true;
  85. }
  86. // 手机号码绑定
  87. function bindBtn(){
  88. myGetAuth()
  89. }
  90. // 关闭手机号码弹窗
  91. function telClose(){
  92. telDialogFlag.value = false;
  93. }
  94. // 关于我们
  95. function aboutClick(){
  96. uni.redirectTo({
  97. url: '/pages/my/aboutPage'
  98. });
  99. }
  100. // 订单
  101. function orderClick(){
  102. uni.redirectTo({
  103. url: '/pages/pay/order'
  104. });
  105. }
  106. // 获取用户数据
  107. function getMyInfo(){
  108. myInfo({}).then(res => {
  109. getUserImg(res.data.growth)
  110. myInfoData.userName = res.data.userName;
  111. myInfoData.credit = res.data.credit;
  112. myInfoData.vipFlag = res.data.vipFlag;
  113. })
  114. }
  115. // 获取用户头像
  116. function getUserImg(data){
  117. switch (data) {
  118. case 0:
  119. myInfoData.userImg = 'static/images/my/head-img0.png'
  120. break;
  121. case 10:
  122. myInfoData.userImg = 'static/images/my/head-img1.png'
  123. break;
  124. case 20:
  125. myInfoData.userImg = 'static/images/my/head-img2.png'
  126. break;
  127. case 50:
  128. myInfoData.userImg = 'static/images/my/head-img30.png'
  129. break;
  130. default:
  131. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  132. break;
  133. }
  134. }
  135. // 会员权益按钮
  136. function hyqyBtn(){
  137. if(loginFlag.value){
  138. uni.redirectTo({
  139. url: '/pages/pay/svip'
  140. })
  141. }else{
  142. toast("当前为游客模式请登录!")
  143. uni.redirectTo({
  144. url: '/pages/login/index'
  145. })
  146. }
  147. }
  148. // 判断是否是游客
  149. function myGetAuth(){
  150. let LocalStorage = cacheManager.get('auth');
  151. if (LocalStorage) {
  152. // 非游客
  153. noYoukeFun()
  154. }else{
  155. youkeFun();
  156. }
  157. }
  158. // 游客
  159. function youkeFun(){
  160. zhangId.value = routerOpt.zhangId
  161. nianji.value = routerOpt.nianji
  162. cardId.value = routerOpt.cardId
  163. // my游客
  164. loginFlag.value = false;
  165. myInfoData.userName = '游客';
  166. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  167. }
  168. // 非游客
  169. function noYoukeFun(){
  170. loginFlag.value = true;
  171. getMyInfo();
  172. }
  173. onLoad((options) => {
  174. if(!cacheManager.get('auth')){
  175. // 游客
  176. routerOpt = options;
  177. youkeFun();
  178. }else{
  179. // 非游客
  180. noYoukeFun();
  181. }
  182. })
  183. function checkWrong() {
  184. const AuthCode = getUserIdentity();
  185. if (AuthCode == 'Visitor') {
  186. toast(MESSAGE_VISITER_TO_LOGIN);
  187. uni.navigateTo({
  188. url: '/pages/login/index'
  189. });
  190. return;
  191. }
  192. uni.redirectTo({
  193. url: '/pages/wrong/index'
  194. })
  195. }
  196. </script>