tokenlogin.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="login">
  3. <div>
  4. <div class="avatar-box">
  5. <van-loading text-color="#0094ff" v-if="loading">正在跳转</van-loading>
  6. <span style="color: red" v-if="type == 'error'">{{ message }}</span>
  7. <span style="color: #E6A23C" v-if="type == 'warn'">{{ message }}</span>
  8. </div>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. // 请求接口
  14. import { tokenLogin } from '@/api/public.js'
  15. import { mapGetters } from 'vuex'
  16. export default {
  17. data() {
  18. return {
  19. loading: false,
  20. type: '',
  21. message: ''
  22. }
  23. },
  24. computed: {
  25. ...mapGetters(['userName'])
  26. },
  27. inject:["initWebSocket"],
  28. mounted() {
  29. this.loading = true
  30. let { query } = this.$route;
  31. if (!query) {
  32. this.loading = false
  33. this.type = 'error'
  34. this.message = '缺少sso_token'
  35. } else {
  36. let { sso_token } = query
  37. if (!sso_token) {
  38. this.type = 'warn'
  39. this.loading = false
  40. this.message = '缺少sso_token'
  41. } else {
  42. tokenLogin(sso_token)
  43. .then(res => {
  44. console.log(res, 'res')
  45. sessionStorage.setItem('access_token',res.data.access_token);
  46. this.$router.replace('/home');
  47. //初始化websocket
  48. // this.initWebSocket();
  49. })
  50. .catch(e => {
  51. this.type = 'error'
  52. this.message = '请求错误'
  53. this.loading = false
  54. })
  55. }
  56. }
  57. },
  58. methods: {}
  59. }
  60. </script>
  61. <style lang="scss">
  62. //.van-cell__title{
  63. // align-items: center;
  64. //}
  65. //.custom-title{
  66. // align-self: center;
  67. //}
  68. </style>
  69. <style scoped lang="scss">
  70. .login {
  71. height: 100vh;
  72. background: url('../assets/img/login-background.png') top left no-repeat #edfcff;
  73. background-size: 100%;
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. > div {
  78. width: 450px;
  79. padding: 30px 0;
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. background-color: #fff;
  84. border-radius: 10px;
  85. .avatar-box {
  86. display: flex;
  87. justify-content: center;
  88. align-items: center;
  89. height: 150px;
  90. }
  91. }
  92. h2 {
  93. letter-spacing: 10px;
  94. text-align: center;
  95. }
  96. .custom-title {
  97. align-self: center;
  98. vertical-align: middle;
  99. }
  100. }
  101. </style>