login.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="login" />
  3. </template>
  4. <script>
  5. export default {
  6. data() {
  7. return {
  8. path: '/pages/index/index',
  9. query: {}
  10. }
  11. },
  12. computed: {},
  13. methods: {
  14. login() {
  15. this.$loading('登陆中...')
  16. this.$api.user.login().then(async res => {
  17. this.$hideLoading()
  18. const { token, user_info } = res.data
  19. await this.$store.dispatch('user/token', token)
  20. await this.$store.dispatch('user/info', user_info)
  21. uni.reLaunch({
  22. url: this.path,
  23. success() {
  24. console.log('-->success')
  25. },
  26. fail(err) {
  27. uni.reLaunch({
  28. url: '/pages/index/index'
  29. })
  30. console.log('-->error', err)
  31. }
  32. })
  33. })
  34. }
  35. },
  36. onLoad(options) {
  37. console.log('-->data', options)
  38. this.path = options.path ? options.path : this.path
  39. this.path = this.path.replace('//', '/')
  40. this.path = this.path.indexOf('/') !== 0 ? '/' + this.path : this.path
  41. const query = options.query ? JSON.parse(decodeURI(options.query)) : {}
  42. const queryArr = []
  43. for (const queryKey in query) {
  44. queryArr.push(`${queryKey}=${query[queryKey]}`)
  45. }
  46. this.path = this.path + '?' + queryArr.join('&')
  47. this.login()
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .login{
  53. }
  54. </style>