index.vue 10 KB

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