index.vue 10 KB

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