project-api.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import MonitorApiBase from './base'
  2. import {
  3. ajaxFollowProjectInfo,
  4. ajaxFollowProjectAdd,
  5. ajaxFollowProjectCancel
  6. } from '../api/follow-project'
  7. export default class MonitorProjectApi extends MonitorApiBase {
  8. constructor({ id, fid = '' }) {
  9. super()
  10. this.id = id
  11. this.fid = fid
  12. }
  13. /**
  14. * 提供覆盖的ajax请求
  15. * @return {{}}
  16. */
  17. async ajaxGetState() {
  18. return await ajaxFollowProjectInfo({ sid: this.id }).then((res) => {
  19. const result = this.createModel()
  20. result.canFollow = res?.data?.showFollow || false
  21. result.follow = res?.data?.flag || false
  22. if (res?.data?.info) {
  23. result.expands = res.data.info
  24. }
  25. if (res?.data?.fig) {
  26. this.fid = res.data.fig
  27. }
  28. return result
  29. })
  30. }
  31. async ajaxAdd() {
  32. return ajaxFollowProjectAdd({ sid: this.id }).then((res) => {
  33. const result = {
  34. success: false,
  35. data: {}
  36. }
  37. result.success = res?.error_code === 0 && res?.data?.status === 0
  38. result.data = res?.data
  39. if (res?.data?.followId) {
  40. this.fid = res.data.followId
  41. }
  42. return result
  43. })
  44. }
  45. async ajaxRemove() {
  46. return ajaxFollowProjectCancel({ sid: this.id, fid: this.fid }).then(
  47. (res) => {
  48. const result = {
  49. success: false,
  50. data: {}
  51. }
  52. result.success = res?.error_code === 0 && res?.data === 'success'
  53. result.data = res?.data
  54. return result
  55. }
  56. )
  57. }
  58. }