login.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div>
  3. <img src="http://pjczv6ygf.bkt.clouddn.com/login_background.png"
  4. style="max-width: 100%"
  5. />
  6. <h1>正在自动登录,请稍后</h1>
  7. </div>
  8. </template>
  9. <script>
  10. import 'whatwg-fetch';
  11. import { BasicFunction } from '../connector/basic-service';
  12. import {Toast} from 'vant';
  13. export default {
  14. created: function () {
  15. Toast.loading({
  16. mask: true,
  17. message: '加载中...',
  18. duration: 1500
  19. });
  20. if (localStorage.getItem('frontend-userid')) {
  21. Toast.success('登录成功');
  22. this.$router.push('index');
  23. return;
  24. }
  25. let otp = this.$route.query.o;
  26. // console.log('otp: ');
  27. // console.log(otp);
  28. if (otp === undefined) {
  29. otp = BasicFunction.utils_get_param("o");
  30. }
  31. // console.log('otp: ');
  32. // console.log(otp);
  33. let userid = '';
  34. if (otp === null) {
  35. // no-otp
  36. Toast.fail("链接失效!请回到公众号重新获取链接");
  37. return;
  38. }
  39. let that = this;
  40. BasicFunction.get_data("ajaxotplogin?otp=" + otp.toString(), function (response) {
  41. // console.log("------ User Info login --------");
  42. // console.log(response);
  43. if (response.ret === "10000") {
  44. let user = response.model;
  45. userid = user.userId;
  46. localStorage.setItem('frontend-userid', userid);
  47. Toast.success('登录成功');
  48. that.$router.push('index');
  49. } else {
  50. // 失败的处理
  51. // console.warn("获取用户信息失败");
  52. Toast.fail('链接失效!请回到公众号重新获取链接');
  53. that.$router.push('warning');
  54. }
  55. }, {});
  56. }
  57. }
  58. /** Post JSON **/
  59. /*
  60. // 怎么把一段放到另一个文件?
  61. fetch('/users', {
  62. method: 'POST',
  63. headers: {
  64. 'Content-Type': 'application/json'
  65. },
  66. body: JSON.stringify({
  67. name: 'Hubot',
  68. login: 'hubot',
  69. })
  70. })
  71. */
  72. </script>
  73. <style scoped>
  74. .card {
  75. margin: 20px 20px 130px;
  76. border: solid 1px #e4e4e4;
  77. }
  78. .login {
  79. margin-bottom: 10px;
  80. width: 85%;
  81. background-color: #fd6740;
  82. border-color: #fd6740;
  83. }
  84. .register {
  85. margin-bottom: 5px;
  86. width: 85%;
  87. }
  88. </style>