index.vue 11 KB

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