index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. <swiper class="my-hyqy-swiper" circular :indicator-dots="hyqyData.indicatorDots" :autoplay="hyqyData.autoplay"
  14. :interval="hyqyData.interval" :duration="hyqyData.duration" indicator-color="#5195d3" indicator-active-color="#83d9ff">
  15. <!-- 1.数学 2.英语-->
  16. <swiper-item v-for="(item, index) in 2" :key="index" class="hyqy-box" :class="getHyqyClass(index)">
  17. <view class="hyqy-btn" @click="hyqyBtn(index)" v-if="getHyqyBtn(index)"></view>
  18. </swiper-item>
  19. </swiper>
  20. <view class="my-list-box">
  21. <view class="list-row" @click="telClick">
  22. <icon class="list-icon tel-icon"></icon>
  23. <text>手机号码</text>
  24. </view>
  25. <view class="list-row" @click="checkWrong">
  26. <icon class="list-icon error-icon"></icon>
  27. <text>我的错题</text>
  28. </view>
  29. <view class="list-row" @click="orderClick">
  30. <icon class="list-icon order-icon"></icon>
  31. <text>我的订单</text>
  32. </view>
  33. <view class="list-row no-jt" @click="aboutClick">
  34. <icon class="list-icon about-icon"></icon>
  35. <text>关于我们</text>
  36. </view>
  37. <view class="list-row no-jt" @click="exitLogin">
  38. <icon class="list-icon login-out-icon"></icon>
  39. <text>退出登录</text>
  40. </view>
  41. </view>
  42. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  43. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  44. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :content="YouKeContent"></tip-middle-dialog>
  45. <tel-dialog @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  46. </view>
  47. </template>
  48. <script setup>
  49. import {toast,getUserIdentity} from "@/utils/common";
  50. import cacheManager from '@/utils/cacheManager.js';
  51. import {logout} from '@/api/login.js'
  52. import {myInfo} from '@/api/my.js'
  53. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  54. import {getCurrentInstance} from 'vue';
  55. import {onLoad} from '@dcloudio/uni-app';
  56. import {reactive,ref} from "vue";
  57. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue';
  58. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  59. import telDialog from './telDialog.vue'
  60. import {MESSAGE_VISITER_TO_LOGIN} from "@/utils/constant.js"
  61. const zhangId = ref(null);
  62. const nianji = ref(null);
  63. const cardId = ref(null);
  64. const tipContent = '你确定要执行这个操作吗?';
  65. const YouKeContent = '您当前是游客身份,登录后才能浏览内容,现在去登录?';
  66. let hyqyData = reactive({
  67. indicatorDots: true,
  68. autoplay: true,
  69. interval: 2000,
  70. duration: 500
  71. });
  72. let loginFlag = ref(false);
  73. let telDialogFlag = ref(false);
  74. let myInfoData = reactive({
  75. userImg: 'static/images/my/head-unlogin-img.png',
  76. userName: '',
  77. credit: '',
  78. vipFlag: '',
  79. });
  80. let routerOpt = ref(false);
  81. const exitDialogRef = ref(null);
  82. const youkeDialogRef = ref(null);
  83. const exitLogin = () => {
  84. exitDialogRef.value.handleShow();
  85. }
  86. // 退出按钮
  87. const exitBtn = () => {
  88. logout().then(res => {
  89. cacheManager.clearAll();
  90. uni.redirectTo({
  91. url: '/pages/login/index'
  92. });
  93. }).catch(err => {
  94. toast('退出登录失败,请稍后重试')
  95. })
  96. }
  97. // 游客弹窗---确定
  98. function ykConfirm(){
  99. uni.redirectTo({
  100. url: '/pages/login/index'
  101. });
  102. }
  103. // 手机号码
  104. function telClick(){
  105. if(loginFlag.value){
  106. telDialogFlag.value = true;
  107. }else{
  108. youkeDialogRef.value.handleShow();
  109. }
  110. }
  111. // 手机号码绑定
  112. function bindBtn(){
  113. myGetAuth()
  114. }
  115. // 关闭手机号码弹窗
  116. function telClose(){
  117. telDialogFlag.value = false;
  118. }
  119. // 关于我们
  120. function aboutClick(){
  121. uni.redirectTo({
  122. url: '/pages/my/aboutPage'
  123. });
  124. }
  125. // 订单
  126. function orderClick(){
  127. if(loginFlag.value){
  128. uni.redirectTo({
  129. url: '/pages/pay/order'
  130. });
  131. }else{
  132. youkeDialogRef.value.handleShow();
  133. }
  134. }
  135. // 获取用户数据
  136. function getMyInfo(){
  137. myInfo({}).then(res => {
  138. getUserImg(res.data.growth)
  139. myInfoData.userName = res.data.userName;
  140. myInfoData.credit = res.data.credit;
  141. })
  142. }
  143. // 获取用户头像
  144. function getUserImg(data){
  145. switch (data) {
  146. case 0:
  147. myInfoData.userImg = 'static/images/my/head-img0.png'
  148. break;
  149. case 10:
  150. myInfoData.userImg = 'static/images/my/head-img1.png'
  151. break;
  152. case 20:
  153. myInfoData.userImg = 'static/images/my/head-img2.png'
  154. break;
  155. case 50:
  156. myInfoData.userImg = 'static/images/my/head-img30.png'
  157. break;
  158. default:
  159. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  160. break;
  161. }
  162. }
  163. // 会员权益按钮
  164. function hyqyBtn(index){
  165. /* index为学科 1数学 2英语 */
  166. if(loginFlag.value){
  167. // 非游客
  168. uni.redirectTo({
  169. url: '/pages/pay/svip'
  170. })
  171. }else{
  172. // 游客
  173. youkeDialogRef.value.handleShow();
  174. }
  175. }
  176. // 判断是否是游客
  177. function myGetAuth(){
  178. let LocalStorage = cacheManager.get('auth');
  179. if (LocalStorage) {
  180. // 非游客
  181. noYoukeFun()
  182. }else{
  183. youkeFun();
  184. }
  185. }
  186. // 游客
  187. function youkeFun(){
  188. zhangId.value = routerOpt.zhangId
  189. nianji.value = routerOpt.nianji
  190. cardId.value = routerOpt.cardId
  191. // my游客
  192. loginFlag.value = false;
  193. myInfoData.userName = '游客';
  194. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  195. }
  196. // 非游客
  197. function noYoukeFun(){
  198. loginFlag.value = true;
  199. getMyInfo();
  200. }
  201. // 获取会员权益card class
  202. function getHyqyClass(index){
  203. let VipIndex =index +1;
  204. if(cacheManager.get('auth')){
  205. // 非游客
  206. let VipArr = cacheManager.get('auth').cardList;
  207. if (VipArr.includes(VipIndex)) {
  208. return 'hyqy-box' + VipIndex;
  209. } else {
  210. return 'hyqy-disabled-box' + VipIndex;
  211. }
  212. }else{
  213. // 游客
  214. return 'hyqy-disabled-box' + VipIndex;
  215. }
  216. }
  217. //获取会员权益按钮是否显示
  218. function getHyqyBtn(index){
  219. let VipIndex =index +1;
  220. if(cacheManager.get('auth')){
  221. let VipArr = cacheManager.get('auth').cardList;
  222. if (VipArr.includes(VipIndex)) {
  223. return false;
  224. } else {
  225. return true;
  226. }
  227. }else{
  228. // 游客
  229. return 'hyqy-disabled-box' + VipIndex;
  230. }
  231. }
  232. onLoad((options) => {
  233. if(!cacheManager.get('auth')){
  234. // 游客
  235. routerOpt = options;
  236. youkeFun();
  237. }else{
  238. // 非游客
  239. noYoukeFun();
  240. }
  241. })
  242. function checkWrong() {
  243. if(loginFlag.value){
  244. const AuthCode = getUserIdentity();
  245. if (AuthCode == 'Visitor') {
  246. toast(MESSAGE_VISITER_TO_LOGIN);
  247. uni.navigateTo({
  248. url: '/pages/login/index'
  249. });
  250. return;
  251. }
  252. uni.redirectTo({
  253. url: '/pages/wrong/index'
  254. })
  255. }else{
  256. youkeDialogRef.value.handleShow();
  257. }
  258. }
  259. </script>