request.ts 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. fetch,
  3. fetchfile
  4. } from "./fetch/interceptos.js"
  5. const obj = {
  6. headerGET: {
  7. "Content-type": 'application/x-www-from-urlencoded'
  8. },
  9. headerPOST: {
  10. "Content-type": 'application/json'
  11. },
  12. headerFORM: {
  13. "Content-type": 'multipart/form-data'
  14. }
  15. }
  16. const http = {
  17. // get请求
  18. get(url: String, params: Object) {
  19. let opt = {
  20. header: obj['headerGET'],
  21. method: "GET",
  22. data: params
  23. }
  24. return fetch(url, opt)
  25. },
  26. // post请求
  27. post(action: String, params: Object) {
  28. let opt = {
  29. header: obj['headerPOST'],
  30. method: "POST",
  31. data: params
  32. }
  33. if (params) {
  34. opt.data = {
  35. 'Method': action,
  36. 'Content': params
  37. }
  38. }
  39. let apiname = action;
  40. if (apiname.indexOf("Safe_") == 0) {
  41. apiname = "ExecuteSafe";
  42. }
  43. else {
  44. apiname = apiname === "Login" ? "Login" : "Execute"
  45. }
  46. return fetch(apiname, opt)
  47. },
  48. // post请求
  49. upload(action: String, params: Object) {
  50. return fetchfile(action, params)
  51. }
  52. }
  53. export default http