index.vue 11 KB

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