index.vue 7.7 KB

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