Browse Source

feat:监控分组数据模型

yangfeng 6 months ago
parent
commit
b90a004e1d

+ 12 - 1
data/data-models/modules/quick-monitor/api/follow-ent.js

@@ -1,12 +1,13 @@
 import qs from 'qs'
 import qs from 'qs'
 import { useRequest } from '../../../api'
 import { useRequest } from '../../../api'
+
 export function ajaxFollowEntInfo(data) {
 export function ajaxFollowEntInfo(data) {
   data = qs.stringify(data)
   data = qs.stringify(data)
   return useRequest({
   return useRequest({
     url: '/bigmember/follow/ent/followCheck',
     url: '/bigmember/follow/ent/followCheck',
     method: 'post',
     method: 'post',
     noToast: true,
     noToast: true,
-    data: data
+    data
   })
   })
 }
 }
 
 
@@ -27,3 +28,13 @@ export function ajaxFollowEntCancel(data) {
     data
     data
   })
   })
 }
 }
+
+// 企业监控分组(获取、新增、编辑、删除),包含达到监控上限相关
+export function ajaxMonitorGroup(data) {
+  data = qs.stringify(data)
+  return useRequest({
+    url: '/bigmember/follow/ent/labelGroup',
+    method: 'post',
+    data
+  })
+}

+ 31 - 3
data/data-models/modules/quick-monitor/plugins/base.js

