login.vue 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. localStorage.setItem('user', JSON.stringify(user));
  24. this.$toast.clear();
  25. if (this.redirect_uri) this.$router.push(this.redirect_uri);
  26. else if (!this.is_dev) this.toIndex();
  27. },
  28. computed: {
  29. redirect_uri() {
  30. return this.$route.query.redirect_uri;
  31. },
  32. },
  33. methods: {
  34. toIndex() {
  35. this.$router.push({ path: '/' });
  36. },
  37. },
  38. };
  39. </script>
  40. <style lang="less" scoped></style>