ent-api.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if (result.success) {
  36. this.model.expands.used += 1
  37. this.model.expands.surplus = Math.max(this.model.expands.surplus - 1, 0)
  38. }
  39. return result
  40. })
  41. }
  42. async ajaxRemove() {
  43. return ajaxFollowEntCancel({ entId: this.id }).then(
  44. (res) => {
  45. const result = {
  46. success: false,
  47. data: {}
  48. }
  49. result.success = res?.error_code === 0 && res?.data === 'success'
  50. result.data = res?.data
  51. if (result.success) {
  52. this.model.expands.surplus += 1
  53. this.model.expands.used = Math.max(this.model.expands.used - 1, 0)
  54. }
  55. return result
  56. }
  57. )
  58. }
  59. }