|
@@ -0,0 +1,61 @@
|
|
|
+import MonitorApiBase from './base'
|
|
|
+import {
|
|
|
+ ajaxFollowProjectInfo,
|
|
|
+ ajaxFollowProjectAdd,
|
|
|
+ ajaxFollowProjectCancel
|
|
|
+} from '../api/follow-project'
|
|
|
+
|
|
|
+export default class MonitorProjectApi extends MonitorApiBase {
|
|
|
+ constructor({ id, fid = '' }) {
|
|
|
+ super()
|
|
|
+ this.id = id
|
|
|
+ this.fid = fid
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提供覆盖的ajax请求
|
|
|
+ * @return {{}}
|
|
|
+ */
|
|
|
+ async ajaxGetState() {
|
|
|
+ return await ajaxFollowProjectInfo({ sid: this.id }).then((res) => {
|
|
|
+ const result = this.createModel()
|
|
|
+ result.canFollow = res?.data?.showFollow || false
|
|
|
+ result.follow = res?.data?.flag || false
|
|
|
+
|
|
|
+ if (res?.data?.info) {
|
|
|
+ result.expands = res.data.info
|
|
|
+ }
|
|
|
+ if (res?.data?.fig) {
|
|
|
+ this.fid = res.data.fig
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ })
|
|
|
+ }
|
|
|
+ async ajaxAdd() {
|
|
|
+ return ajaxFollowProjectAdd({ sid: this.id }).then((res) => {
|
|
|
+ const result = {
|
|
|
+ success: false,
|
|
|
+ data: {}
|
|
|
+ }
|
|
|
+ result.success = res?.error_code === 0 && res?.data?.status === 0
|
|
|
+ result.data = res?.data
|
|
|
+ if (res?.data?.fig) {
|
|
|
+ this.fid = res.data.fig
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ })
|
|
|
+ }
|
|
|
+ async ajaxRemove() {
|
|
|
+ return ajaxFollowProjectCancel({ sid: this.id, fid: this.fid }).then(
|
|
|
+ (res) => {
|
|
|
+ const result = {
|
|
|
+ success: false,
|
|
|
+ data: {}
|
|
|
+ }
|
|
|
+ result.success = res?.error_code === 0 && res?.data?.status === 0
|
|
|
+ result.data = res?.data
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|