index.vue 7.5 KB

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