index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.init()
  20. },
  21. methods: {
  22. ...mapMutations('user', ['SET_USER_INFO']),
  23. ...mapActions('user', ['wxAutoLogin', 'getAccessToken']),
  24. ...mapActions('coupon', ['initCouponCount']),
  25. ...mapActions('cart', ['fetchCartKindCount']),
  26. async init() {
  27. await this.getAccessToken()
  28. await this.initUserInfo()
  29. await this.initCouponCount()
  30. await this.fetchCartKindCount()
  31. },
  32. // 初始化用户信息
  33. async initUserInfo() {
  34. this.$setStorage('ENTRY_MARK_TYPE', 'YES')
  35. const user = this.$getStorage('USER_INFO')
  36. if (user) {
  37. // 用户已登录
  38. this.SET_USER_INFO(user)
  39. this.redirectToEntry()
  40. return Promise.resolve()
  41. }
  42. try {
  43. // 微信登录
  44. this.wxAutoLogin()
  45. this.redirectToEntry()
  46. return Promise.resolve()
  47. } catch (e) {
  48. console.log(e)
  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>