BaseCurdApi.js 880 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { api } from '@/utils/api'
  2. import QsUtil from '@/utils/QsUtil'
  3. export default class CurdApi {
  4. basePath
  5. api = api
  6. getList = (query) => api({
  7. url: `${this.basePath}/list`,
  8. method: 'POST',
  9. data: query
  10. })
  11. getPagination = (query, pagination) => api({
  12. url: `${this.basePath}/page${QsUtil.stringify({
  13. offset: (pagination.pageNo - 1) * pagination.pageSize,
  14. limit: pagination.pageSize
  15. })}`,
  16. method: 'POST',
  17. data: query
  18. })
  19. getDetail = (data, Target) => api({
  20. url: `${this.basePath}/${data[Target.$$idProp]}`,
  21. method: 'GET'
  22. })
  23. save = (data, saveType, Target) => api({
  24. url: `${this.basePath}`,
  25. method: saveType,
  26. data
  27. })
  28. delete = (data, Target) => api({
  29. url: `${this.basePath}/${data[Target.$$idProp]}`,
  30. method: 'DELETE'
  31. })
  32. constructor (basePath) {
  33. this.basePath = basePath
  34. }
  35. }