user.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view>
  3. <!-- 简约风格 -->
  4. <kz-page-my-simple :user="user" @login="login" @goTo="goTo" @clearStorage="clearStorage" v-if="pageStyle == 'simple'"></kz-page-my-simple>
  5. <!-- 多彩风格 -->
  6. <kz-page-my-color :user="user" @login="login" @goTo="goTo" @clearStorage="clearStorage" v-else-if="pageStyle == 'color'"></kz-page-my-color>
  7. <!-- 流量主组件 -->
  8. <!-- #ifdef MP-WEIXIN -->
  9. <kz-ad ref="adMy" kind="BANNER" :config="ad" field="my_banner"></kz-ad>
  10. <kz-ad ref="adMy" kind="VIDEO" :config="ad" field="my_video"></kz-ad>
  11. <kz-ad ref="adMy" kind="VIDEO_PATCH" :config="ad" field="my_video_patch"></kz-ad>
  12. <!-- #endif -->
  13. <!-- 大嘴鸟组件 -->
  14. <monster v-if="showMonster"></monster>
  15. <login ref="login" v-on:succ="ajax"></login>
  16. <tabbar></tabbar>
  17. </view>
  18. </template>
  19. <script>
  20. import userApi from "@/common/api/user.js"
  21. import { nextTick } from "vue";
  22. export default {
  23. data() {
  24. return {
  25. imgUrl: this.url,
  26. user: null,
  27. ad: {},
  28. pageStyle: 'simple',
  29. showMonster: false,
  30. isLogin : false
  31. };
  32. },
  33. onLoad() {
  34. //判断用户是否登录 , 如果没有登录的话就去登录
  35. this.ad = this.utils.getData('ad')
  36. // 插屏广告
  37. if (this.ad.my_cp_open == 1) {
  38. this.adUtils.interstitial.load(this.ad.my_cp)
  39. this.adUtils.interstitial.show()
  40. }
  41. let page = this.utils.getData('page')
  42. if (page) {
  43. // 页面风格
  44. this.pageStyle = page.page_my_style ? page.page_my_style : 'simple'
  45. // this.pageStyle = 'simple'
  46. // 大嘴鸟
  47. this.showMonster = page.page_my_monster_btn == 1
  48. }
  49. },
  50. onShow() {
  51. uni.$on('login_success', (data) => {
  52. console.log('login_success', data)
  53. this.user = data.user
  54. this.ajax()
  55. })
  56. this.ajax()
  57. if(uni.getStorageSync('token')){
  58. this.isLogin = true
  59. }else{
  60. this.$nextTick(()=>{
  61. console.log(this.$refs.login)
  62. this.$refs.login.modal = true;
  63. })
  64. }
  65. },
  66. onHide() {
  67. uni.$off('login_success')
  68. },
  69. methods: {
  70. ajax() {
  71. if (uni.getStorageSync('token')) {
  72. userApi.getUserInfo(this).then(res => {
  73. if (res.code == 1) {
  74. this.user = res.data
  75. uni.setStorageSync('user', this.user)
  76. } else {
  77. uni.$emit('uniLogin')
  78. }
  79. })
  80. } else {
  81. uni.$emit('uniLogin')
  82. }
  83. // setTimeout(() => {
  84. // this.user = uni.getStorageSync('user')
  85. // console.log('user', this.user)
  86. // }, 500)
  87. },
  88. login() {
  89. console.log('on login')
  90. if (!uni.getStorageSync('token')) {
  91. this.$refs.login.modal = true;
  92. return;
  93. } else {
  94. uni.navigateTo({
  95. url: 'set'
  96. });
  97. }
  98. },
  99. goTo(page) {
  100. console.log('page', page)
  101. if (!uni.getStorageSync('token')) {
  102. this.$refs.login.modal = true;
  103. return;
  104. } else {
  105. uni.navigateTo({
  106. url: page
  107. // url: e.currentTarget.dataset.url
  108. });
  109. }
  110. },
  111. clearStorage() {
  112. console.log('on clearStorage')
  113. uni.showModal({
  114. title: '提醒',
  115. content: '是否确认要清理缓存吗?(将清理用户登录信息及练题记忆模式等数据)',
  116. confirmColor: '#4A90E2',
  117. success: (t) => {
  118. t.confirm ?
  119. (uni.showLoading({
  120. title: '正在清除缓存...',
  121. mask: !0
  122. }),
  123. uni.clearStorage({
  124. success: () => {
  125. this.user = null
  126. uni.setStorageSync('user', '');
  127. uni.setStorageSync('user_id', '');
  128. uni.setStorageSync('openid', '');
  129. },
  130. fail: (t) => {
  131. console.log('fail');
  132. },
  133. complete: function(t) {
  134. setTimeout(function() {
  135. uni.hideLoading();
  136. }, 1000);
  137. }
  138. })) :
  139. t.cancel && console.log('取消');
  140. }
  141. });
  142. },
  143. tel() {
  144. uni.makePhoneCall({
  145. phoneNumber: this.copyright_mobile
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style>
  152. page {
  153. /* background-color: #fff; */
  154. }
  155. </style>