login.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import request from '@/utils/request'
  2. import Qs from 'qs'
  3. import md5 from 'js-md5';
  4. // 登录方法
  5. export function login(username, password, code, uuid) {
  6. return request({
  7. url: '/login',
  8. method: 'post',
  9. headers:{
  10. 'Authorization':'Basic bGluZ3dlaTpscWtqMDA3',
  11. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  12. },
  13. transformRequest: [function(data) { //在请求之前对data传参进行格式转换
  14. data = Qs.stringify(data)
  15. return data
  16. }],
  17. params:{},
  18. data:{
  19. username: username,
  20. password: md5(username + password),
  21. code: code,
  22. uuid: uuid,
  23. grant_type: "password"
  24. }
  25. })
  26. }
  27. //刷新token方法
  28. export function refreshAccessToken(refreshToken){
  29. return request({
  30. url: '/oauth/token',
  31. method: 'get',
  32. headers:{
  33. isToken: false,
  34. 'Authorization':'Basic bGluZ3dlaTpscWtqMDA3',
  35. 'Content-Type': 'application/x-www-form-urlencoded'
  36. },
  37. params:{
  38. refresh_token: refreshToken,
  39. grant_type: "refresh_token"
  40. }
  41. })
  42. }
  43. // 注册方法
  44. export function register(data) {
  45. return request({
  46. url: '/register',
  47. headers: {
  48. isToken: false
  49. },
  50. method: 'post',
  51. data: data
  52. })
  53. }
  54. // 获取用户详细信息
  55. export function getInfo() {
  56. return request({
  57. url: '/v1/getInfo',
  58. method: 'get'
  59. })
  60. }
  61. // 退出方法
  62. export function logout() {
  63. return request({
  64. url: '/logout',
  65. method: 'post'
  66. })
  67. }
  68. // 获取验证码
  69. export function getCodeImg() {
  70. return request({
  71. url: '/v1/captchaImage',
  72. method: 'get',
  73. timeout: 20000
  74. })
  75. }