index.vue 11 KB

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