@@ -6,9 +6,14 @@
 class MonitorApiBase {
 class MonitorApiBase {
   constructor() {
   constructor() {
     this.model = this.createModel()
     this.model = this.createModel()
+    // 分组列表
+    this.groupList = []
+    // 分组id
+    this.groupId = ''
     // 通用函数Hooks
     // 通用函数Hooks
     this.doFetch = this.runFetch.bind(this)
     this.doFetch = this.runFetch.bind(this)
     this.doChange = this.runChange.bind(this)
     this.doChange = this.runChange.bind(this)
+    this.doFetchGroup = this.runFetchGroup.bind(this)
   }
   }
 
 
   /**
   /**
@@ -25,7 +30,9 @@ class MonitorApiBase {
    * @param follow
    * @param follow
    * @return {Promise<{}>}
    * @return {Promise<{}>}
    */
    */
-  async runChange(follow = this.model.follow) {
+  async runChange(follow = this.model.follow, params = {}) {
+    const { groupId } = params
+    this.groupId = groupId
     let result = {
     let result = {
       // 操作是否成功
       // 操作是否成功
       success: false,
       success: false,
@@ -33,7 +40,9 @@ class MonitorApiBase {
       data: {}
       data: {}
     }
     }
 
 
-    const doAction = follow ? this.ajaxRemove.bind(this) : this.ajaxAdd.bind(this)
+    const doAction = follow
+      ? this.ajaxRemove.bind(this)
+      : this.ajaxAdd.bind(this)
     result = await doAction()
     result = await doAction()
     if (result.success) {
     if (result.success) {
       this.model.follow = !follow
       this.model.follow = !follow
@@ -41,6 +50,17 @@ class MonitorApiBase {
     return result
     return result
   }
   }
 
 
+  /**
+   * 获取监控分组信息并赋值
+   */
+  async runFetchGroup(params = {}) {
+    const result = await this.ajaxGroup(params)
+    if (result.success) {
+      this.groupList = result.data
+    }
+    return result
+  }
+
   createModel() {
   createModel() {
     return {
     return {
       // 是否可以展示监控按钮
       // 是否可以展示监控按钮
@@ -53,7 +73,9 @@ class MonitorApiBase {
         surplus: 0,
         surplus: 0,
         // 已用数量
         // 已用数量
         used: 0
         used: 0
-      }
+      },
+      // 分组名
+      followedGroup: ''
     }
     }
   }
   }
 
 
@@ -64,12 +86,18 @@ class MonitorApiBase {
   async ajaxGetState() {
   async ajaxGetState() {
     return {}
     return {}
   }
   }
+
   async ajaxAdd() {
   async ajaxAdd() {
     return {}
     return {}
   }
   }
+
   async ajaxRemove() {
   async ajaxRemove() {
     return {}
     return {}
   }
   }
+
+  async ajaxGroup() {
+    return {}
+  }
 }
 }
 
 
 export default MonitorApiBase
 export default MonitorApiBase

+ 61 - 24
data/data-models/modules/quick-monitor/plugins/ent-api.js

@@ -1,9 +1,10 @@
-import MonitorApiBase from './base'
 import {
 import {
-  ajaxFollowEntInfo,
   ajaxFollowEntAdd,
   ajaxFollowEntAdd,
-  ajaxFollowEntCancel
+  ajaxFollowEntCancel,
+  ajaxFollowEntInfo,
+  ajaxMonitorGroup
 } from '../api/follow-ent'
 } from '../api/follow-ent'
+import MonitorApiBase from './base'
 
 
 export default class MonitorEntApi extends MonitorApiBase {
 export default class MonitorEntApi extends MonitorApiBase {
   constructor({ id }) {
   constructor({ id }) {
@@ -20,6 +21,7 @@ export default class MonitorEntApi extends MonitorApiBase {
       const result = this.createModel()
       const result = this.createModel()
       result.canFollow = res?.data?.isShow || false
       result.canFollow = res?.data?.isShow || false
       result.follow = res?.data?.followed || false
       result.follow = res?.data?.followed || false
+      result.followedGroup = res?.data?.followedGroup || ''
 
 
       if (res?.data?.info) {
       if (res?.data?.info) {
         result.expands = res.data.info
         result.expands = res.data.info
@@ -27,42 +29,77 @@ export default class MonitorEntApi extends MonitorApiBase {
       return result
       return result
     })
     })
   }
   }
+
   async ajaxAdd() {
   async ajaxAdd() {
-    return ajaxFollowEntAdd({ entId: this.id }).then((res) => {
+    return ajaxFollowEntAdd({ entId: this.id, groups: this.groupId }).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 ajaxFollowEntCancel({ entId: this.id }).then((res) => {
       const result = {
       const result = {
         success: false,
         success: false,
         msg: '',
         msg: '',
         data: {}
         data: {}
       }
       }
-      result.success = res?.error_code === 0 && res?.data?.status
+      result.success = res?.error_code === 0 && res?.data === 'success'
       result.data = res?.data
       result.data = res?.data
       if (result.success) {
       if (result.success) {
-        this.model.expands.used += 1
-        this.model.expands.surplus = Math.max(this.model.expands.surplus - 1, 0)
-      } else {
+        this.model.expands.surplus += 1
+        this.model.expands.used = Math.max(this.model.expands.used - 1, 0)
+        this.model.followedGroup = ''
+      }
+      else {
         result.msg = res?.error_msg || '抱歉,操作失败'
         result.msg = res?.error_msg || '抱歉,操作失败'
       }
       }
       return result
       return result
     })
     })
   }
   }
-  async ajaxRemove() {
-    return ajaxFollowEntCancel({ entId: this.id }).then(
-      (res) => {
-        const result = {
-          success: false,
-          msg: '',
-          data: {}
+
+  async ajaxGroup(params = {}) {
+    const { type, name, groupId, callback } = params
+    return ajaxMonitorGroup({ type, name, groupId }).then((res) => {
+      const result = {
+        success: false,
+        msg: '',
+        data: {}
+      }
+      result.success = res?.error_code === 0
+      result.data = res?.data
+      if (result.success) {
+        // 非获取(新增、修改、删除)成功后再次获取分组列表
+        if (type !== 'get') {
+          this.ajaxGroup({ type: 'get' })
         }
         }
-        result.success = res?.error_code === 0 && res?.data === 'success'
-        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 || '抱歉,操作失败'
+        else {
+          this.groupList = res?.data
         }
         }
-        return result
+        callback && callback()
       }
       }
-    )
+      else {
+        result.msg = res?.error_msg || '抱歉,操作失败'
+      }
+      return result
+    })
   }
   }
 }
 }