api.js 777 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import http from '../utils/http'
  2. const getProject = (that, success = null, error = null) => {
  3. http({
  4. url: 'projects/detail',
  5. data: {
  6. id: that.data.id
  7. },
  8. success: function(res) {
  9. if(res.code == 0) {
  10. that.setData({
  11. project: res.data
  12. })
  13. }
  14. typeof success === "function" && success(res.data)
  15. },
  16. error: error
  17. })
  18. }
  19. const getByName = (that, url, name, data={}, success=null, error=null) => {
  20. http({
  21. url: url,
  22. data: data,
  23. success: function(res) {
  24. if(res.code == 0) {
  25. that.setData({
  26. [name]: res.data
  27. })
  28. }
  29. typeof success === "function" && success(res.data)
  30. },
  31. error: error
  32. })
  33. }
  34. const api = {
  35. getProject,
  36. getByName
  37. }
  38. export default api