index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 v-if="loginFlag" class="list-row no-jt" @click="yonghuzhuxiao">
  38. <icon class="list-icon zhuxiao-icon"></icon>
  39. <text>用户注销</text>
  40. </view>
  41. <view v-if="loginFlag" class="list-row no-jt" @click="yinsizhengce">
  42. <icon class="list-icon yszc-icon"></icon>
  43. <text>隐私政策</text>
  44. </view>
  45. <view class="list-row no-jt" @click="exitLogin">
  46. <icon class="list-icon login-out-icon"></icon>
  47. <text>退出登录</text>
  48. </view>
  49. </view>
  50. <CustomTabBar :cardId="cardId" :currentTabNumber="2" :nianji="nianji" :zhangId="zhangId" :tipFlag="tipFlag"></CustomTabBar>
  51. <tip-small-dialog ref="exitDialogRef" @confirm-btn="exitBtn" :content="tipContent"></tip-small-dialog>
  52. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" imgShow="false"></tip-big-dialog>
  53. <tip-small-dialog ref="zhuxiaoDialogRef" @confirm-btn="zhuxiaoBtn" :content="zhuxiaoContent"></tip-small-dialog>
  54. <tel-dialog @telClose="telClose" @bindBtn="bindBtn" v-if="telDialogFlag"></tel-dialog>
  55. <agree-content-dialog ref="agreeContentDialogRef" :agreeType="agreeType"></agree-content-dialog>
  56. </view>
  57. </template>
  58. <script setup>
  59. import agreeContentDialog from '@/pages/login/agreeContentDialog.vue';
  60. import {toast,getUserIdentity} from "@/utils/common";
  61. import cacheManager from '@/utils/cacheManager.js';
  62. import {logout} from '@/api/login.js'
  63. import {myInfo,zhuxiao} from '@/api/my.js'
  64. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  65. import {getCurrentInstance} from 'vue';
  66. import {onLoad} from '@dcloudio/uni-app';
  67. import {reactive,ref} from "vue";
  68. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue';
  69. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  70. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  71. import telDialog from './telDialog.vue'
  72. import {MESSAGE_VISITER_TO_LOGIN} from "@/utils/constant.js"
  73. import {
  74. onShow
  75. } from '@dcloudio/uni-app';
  76. onShow(() => {
  77. if(!cacheManager.get('auth')){
  78. youkeFun();
  79. }else{
  80. // 非游客
  81. noYoukeFun();
  82. }
  83. })
  84. const agreeType = ref(null);
  85. const agreeContentDialogRef = ref(null);
  86. const zhangId = ref(null); //游客使用
  87. const nianji = ref(null); //游客使用
  88. const cardId = ref(null); //游客使用
  89. const tipFlag = ref(null); //游客使用
  90. const tipContent = '你确定要执行这个操作吗?';
  91. const zhuxiaoContent = '你确定要执行这个操作吗?';
  92. let hyqyData = reactive({
  93. indicatorDots: true,
  94. autoplay: true,
  95. interval: 10000,
  96. duration: 500
  97. });
  98. let loginFlag = ref(false);
  99. let telDialogFlag = ref(false);
  100. let myInfoData = reactive({
  101. userImg: '',
  102. userName: '',
  103. credit: '',
  104. vipFlag: '',
  105. });
  106. let routerOpt = ref(false);
  107. const exitDialogRef = ref(null);
  108. const youkeDialogRef = ref(null);
  109. const zhuxiaoDialogRef = ref(null);
  110. const exitLogin = () => {
  111. exitDialogRef.value.handleShow();
  112. }
  113. // 退出按钮
  114. const exitBtn = () => {
  115. if(loginFlag.value){
  116. logout().then(res => {
  117. toast('退出登录成功')
  118. cacheManager.clearAll();
  119. uni.reLaunch({
  120. url: '/pages/login/index'
  121. });
  122. }).catch(err => {
  123. toast('退出登录失败,请稍后重试')
  124. })
  125. }else{
  126. uni.reLaunch({
  127. url: '/pages/login/index'
  128. });
  129. }
  130. }
  131. const zhuxiaoBtn = () => {
  132. let req = {
  133. }
  134. zhuxiao().then(res=>{
  135. cacheManager.clearAll();
  136. toast('用户注销成功')
  137. uni.redirectTo({
  138. url: '/pages/login/index'
  139. });
  140. }).catch(err=>{
  141. toast('失败,请稍后重试')
  142. })
  143. }
  144. function yonghuzhuxiao(){
  145. zhuxiaoDialogRef.value.handleShow();
  146. }
  147. function yinsizhengce(){
  148. agreeType.value = 'ystk'
  149. agreeContentDialogRef.value.handleShow();
  150. }
  151. // 游客弹窗---确定
  152. function ykConfirm(){
  153. uni.redirectTo({
  154. url: '/pages/login/index'
  155. });
  156. }
  157. // 手机号码
  158. function telClick(){
  159. if(loginFlag.value){
  160. telDialogFlag.value = true;
  161. }else{
  162. youkeDialogRef.value.handleShow();
  163. }
  164. }
  165. // 手机号码绑定
  166. function bindBtn(){
  167. telDialogFlag.value = false;
  168. myGetAuth()
  169. }
  170. // 关闭手机号码弹窗
  171. function telClose(){
  172. telDialogFlag.value = false;
  173. }
  174. // 关于我们
  175. function aboutClick(){
  176. if(loginFlag.value){
  177. uni.redirectTo({
  178. url: '/pages/my/aboutPage'
  179. });
  180. }else{
  181. uni.redirectTo({
  182. url: `/pages/my/aboutPage?nianji=${routerOpt.nianji}&cardId=${routerOpt.cardId}&zhangId=${routerOpt.zhangId}&tipFlag=${routerOpt.tipFlag}`
  183. });
  184. }
  185. }
  186. // 订单
  187. function orderClick(){
  188. if(loginFlag.value){
  189. uni.redirectTo({
  190. url: '/pages/pay/order'
  191. });
  192. }else{
  193. youkeDialogRef.value.handleShow();
  194. }
  195. }
  196. // 获取用户数据
  197. function getMyInfo(){
  198. myInfo({}).then(res => {
  199. getUserImg(res.data.growthType)
  200. myInfoData.userName = res.data.userName;
  201. myInfoData.credit = res.data.credit;
  202. })
  203. }
  204. // 获取用户头像
  205. function getUserImg(data){
  206. switch (data) {
  207. case 0:
  208. myInfoData.userImg = 'static/images/my/head-img0.png'
  209. break;
  210. case 1:
  211. myInfoData.userImg = 'static/images/my/head-img1.png'
  212. break;
  213. case 2:
  214. myInfoData.userImg = 'static/images/my/head-img2.png'
  215. break;
  216. case 3:
  217. myInfoData.userImg = 'static/images/my/head-img3.png'
  218. break;
  219. default:
  220. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  221. break;
  222. }
  223. }
  224. // 会员权益按钮
  225. function hyqyBtn(index){
  226. let cardId = index+1;
  227. /* index为学科 1数学 2英语 */
  228. if(loginFlag.value){
  229. // 非游客
  230. uni.redirectTo({
  231. url: `/pages/pay/svip?cardId=${cardId}&formPage=my`
  232. })
  233. }else{
  234. // 游客
  235. youkeDialogRef.value.handleShow();
  236. }
  237. }
  238. // 判断是否是游客
  239. function myGetAuth(){
  240. let LocalStorage = cacheManager.get('auth');
  241. if (LocalStorage) {
  242. // 非游客
  243. noYoukeFun()
  244. }else{
  245. youkeFun();
  246. }
  247. }
  248. // 游客
  249. function youkeFun(){
  250. zhangId.value = routerOpt.zhangId
  251. nianji.value = routerOpt.nianji
  252. cardId.value = routerOpt.cardId
  253. tipFlag.value = routerOpt.tipFlag
  254. // my游客
  255. loginFlag.value = false;
  256. myInfoData.userName = '游客';
  257. myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
  258. }
  259. // 非游客
  260. function noYoukeFun(){
  261. loginFlag.value = true;
  262. getMyInfo();
  263. }
  264. // 获取会员权益card class
  265. function getHyqyClass(index){
  266. let VipIndex =index +1;
  267. if(cacheManager.get('auth')){
  268. // 非游客
  269. let VipArr = cacheManager.get('auth').cardList;
  270. if (VipArr.includes(VipIndex)) {
  271. return 'hyqy-box' + VipIndex;
  272. } else {
  273. return 'hyqy-disabled-box' + VipIndex;
  274. }
  275. }else{
  276. // 游客
  277. return 'hyqy-disabled-box' + VipIndex;
  278. }
  279. }
  280. //获取会员权益按钮是否显示
  281. function getHyqyBtn(index){
  282. let VipIndex =index +1;
  283. if(cacheManager.get('auth')){
  284. let VipArr = cacheManager.get('auth').cardList;
  285. if (VipArr.includes(VipIndex)) {
  286. return false;
  287. } else {
  288. return true;
  289. }
  290. }else{
  291. // 游客
  292. return 'hyqy-disabled-box' + VipIndex;
  293. }
  294. }
  295. onLoad((options) => {
  296. if(!cacheManager.get('auth')){
  297. // 游客
  298. routerOpt = options;
  299. }else{
  300. }
  301. })
  302. function checkWrong() {
  303. if(loginFlag.value){
  304. const AuthCode = getUserIdentity();
  305. if (AuthCode == 'Visitor') {
  306. youkeDialogRef.value.handleShow();
  307. return;
  308. }
  309. uni.redirectTo({
  310. url: '/pages/wrong/index'
  311. })
  312. }else{
  313. youkeDialogRef.value.handleShow();
  314. }
  315. }
  316. </script>