Explorar el Código

1、分配任务调整

yys hace 4 días
padre
commit
e3364a1f9f
Se han modificado 2 ficheros con 14 adiciones y 23 borrados
  1. 9 0
      src/api/monitor/tenantJob.js
  2. 5 23
      src/views/monitor/job/index.vue

+ 9 - 0
src/api/monitor/tenantJob.js

@@ -59,3 +59,12 @@ export function updateTenantJobStatus(configId, status) {
     params: { configId, status }
   })
 }
+
+/** 按模板全量覆盖租户分配 */
+export function assignTemplateTenants(templateId, tenantIds) {
+  return request({
+    url: '/monitor/tenantJob/template/' + templateId + '/tenants',
+    method: 'put',
+    data: tenantIds || []
+  })
+}

+ 5 - 23
src/views/monitor/job/index.vue

@@ -248,7 +248,7 @@
 
 <script>
 import { listTemplate, getTemplate, addTemplate, updateTemplate, delTemplate } from "@/api/monitor/jobTemplate";
-import { getTenantJobConfig, updateTenantJobStatus, syncTenantJob, syncAllTenantJob, saveTenantJobConfig, listTenantJobConfig } from "@/api/monitor/tenantJob";
+import { getTenantJobConfig, updateTenantJobStatus, syncTenantJob, syncAllTenantJob, saveTenantJobConfig, listTenantJobConfig, assignTemplateTenants } from "@/api/monitor/tenantJob";
 import { tenantList } from "@/api/tenant/tenant";
 import Crontab from '@/components/Crontab'
 
@@ -423,29 +423,11 @@ export default {
     },
     submitAssignTenant() {
       this.assignTenantSaving = true
-      // 只处理选择状态发生变化的租户,避免覆盖其他模板的分配
-      const promises = []
-      const prevIds = this.previousSelectedTenantIds || []
-      this.allTenants.forEach(t => {
-        const isSelected = this.selectedTenantIds.includes(t.id)
-        const wasSelected = prevIds.includes(t.id)
-        if (isSelected === wasSelected) return  // 无变化,跳过
-        const p = getTenantJobConfig(t.id).then(res => {
-          const currentIds = (res.data || []).map(c => c.templateId)
-          const newIds = isSelected
-            ? [...new Set([...currentIds, this.assignTemplate.templateId])]
-            : currentIds.filter(id => id !== this.assignTemplate.templateId)
-          return saveTenantJobConfig({ tenantId: t.id, templateIds: newIds, status: '0' })
-        })
-        promises.push(p)
-      })
-      if (promises.length === 0) {
-        this.assignTenantSaving = false
-        this.openAssignTenant = false
-        return
-      }
-      Promise.all(promises).then(() => {
+      const templateId = this.assignTemplate.templateId
+      const tenantIds = (this.selectedTenantIds || []).map(id => Number(id))
+      assignTemplateTenants(templateId, tenantIds).then(() => {
         this.msgSuccess('分配成功')
+        this.previousSelectedTenantIds = [...tenantIds]
         this.assignTenantSaving = false
         this.openAssignTenant = false
       }).catch(() => { this.assignTenantSaving = false })