ent-api.js 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. import MonitorApiBase from './base'
  2. import {
  3. ajaxFollowEntInfo,
  4. ajaxFollowEntAdd,
  5. ajaxFollowEntCancel
  6. } from '../api/follow-ent'
  7. export default class MonitorEntApi extends MonitorApiBase {
  8. constructor({ id }) {
  9. super()
  10. this.id = id
  11. }
  12. /**
  13. * 提供覆盖的ajax请求
  14. * @return {{}}
  15. */
  16. async ajaxGetState() {
  17. return ajaxFollowEntInfo({ endId: this.id }).then((res) => {
  18. const result = this.createModel()
  19. result.canFollow = res?.data?.isShow || false
  20. result.follow = res?.data?.followed || false
  21. if (res?.data?.info) {
  22. result.expands = res.data.info
  23. }
  24. return result
  25. })
  26. }
  27. async ajaxAdd() {
  28. return ajaxFollowEntAdd({ entId: this.id })
  29. }
  30. async ajaxRemove() {
  31. return ajaxFollowEntCancel({ entId: this.id })
  32. }
  33. }