ent-api.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 }).then((res) => {
  29. const result = {
  30. success: false,
  31. data: {}
  32. }
  33. result.success = res?.error_code === 0 && res?.data?.status === 0
  34. result.data = res?.data
  35. return result
  36. })
  37. }
  38. async ajaxRemove() {
  39. return ajaxFollowEntCancel({ entId: this.id }).then(
  40. (res) => {
  41. const result = {
  42. success: false,
  43. data: {}
  44. }
  45. result.success = res?.error_code === 0 && res?.data === 'success'
  46. result.data = res?.data
  47. return result
  48. }
  49. )
  50. }
  51. }