index.vue 12 KB

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