login.vue 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <div id="login">
  3. <van-button type="primary" @click="toIndex" v-if="is_dev">去首页(开发用)</van-button>
  4. </div>
  5. </template>
  6. <script>
  7. const jwt = require('jsonwebtoken');
  8. export default {
  9. metaInfo: { title: '正在登陆...' },
  10. name: 'login',
  11. props: {},
  12. components: {},
  13. data: () => ({
  14. is_dev: process.env.NODE_ENV === 'development',
  15. }),
  16. created() {
  17. this.$toast.loading({
  18. message: '登陆中...',
  19. duration: 0,
  20. });
  21. let token = this.$route.query.token;
  22. let user = jwt.decode(token);
  23. console.log(user);
  24. localStorage.setItem('user', JSON.stringify(user));
  25. this.$toast.clear();
  26. if (this.redirect_uri) this.$router.push('this.redirect_uri');
  27. else if (!this.is_dev) this.toIndex();
  28. },
  29. computed: {
  30. redirect_uri() {
  31. return this.$route.query.redirect_uri;
  32. },
  33. },
  34. methods: {
  35. toIndex() {
  36. this.$router.push({ path: '/' });
  37. },
  38. },
  39. };
  40. </script>
  41. <style lang="less" scoped></style>