App.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 !== 'undefined' && query.scene) {
  18. Cache.set('parent_id', query.scene)
  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. } else {
  25. uni.reLaunch({
  26. url: '/pages/login?path=' + path + '&query=' + encodeURI(JSON.stringify(query))
  27. })
  28. }
  29. },
  30. onShow() {
  31. console.log('App Show')
  32. },
  33. onHide() {
  34. console.log('App Hide')
  35. }
  36. }
  37. </script>
  38. <style lang="scss">
  39. /*每个页面公共css */
  40. @import "@/uni_modules/uview-ui/index.scss";
  41. @import '@/static/css/flex.scss';
  42. @import '@/static/css/common.scss';
  43. @import '@/static/css/iconfont.css';
  44. </style>