index.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import qs from 'qs'
  2. import Request from '../..'
  3. enum Api {
  4. GetTenant = '/workspace/tenant/identifier',
  5. Login = '/auth/oauth2/token',
  6. LogOut = '/auth/token/logout',
  7. LoginByMobile = '/auth/mobile/token/sms'
  8. }
  9. export interface GetTenantParmas {
  10. identifier: string
  11. }
  12. export interface GetTenantResult {
  13. nickname: string
  14. tenantId: number
  15. tenantLevel: string
  16. tenantLogo: string
  17. }
  18. /** 登录-结果 */
  19. export interface LoginResult {
  20. access_token: string
  21. token_type: string
  22. refresh_token: string
  23. expires_in: number
  24. scope: string
  25. license: string
  26. active: boolean
  27. user_id: number
  28. client_id: string
  29. username: string
  30. }
  31. export function getTenantByName(data: GetTenantParmas) {
  32. return Request.get<GetTenantResult>({
  33. url: Api.GetTenant,
  34. params: data
  35. })
  36. }
  37. // 登录
  38. export const loginByUsername = (
  39. username: string,
  40. password: string,
  41. code: string,
  42. randomStr: string
  43. ) => {
  44. const grant_type = 'password'
  45. const dataObj = qs.stringify({ username: username, password: password })
  46. console.log(randomStr)
  47. return Request.post<LoginResult, false>({
  48. url: Api.Login,
  49. headers: {
  50. isToken: false,
  51. Authorization: 'Basic d2ViOndlYg=='
  52. },
  53. params: { randomStr, grant_type, code, scope: 'server' },
  54. data: dataObj
  55. })
  56. }