index.vue 9.9 KB

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