user.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. onShow() {
  36. uni.$on('login_success', (data) => {
  37. console.log('login_success', data)
  38. this.user = data.user
  39. this.ajax()
  40. })
  41. this.ajax()
  42. if(uni.getStorageSync('token')){
  43. this.isLogin = true
  44. }else{
  45. this.$nextTick(()=>{
  46. console.log(this.$refs.login)
  47. this.$refs.login.modal = true;
  48. })
  49. }
  50. },
  51. onHide() {
  52. uni.$off('login_success')
  53. },
  54. methods: {
  55. ajax() {
  56. // 获取配置
  57. this.getSetting()
  58. if (uni.getStorageSync('token')) {
  59. userApi.getUserInfo(this).then(res => {
  60. if (res.code == 1) {
  61. this.user = res.data
  62. uni.setStorageSync('user', this.user)
  63. } else {
  64. uni.$emit('uniLogin')
  65. }
  66. })
  67. } else {
  68. uni.$emit('uniLogin')
  69. }
  70. // setTimeout(() => {
  71. // this.user = uni.getStorageSync('user')
  72. // console.log('user', this.user)
  73. // }, 500)
  74. },
  75. loadSetting() {
  76. let page = this.utils.getData('page')
  77. if (page) {
  78. // 页面风格
  79. this.pageStyle = page.page_my_style ? page.page_my_style : 'color2'
  80. // 大嘴鸟
  81. this.showMonster = page.page_my_monster_btn == 1
  82. }
  83. // #ifdef MP-WEIXIN
  84. this.ad = this.utils.getData('ad')
  85. // 插屏广告
  86. if (this.ad.my_cp_open == 1) {
  87. this.adUtils.interstitial.load(this.ad.my_cp)
  88. this.adUtils.interstitial.show()
  89. }
  90. // #endif
  91. },
  92. getSetting() {
  93. this.http('common/index', '', 'get').then(res => {
  94. if (!res.code) {
  95. uni.showToast({
  96. title: '获取数据失败,请刷新重试',
  97. icon: 'error'
  98. })
  99. return
  100. }
  101. // 系统配置数据
  102. let system = res.data.system
  103. if (system) {
  104. this.system = system
  105. uni.setStorageSync('system', system)
  106. }
  107. // 页面配置数据
  108. let page = res.data.page
  109. if (page) {
  110. this.page = page
  111. uni.setStorageSync('page', page)
  112. }
  113. // #ifdef MP-WEIXIN
  114. // 流量主数据
  115. let ad = res.data.ad;
  116. if (ad) {
  117. this.ad = ad
  118. uni.setStorageSync('ad', ad);
  119. // 插屏广告
  120. if (this.ad.index_cp_open == 1) {
  121. this.adUtils.interstitial.load(this.ad.index_cp)
  122. this.adUtils.interstitial.show()
  123. }
  124. }
  125. // #endif
  126. this.loadSetting()
  127. })
  128. },
  129. login() {
  130. console.log('on login')
  131. if (!uni.getStorageSync('token')) {
  132. this.$refs.login.modal = true;
  133. return;
  134. } else {
  135. uni.navigateTo({
  136. url: 'set'
  137. });
  138. }
  139. },
  140. goTo(page) {
  141. console.log('page', page)
  142. if (!uni.getStorageSync('token')) {
  143. this.$refs.login.modal = true;
  144. return;
  145. } else {
  146. uni.navigateTo({
  147. url: page
  148. // url: e.currentTarget.dataset.url
  149. });
  150. }
  151. },
  152. clearStorage() {
  153. console.log('on clearStorage')
  154. uni.showModal({
  155. title: '提醒',
  156. content: '是否确认要清理缓存吗?(将清理用户登录信息及练题记忆模式等数据)',
  157. confirmColor: '#4A90E2',
  158. success: (t) => {
  159. t.confirm ?
  160. (uni.showLoading({
  161. title: '正在清除缓存...',
  162. mask: !0
  163. }),
  164. uni.clearStorage({
  165. success: () => {
  166. this.user = null
  167. uni.setStorageSync('user', '');
  168. uni.setStorageSync('user_id', '');
  169. uni.setStorageSync('openid', '');
  170. },
  171. fail: (t) => {
  172. console.log('fail');
  173. },
  174. complete: function(t) {
  175. setTimeout(function() {
  176. uni.hideLoading();
  177. }, 1000);
  178. }
  179. }),
  180. this.getSetting()
  181. ) :
  182. t.cancel && console.log('取消');
  183. }
  184. });
  185. },
  186. tel() {
  187. uni.makePhoneCall({
  188. phoneNumber: this.copyright_mobile
  189. });
  190. }
  191. }
  192. };
  193. </script>
  194. <style>
  195. page {
  196. /* background-color: #fff; */
  197. }
  198. </style>