图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
803 B

2 weeks ago
  1. import store from '../store';
  2. const BASE_URL = 'https://api.imooc-blog.lgdsunday.club/api';
  3. function request({ url, data, method }) {
  4. return new Promise((resolve, reject) => {
  5. uni.request({
  6. url: BASE_URL + url,
  7. data,
  8. method,
  9. header: {
  10. Authorization: store.state.user.token
  11. },
  12. success: ({ data }) => {
  13. if (data.success) {
  14. resolve(data);
  15. } else {
  16. uni.showToast({
  17. title: data.message,
  18. icon: 'none',
  19. mask: true,
  20. duration: 3000
  21. });
  22. reject(data.message);
  23. }
  24. },
  25. fail: (error) => {
  26. reject(error);
  27. },
  28. complete: () => {
  29. // 关闭加载
  30. uni.hideLoading();
  31. }
  32. });
  33. });
  34. }
  35. export default request;