瀏覽代碼

feat: [data-models/quick-monitor] 新增 client 类型支持

zhangyuhan 1 年之前
父節點
當前提交
b70e715e7e

+ 18 - 0
data/data-models/modules/quick-monitor/api/follow-client.js

@@ -0,0 +1,18 @@
+import qs from 'qs'
+import { useRequest } from '../../../api'
+export function ajaxFollowClientInfo(data) {
+  return useRequest({
+    url: '/publicapply/customer/check',
+    method: 'post',
+    data: data
+  })
+}
+
+export function ajaxFollowClientChange(data) {
+  return useRequest({
+    url: '/publicapply/customer/attention',
+    method: 'post',
+    data
+  })
+}
+

+ 8 - 1
data/data-models/modules/quick-monitor/model/index.js

@@ -1,13 +1,20 @@
 import MonitorEntApi from '../plugins/ent-api'
 import MonitorProjectApi from '../plugins/project-api'
+import MonitorClientApi from '../plugins/client-api'
 
 /**
  * 一键使用项目监控、企业监控功能
  * 1. 根据 type 查询当前监控信息
  * 2. 返回监控信息及改变监控状态的事件钩子 { state, doChange }
  */
+
+const APIS = {
+  project: MonitorProjectApi,
+  ent: MonitorEntApi,
+  client: MonitorClientApi
+}
 function useQuickMonitor({ type, params }) {
-  const useMonitorApi = type === 'project' ? MonitorProjectApi : MonitorEntApi
+  const useMonitorApi = APIS[type]
   return new useMonitorApi(params)
 }
 

+ 75 - 0
data/data-models/modules/quick-monitor/plugins/client-api.js

@@ -0,0 +1,75 @@
+import MonitorApiBase from './base'
+import {
+  ajaxFollowClientInfo,
+  ajaxFollowClientChange
+} from "../api/follow-client";
+
+export default class MonitorClientApi extends MonitorApiBase {
+  constructor({ id }) {
+    super()
+    this.id = id
+  }
+
+  /**
+   * 提供覆盖的ajax请求
+   * @return {{}}
+   */
+  async ajaxGetState() {
+    return ajaxFollowClientInfo({ name_list: [this.id] }).then((res) => {
+      const result = this.createModel()
+      result.canFollow = true
+      result.follow = false
+      if (res?.data?.follow) {
+        if (res.data.follow[this.id]) {
+          result.follow = true
+        }
+      }
+
+      if (res?.data?.count) {
+        result.expands = {
+          used: res?.data?.count?.use || 0,
+          surplus: res?.data?.count?.surplus || 0
+        }
+      }
+      return result
+    })
+  }
+  async ajaxAdd() {
+    return ajaxFollowClientChange({ name: this.id, b: false }).then((res) => {
+      const result = {
+        success: false,
+        msg: '',
+        data: {}
+      }
+      result.success = res?.error_code === 0 && res?.data?.status
+      result.data = res?.data
+      if (result.success) {
+        this.model.expands.used += 1
+        this.model.expands.surplus = Math.max(this.model.expands.surplus - 1, 0)
+      } else {
+        result.msg = res?.error_msg || '抱歉,操作失败'
+      }
+      return result
+    })
+  }
+  async ajaxRemove() {
+    return ajaxFollowClientChange({ name: this.id, b: true }).then(
+      (res) => {
+        const result = {
+          success: false,
+          msg: '',
+          data: {}
+        }
+        result.success = res?.error_code === 0 && res?.data?.status
+        result.data = res?.data
+        if (result.success) {
+          this.model.expands.surplus += 1
+          this.model.expands.used = Math.max(this.model.expands.used - 1, 0)
+        } else {
+          result.msg = res?.error_msg || '抱歉,操作失败'
+        }
+        return result
+      }
+    )
+  }
+}