login.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div>
  3. 全局登录页面 账号 <input type="text" /> 密码
  4. <input type="text" /> 验证码 <input type="text" v-model="loginForm.code" /><img :src="image" alt="" />
  5. <button @click="login">登录</button>
  6. </div>
  7. </template>
  8. <script>
  9. import axios from 'axios';
  10. import md5 from 'js-md5';
  11. import { getAll,setToken } from '@/libs/micros'
  12. import { Alert } from 'element-ui';
  13. export default {
  14. data() {
  15. return {
  16. loginForm: {
  17. //租户ID
  18. tenantId: '000000',
  19. //部门ID
  20. deptId: '',
  21. //角色ID
  22. roleId: '',
  23. //用户名
  24. username: 'admin',
  25. //密码
  26. password: 'admin',
  27. //账号类型
  28. type: 'account',
  29. //验证码的值
  30. code: '',
  31. //验证码的索引
  32. key: '',
  33. grant_type: 'captcha',
  34. scope: 'all'
  35. //预加载白色背景
  36. },
  37. image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
  38. }
  39. },
  40. methods: {
  41. login() {
  42. const v = this
  43. console.log(md5(v.loginForm.password))
  44. v.loginForm.password = md5(v.loginForm.password)
  45. axios({
  46. method:"post",
  47. url:'/api/blade-auth/oauth/token',
  48. params:this.loginForm,
  49. headers:{
  50. 'Captcha-Key':this.loginForm.key,
  51. 'Captcha-Code':this.loginForm.code,
  52. 'Tenant-Id': this.loginForm.tenantId
  53. },
  54. }).then(res=>{
  55. console.log(res)
  56. if(res.status == 200 && res.data){
  57. setToken(res.data)
  58. alert('登录成功')
  59. setTimeout(()=>{
  60. v.$router.push("/main")
  61. },1000)
  62. }
  63. // window.localStorage.setItem("token",JSON.stringify(res.data))
  64. // v.$router.push("/emailHome")
  65. })
  66. },
  67. getCodeImg() {
  68. this.$get('/api/blade-auth/oauth/captcha').then((res) => {
  69. const data = res
  70. this.loginForm.key = data.key
  71. this.image = data.image
  72. })
  73. },
  74. },
  75. created() {
  76. this.getCodeImg()
  77. },
  78. }
  79. </script>