login.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import axios from 'axios';
  2. //登录
  3. export function login({username, password,loginFrom}) {
  4. return axios({
  5. method: 'post',
  6. url: '/login',
  7. data: {
  8. username,
  9. password,
  10. loginFrom
  11. },
  12. transformRequest: [function(data) {
  13. let ret = ''
  14. for (let it in data) {
  15. ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
  16. }
  17. return ret;
  18. }],
  19. headers: {
  20. // 'Content-Type': 'application/x-www-form-urlencoded'
  21. }
  22. }).then(res => res.data)
  23. }
  24. //获取当前身份
  25. export function getLoginUser(){
  26. return axios.get('/user/cur').then(result => result.data)
  27. }
  28. //验证身份唯一
  29. export function checkOnly(name){
  30. return axios.get('/open/user/checkUsername?username=' + name).then(result => result.data)
  31. }
  32. //注册
  33. export function register(reg) {
  34. return axios({
  35. method: 'post',
  36. url: '/open/user/register',
  37. data: reg
  38. }).then(res => res.data)
  39. }
  40. //登出
  41. export function logout() {
  42. return axios.get('/logout').then(res => res.data);
  43. }