index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class=""><tui-skeleton v-if="true" :loadingType="3" :isLoading="true"></tui-skeleton></view>
  3. </template>
  4. <script>
  5. import { mapActions, mapMutations } from 'vuex'
  6. import shareEntry from './mixins/share-entry.js'
  7. // 页面初始化
  8. export default {
  9. mixins: [shareEntry],
  10. data() {
  11. return {
  12. scene: '',
  13. state_str: ''
  14. }
  15. },
  16. onLoad(options) {
  17. this.scene = options.scene
  18. this.state_str = options.state_str
  19. this.initUserInfo()
  20. },
  21. methods: {
  22. ...mapMutations('user', ['SET_USER_INFO']),
  23. ...mapActions('user', ['wxAutoLogin', 'getAccessToken']),
  24. ...mapActions('coupon', ['initCouponCount']),
  25. ...mapActions('cart', ['fetchCartKindCount']),
  26. // 初始化页面数据
  27. initPageData() {
  28. this.getAccessToken()
  29. this.initCouponCount()
  30. this.fetchCartKindCount()
  31. },
  32. // 初始化用户信息
  33. async initUserInfo() {
  34. try {
  35. const user = this.$getStorage('USER_INFO')
  36. if (user) {
  37. // 用户已登录
  38. this.SET_USER_INFO(user)
  39. } else {
  40. // 微信登录
  41. await this.wxAutoLogin()
  42. }
  43. } catch (e) {
  44. console.log('初始化用户信息时出现了错误')
  45. console.log(e)
  46. } finally {
  47. this.initPageData()
  48. this.redirectToEntry()
  49. }
  50. },
  51. // 跳转入口页面
  52. redirectToEntry() {
  53. if (this.scene) {
  54. // 处理分享信息
  55. this.shareHandle(this.scene, 'scene')
  56. } else if (this.state_str) {
  57. this.shareHandle(this.state_str, 'state_str')
  58. } else {
  59. // 默认调整首页
  60. this.$router.switchTab('home')
  61. }
  62. }
  63. }
  64. }
  65. </script>