index.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import qs from 'qs';
  2. import { request } from '@/utils';
  3. /**
  4. * 获取认证授权服务 url
  5. */
  6. const apiUaa = (path: string, params?: unknown) => {
  7. const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
  8. return `/api-uaa${apiUrl}`;
  9. };
  10. /**
  11. * 获取业务服务 url
  12. */
  13. const apiBiz = (path: string, params?: unknown) => {
  14. const apiUrl = params ? `${path}?${qs.stringify(params)}` : path;
  15. return `/api-biz${apiUrl}`;
  16. };
  17. // 登录和注销
  18. export const loginUser = async () => {
  19. const params = {
  20. grant_type: 'password',
  21. username: 'admin1',
  22. password: 'admin',
  23. };
  24. await request(apiUaa('/oauth/token', params), {
  25. method: 'POST',
  26. headers: {
  27. Authorization: 'Basic ' + btoa('unimat:unimat'),
  28. },
  29. });
  30. };
  31. export const logoutUser = async () => {
  32. await request(apiUaa('/oauth/remove/token'));
  33. };
  34. export const refreshUser = async () => {
  35. await request(apiUaa('/oauth/token'));
  36. };
  37. // 设备列表
  38. export const addDevice = async () => {
  39. await request(apiBiz('/device/add'));
  40. };
  41. // 网关基本信息
  42. export const addGateway = async () => {
  43. await request(apiBiz('/gateway/add'));
  44. };
  45. // 协议基本信息
  46. export const addProtocolBaseInfo = async () => {
  47. await request(apiBiz('/protocolBaseInfo/add'), {
  48. method: 'POST',
  49. });
  50. };