index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="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: 2000,
  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. myGetAuth()
  119. }
  120. // 关闭手机号码弹窗
  121. function telClose(){
  122. telDialogFlag.value = false;
  123. }
  124. // 关于我们
  125. function aboutClick(){
  126. uni.redirectTo({
  127. url: '/pages/my/aboutPage'
  128. });
  129. }
  130. // 订单
  131. function orderClick(){
  132. if(loginFlag.value){
  133. uni.redirectTo({
  134. url: '/pages/pay/order'
  135. });
  136. }else{
  137. youkeDialogRef.value.handleShow();
  138. }
  139. }
  140. // 获取用户数据
  141. function getMyInfo(){
  142. myInfo({}).then(res => {
  143. getUserImg(res.data.growth)
  144. myInfoData.userName = res.data.userName;
  145. myInfoData.credit = res.data.credit;
  146. })
  147. }
  148. // 获取用户头像
  149. function getUserImg(data){
  150. switch (data) {
  151. case 0:
  152. myInfoData.userImg = 'static/images/my/head-img0.png'
  153. break;
  154. case 10:
  155. myInfoData.userImg = 'static/images/my/head-img1.png'
  156. break;
  157. case 20:
  158. myInfoData.userImg = 'static/images/my/head-img2.png'
  159. break;
  160. case 50:
  161. myInfoData.userImg = 'static/images/my/head-img30.png'
  162. break;
  163. default:
  164. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  165. break;
  166. }
  167. }
  168. // 会员权益按钮
  169. function hyqyBtn(index){
  170. toast("功能暂未开放!")
  171. return false
  172. /* index为学科 1数学 2英语 */
  173. if(loginFlag.value){
  174. // 非游客
  175. uni.redirectTo({
  176. url: '/pages/pay/svip'
  177. })
  178. }else{
  179. // 游客
  180. youkeDialogRef.value.handleShow();
  181. }
  182. }
  183. // 判断是否是游客
  184. function myGetAuth(){
  185. let LocalStorage = cacheManager.get('auth');
  186. if (LocalStorage) {
  187. // 非游客
  188. noYoukeFun()
  189. }else{
  190. youkeFun();
  191. }
  192. }
  193. // 游客
  194. function youkeFun(){
  195. zhangId.value = routerOpt.zhangId
  196. nianji.value = routerOpt.nianji
  197. cardId.value = routerOpt.cardId
  198. // my游客
  199. loginFlag.value = false;
  200. myInfoData.userName = '游客';
  201. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  202. }
  203. // 非游客
  204. function noYoukeFun(){
  205. loginFlag.value = true;
  206. getMyInfo();
  207. }
  208. // 获取会员权益card class
  209. function getHyqyClass(index){
  210. let VipIndex =index +1;
  211. if(cacheManager.get('auth')){
  212. // 非游客
  213. let VipArr = cacheManager.get('auth').cardList;
  214. if (VipArr.includes(VipIndex)) {
  215. return 'hyqy-box' + VipIndex;
  216. } else {
  217. return 'hyqy-disabled-box' + VipIndex;
  218. }
  219. }else{
  220. // 游客
  221. return 'hyqy-disabled-box' + VipIndex;
  222. }
  223. }
  224. //获取会员权益按钮是否显示
  225. function getHyqyBtn(index){
  226. let VipIndex =index +1;
  227. if(cacheManager.get('auth')){
  228. let VipArr = cacheManager.get('auth').cardList;
  229. if (VipArr.includes(VipIndex)) {
  230. return false;
  231. } else {
  232. return true;
  233. }
  234. }else{
  235. // 游客
  236. return 'hyqy-disabled-box' + VipIndex;
  237. }
  238. }
  239. onLoad((options) => {
  240. if(!cacheManager.get('auth')){
  241. // 游客
  242. routerOpt = options;
  243. youkeFun();
  244. }else{
  245. // 非游客
  246. noYoukeFun();
  247. }
  248. })
  249. function checkWrong() {
  250. if(loginFlag.value){
  251. const AuthCode = getUserIdentity();
  252. if (AuthCode == 'Visitor') {
  253. youkeDialogRef.value.handleShow();
  254. return;
  255. }
  256. uni.redirectTo({
  257. url: '/pages/wrong/index'
  258. })
  259. }else{
  260. youkeDialogRef.value.handleShow();
  261. }
  262. }
  263. </script>