App.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <script>
  2. import Cache from './utils/cache'
  3. export default {
  4. globalData: {
  5. isLogin: false
  6. },
  7. async onLaunch(options) {
  8. console.log('-->data', options)
  9. console.log('App Launch')
  10. const path = options.path ? '/' + options.path : '/pages/index/index'
  11. const query = options.query
  12. // 直接传递user_id
  13. if (typeof query.user_id !== 'undefined' && query.user_id) {
  14. Cache.set('parent_id', query.user_id)
  15. }
  16. // 微信小程序 对应的二维码是 scene_code
  17. if (typeof query.scene_code !== 'undefined' && query.scene_code) {
  18. Cache.set('parent_id', query.scene_code)
  19. }
  20. if (this.$api.user.isLogin()) {
  21. await this.$api.user.info().then(res => {
  22. this.$store.dispatch('user/info', res.data)
  23. // 绑定上级
  24. const parentId = Cache.get('parent_id')
  25. if (parentId && !res.data.info.parent_id) {
  26. this.$api.user.bind(parentId).then(res => {
  27. console.log('-->bind parent success')
  28. this.$store.dispatch('user/info', res.data)
  29. Cache.remove('parent_id')
  30. })
  31. }
  32. })
  33. } else {
  34. uni.reLaunch({
  35. url: '/pages/login?path=' + path + '&query=' + encodeURI(JSON.stringify(query))
  36. })
  37. }
  38. },
  39. onShow() {
  40. console.log('App Show')
  41. },
  42. onHide() {
  43. console.log('App Hide')
  44. }
  45. }
  46. </script>
  47. <style lang="scss">
  48. /*每个页面公共css */
  49. @import "@/uni_modules/uview-ui/index.scss";
  50. @import '@/static/css/flex.scss';
  51. @import '@/static/css/common.scss';
  52. @import '@/static/css/iconfont.css';
  53. </style>