index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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="ezy-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="MESSAGE_VISITER_TO_LOGIN"></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. let hyqyData = reactive({
  66. indicatorDots: true,
  67. autoplay: true,
  68. interval: 10000,
  69. duration: 500
  70. });
  71. let loginFlag = ref(false);
  72. let telDialogFlag = ref(false);
  73. let myInfoData = reactive({
  74. userImg: 'static/images/my/head-unlogin-img.png',
  75. userName: '',
  76. credit: '',
  77. vipFlag: '',
  78. });
  79. let routerOpt = ref(false);
  80. const exitDialogRef = ref(null);
  81. const youkeDialogRef = ref(null);
  82. const exitLogin = () => {
  83. exitDialogRef.value.handleShow();
  84. }
  85. // 退出按钮
  86. const exitBtn = () => {
  87. if(loginFlag.value){
  88. logout().then(res => {
  89. cacheManager.clearAll();
  90. uni.redirectTo({
  91. url: '/pages/login/index'
  92. });
  93. }).catch(err => {
  94. toast('退出登录失败,请稍后重试')
  95. })
  96. }else{
  97. uni.redirectTo({
  98. url: '/pages/login/index'
  99. });
  100. }
  101. }
  102. // 游客弹窗---确定
  103. function ykConfirm(){
  104. uni.redirectTo({
  105. url: '/pages/login/index'
  106. });
  107. }
  108. // 手机号码
  109. function telClick(){
  110. if(loginFlag.value){
  111. telDialogFlag.value = true;
  112. }else{
  113. youkeDialogRef.value.handleShow();
  114. }
  115. }
  116. // 手机号码绑定
  117. function bindBtn(){
  118. telDialogFlag.value = false;
  119. myGetAuth()
  120. }
  121. // 关闭手机号码弹窗
  122. function telClose(){
  123. telDialogFlag.value = false;
  124. }
  125. // 关于我们
  126. function aboutClick(){
  127. uni.redirectTo({
  128. url: '/pages/my/aboutPage'
  129. });
  130. }
  131. // 订单
  132. function orderClick(){
  133. if(loginFlag.value){
  134. uni.redirectTo({
  135. url: '/pages/pay/order'
  136. });
  137. }else{
  138. youkeDialogRef.value.handleShow();
  139. }
  140. }
  141. // 获取用户数据
  142. function getMyInfo(){
  143. myInfo({}).then(res => {
  144. getUserImg(res.data.growth)
  145. myInfoData.userName = res.data.userName;
  146. myInfoData.credit = res.data.credit;
  147. })
  148. }
  149. // 获取用户头像
  150. function getUserImg(data){
  151. switch (data) {
  152. case 0:
  153. myInfoData.userImg = 'static/images/my/head-img0.png'
  154. break;
  155. case 10:
  156. myInfoData.userImg = 'static/images/my/head-img1.png'
  157. break;
  158. case 20:
  159. myInfoData.userImg = 'static/images/my/head-img2.png'
  160. break;
  161. case 50:
  162. myInfoData.userImg = 'static/images/my/head-img30.png'
  163. break;
  164. default:
  165. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  166. break;
  167. }
  168. }
  169. // 会员权益按钮
  170. function hyqyBtn(index){
  171. /* index为学科 1数学 2英语 */
  172. if(loginFlag.value){
  173. // 非游客
  174. uni.redirectTo({
  175. url: '/pages/pay/svip'
  176. })
  177. }else{
  178. // 游客
  179. youkeDialogRef.value.handleShow();
  180. }
  181. }
  182. // 判断是否是游客
  183. function myGetAuth(){
  184. let LocalStorage = cacheManager.get('auth');
  185. if (LocalStorage) {
  186. // 非游客
  187. noYoukeFun()
  188. }else{
  189. youkeFun();
  190. }
  191. }
  192. // 游客
  193. function youkeFun(){
  194. zhangId.value = routerOpt.zhangId
  195. nianji.value = routerOpt.nianji
  196. cardId.value = routerOpt.cardId
  197. // my游客
  198. loginFlag.value = false;
  199. myInfoData.userName = '游客';
  200. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  201. }
  202. // 非游客
  203. function noYoukeFun(){
  204. loginFlag.value = true;
  205. getMyInfo();
  206. }
  207. // 获取会员权益card class
  208. function getHyqyClass(index){
  209. let VipIndex =index +1;
  210. if(cacheManager.get('auth')){
  211. // 非游客
  212. let VipArr = cacheManager.get('auth').cardList;
  213. if (VipArr.includes(VipIndex)) {
  214. return 'hyqy-box' + VipIndex;
  215. } else {
  216. return 'hyqy-disabled-box' + VipIndex;
  217. }
  218. }else{
  219. // 游客
  220. return 'hyqy-disabled-box' + VipIndex;
  221. }
  222. }
  223. //获取会员权益按钮是否显示
  224. function getHyqyBtn(index){
  225. let VipIndex =index +1;
  226. if(cacheManager.get('auth')){
  227. let VipArr = cacheManager.get('auth').cardList;
  228. if (VipArr.includes(VipIndex)) {
  229. return false;
  230. } else {
  231. return true;
  232. }
  233. }else{
  234. // 游客
  235. return 'hyqy-disabled-box' + VipIndex;
  236. }
  237. }
  238. onLoad((options) => {
  239. if(!cacheManager.get('auth')){
  240. // 游客
  241. routerOpt = options;
  242. youkeFun();
  243. }else{
  244. // 非游客
  245. noYoukeFun();
  246. }
  247. })
  248. function checkWrong() {
  249. if(loginFlag.value){
  250. const AuthCode = getUserIdentity();
  251. if (AuthCode == 'Visitor') {
  252. youkeDialogRef.value.handleShow();
  253. return;
  254. }
  255. uni.redirectTo({
  256. url: '/pages/wrong/index'
  257. })
  258. }else{
  259. youkeDialogRef.value.handleShow();
  260. }
  261. }
  262. </script>