resource.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { stringify } from 'qs';
  2. import request from '../utils/request';
  3. import { resources, resource, signature } from '../utils/api';
  4. import { saveLocalSignature, getLocalSignature } from '../utils/helper';
  5. export async function getSignature (params) {
  6. /*
  7. const localSignature = getLocalSignature();
  8. const expireTime = Math.floor((new Date()).getTime() / 1000 + 5).toString(); // 5s缓冲时间
  9. // oss签名不存在或者已经过了有效期则请求新的签名
  10. let newSignature;
  11. if (!localSignature || localSignature.expire <= expireTime) {
  12. return request(`${signature}?${stringify(params)}`);
  13. } else {
  14. return { data: localSignature };
  15. }
  16. */
  17. // 每次都重新请求签名 TODO: 保存签名到本地减少请求次数
  18. // return request(`${signature}?${stringify(params)}`);
  19. return request(`http://127.0.0.1:8700`);
  20. }
  21. export async function query (params) {
  22. return request(`${resources}?${stringify(params)}`);
  23. }
  24. export async function create(params) {
  25. const options = {
  26. method: 'POST',
  27. body: JSON.stringify(params),
  28. };
  29. return request(`${resource}`, options);
  30. }
  31. export async function remove ({ id }) {
  32. const options = { method: 'DELETE' };
  33. return request(`${resource}/${id}`, options);
  34. }
  35. export async function update(params) {
  36. const options = {
  37. method: 'PUT',
  38. body: JSON.stringify(params),
  39. };
  40. return request(`${resource}`, options);
  41. }