index.vue 9.0 KB

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