index.js 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * @Author: 廖明明
  3. * @Date: 2022-03-30 15:54:48
  4. * @LastEditors: 廖明明
  5. * @LastEditTime: 2022-04-02 14:27:53
  6. * @Description:后端服务入口文件
  7. */
  8. import config from "./config.js";
  9. import "./auth.js";
  10. import "./interceptor.js";
  11. /**
  12. * @description:封装请求函数
  13. * @param {string} url 接口地址,以”/“开头
  14. * @param {object} data 请求参数
  15. * @param {string} method 请求类型
  16. * @param {object} header 请求头
  17. * @return {promise}
  18. * @author: 廖明明
  19. */
  20. export function request({
  21. url = "",
  22. data = {},
  23. method = "GET",
  24. header = {}
  25. }) {
  26. return new Promise((resolve) => {
  27. uni.request({
  28. method,
  29. url: config.baseUrl + url,
  30. data,
  31. header,
  32. dataType: "json",
  33. success(res) {
  34. resolve(res.data);
  35. },
  36. fail(err) {
  37. uni.hideLoading();
  38. uni.showToast({
  39. icon: "none",
  40. title: "请求失败!",
  41. });
  42. },
  43. });
  44. });
  45. }