index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. state_str: ''
  13. }
  14. },
  15. onLoad(options) {
  16. this.state_str = options.state_str
  17. this.init()
  18. },
  19. methods: {
  20. ...mapMutations('user', ['SET_USER_INFO']),
  21. ...mapActions('user', ['wxAutoLogin']),
  22. ...mapActions('coupon', ['initCouponCount']),
  23. ...mapActions('cart', ['fetchCartKindCount']),
  24. async init() {
  25. await this.initUserInfo()
  26. await this.initCouponCount()
  27. await this.fetchCartKindCount()
  28. },
  29. // 初始化用户信息
  30. async initUserInfo() {
  31. const user = this.$getStorage('USER_INFO')
  32. if (user) {
  33. // 用户已登录
  34. this.SET_USER_INFO(user)
  35. this.redirectToEntry()
  36. return Promise.resolve()
  37. }
  38. try {
  39. // 微信登录
  40. this.wxAutoLogin()
  41. this.redirectToEntry()
  42. return Promise.resolve()
  43. } catch (e) {
  44. console.log(e)
  45. }
  46. },
  47. // 跳转入口页面
  48. redirectToEntry() {
  49. if (this.state_str) {
  50. this.shareHandle(this.state_str)
  51. } else {
  52. this.$router.switchTab('home')
  53. }
  54. }
  55. }
  56. }
  57. </script>