login.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {
  2. request, upload
  3. } from '@/utils/request.js';
  4. import {
  5. getRefreshToken
  6. } from '@/utils/auth';
  7. // 登录方法
  8. export function appLogin(data) {
  9. return request({
  10. url: '/system/auth/login',
  11. headers: {
  12. isToken: false
  13. },
  14. method: 'POST',
  15. data
  16. });
  17. }
  18. /**
  19. * 钉钉授权登录
  20. * @param data
  21. */
  22. export function dingTalkLogin(data) {
  23. return request({
  24. url: '/system/auth/appSocialLogin',
  25. headers: { isToken: false },
  26. method: 'POST',
  27. data
  28. })
  29. }
  30. /**
  31. * 钉钉授权登录 - H5
  32. * @param data
  33. */
  34. export function dingTalkLoginH5(data) {
  35. return request({
  36. url: '/system/auth/h5SocialLogin',
  37. headers: { isToken: false },
  38. method: 'POST',
  39. data
  40. })
  41. }
  42. /**
  43. * 获取用户信息
  44. */
  45. export const getLoginUserInfo = () =>
  46. request({
  47. url: '/system/user/profile/get',
  48. method: 'GET',
  49. })
  50. // 获取用户详细信息
  51. export function getInfo() {
  52. return request({
  53. url: '/system/auth/get-permission-info',
  54. method: 'GET'
  55. })
  56. }
  57. // 退出方法
  58. export function logout() {
  59. return request({
  60. url: '/system/auth/logout',
  61. method: 'POST'
  62. })
  63. }
  64. // 刷新访问令牌
  65. export function refreshToken() {
  66. return request({
  67. url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
  68. method: 'POST',
  69. custom: {
  70. showLoading: false, // 不用加载中
  71. showError: false, // 不展示错误提示
  72. },
  73. });
  74. }
  75. /**
  76. * 修改用户信息
  77. * @param avatar
  78. * @param mobile
  79. */
  80. export const updateUserInfo = (mobile) =>
  81. request({
  82. url: '/system/user/profile/update',
  83. method: 'PUT',
  84. data: { mobile }
  85. })
  86. /**
  87. * 修改头像
  88. * @param avatar
  89. */
  90. export const updateAvatar = (avatar) =>
  91. upload('/system/user/profile/update-avatar', {
  92. // #ifdef MP-ALIPAY
  93. fileType: 'image/video/audio', // 仅支付宝小程序,且必填。
  94. // #endif
  95. filePath: avatar, // 要上传文件资源的路径。
  96. name: 'avatarFile', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
  97. })
  98. /**
  99. * 修改密码
  100. * @param oldPwd
  101. * @param newPwd
  102. */
  103. export const changePassword = (oldPwd, newPwd) =>
  104. request({
  105. url: '/system/user/profile/update-password',
  106. method: 'PUT',
  107. data: { oldPassword: oldPwd, newPassword: newPwd },
  108. })
  109. /**
  110. * 通过userId获取token
  111. * @param userId
  112. */
  113. export const getTokenByUserId = (userId) =>
  114. request({
  115. url: '/system/auth/simple/login/' + userId,
  116. method: 'POST'
  117. })