From 1c5e7b2cec2d26d9b1d605c6fe49566b037c9411 Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Mon, 09 Jun 2025 08:24:33 +0000
Subject: [PATCH] 添加任务迁移功能

---
 eladmin-web-master/src/views/task/task/index.vue |  273 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 267 insertions(+), 6 deletions(-)

diff --git a/eladmin-web-master/src/views/task/task/index.vue b/eladmin-web-master/src/views/task/task/index.vue
index 83f1c86..d6e8e27 100644
--- a/eladmin-web-master/src/views/task/task/index.vue
+++ b/eladmin-web-master/src/views/task/task/index.vue
@@ -100,7 +100,11 @@
           :disabled="this.crud.selections.length === 0"
           @click="doTaskCompleted"
         >任务完结</el-button>
+        <el-button slot="right" icon="el-icon-guide" class="filter-item" size="mini" type="primary" @click="toMigration">
+          任务迁移
+        </el-button>
       </crudOperation>
+
       <!--表单组件-->
       <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
         <el-form ref="form" :model="form" :rules="rules" size="small" label-width="110px">
@@ -230,6 +234,91 @@
           <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
         </div>
       </el-dialog>
+
+      <!--任务迁移表单-->
+      <el-dialog :close-on-click-modal="false" :before-close="closeMigration" :visible.sync="migrationParams.visible" title="任务迁移" width="960px">
+        <el-form ref="migrationForm" :model="migrationParams.form" :rules="migrationParams.rules" size="small" label-width="80px">
+          <el-row :gutter="0">
+            <el-col :span="11" class="part-form-box">
+              <div class="part-form-title">迁移来源</div>
+              <!-- <el-row :gutter="0"> -->
+              <el-col :span="22">
+                <el-form-item label="所属项目" prop="sourceProjectId" required>
+                  <el-select v-model="migrationParams.form.sourceProjectId" filterable clearable placeholder="请先选择所属项目" style="width: 300px;" @change="sourceProjectChange">
+                    <el-option v-for="item in projects" :key="item.id" :label="item.name" :value="item.id" />
+                  </el-select>
+                </el-form-item>
+
+                <el-form-item v-show="migrationParams.sourceTaskList.length > 0" label="所属任务" prop="sourceTaskId" :required="migrationParams.form.sourceLevel === 'task' || migrationParams.form.sourceLevel === 'taskUser'">
+                  <el-select v-model="migrationParams.form.sourceTaskId" filterable clearable placeholder="请先选择所属任务" style="width: 300px;" @change="sourceTaskChange">
+                    <el-option v-for="item in migrationParams.sourceTaskList" :key="item.id" :label="item.name" :value="item.id" />
+                  </el-select>
+                </el-form-item>
+
+                <el-form-item v-show="migrationParams.sourceTaskUserList.length > 0" label="分配任务" prop="sourceTaskUserId" :required="migrationParams.form.sourceLevel === 'taskUser'">
+                  <el-select v-model="migrationParams.form.sourceTaskUserId" multiple filterable clearable placeholder="请先选择分配任务" style="width: 300px;">
+                    <el-option v-for="item in migrationParams.sourceTaskUserList" :key="item.id" :label="item.name" :value="item.id" />
+                  </el-select>
+                </el-form-item>
+              </el-col>
+              <el-col :span="2">
+                <el-radio-group v-model="migrationParams.form.sourceLevel" @input="sourceLevelChange">
+                  <el-form-item prop="sourceLevel" label-width="0">
+                    <el-radio label="project" disabled><span /></el-radio>
+                  </el-form-item>
+
+                  <el-form-item v-show="migrationParams.sourceTaskList.length > 0" prop="sourceLevel" label-width="0">
+                    <el-radio label="task"><span /></el-radio>
+                  </el-form-item>
+
+                  <el-form-item v-show="migrationParams.sourceTaskUserList.length > 0" prop="sourceLevel" label-width="0">
+                    <el-radio label="taskUser"><span /></el-radio>
+                  </el-form-item>
+                </el-radio-group>
+              </el-col>
+              <!-- </el-row> -->
+            </el-col>
+            <el-col :span="2">
+              <div style="text-align: center; line-height: 70px;">
+                <i class="el-icon-d-arrow-right" style="font-size: 36px;" />
+              </div>
+            </el-col>
+            <el-col :span="11" class="part-form-box">
+              <div class="part-form-title">迁移目标</div>
+              <el-col :span="22">
+                <el-form-item label="所属项目" prop="targetProjectId" required>
+                  <el-select v-model="migrationParams.form.targetProjectId" filterable clearable placeholder="请先选择所属项目" style="width: 300px;" @change="targetProjectChange">
+                    <el-option v-for="item in projects" :key="item.id" :label="item.name" :value="item.id" />
+                  </el-select>
+                </el-form-item>
+
+                <el-form-item v-show="migrationParams.targetTaskList.length > 0" label="所属任务" prop="targetTaskId" :required="migrationParams.form.targetLevel === 'task'">
+                  <el-select v-model="migrationParams.form.targetTaskId" filterable clearable placeholder="请先选择所属任务" style="width: 300px;">
+                    <el-option v-for="item in migrationParams.targetTaskList" :key="item.id" :label="item.name" :value="item.id" />
+                  </el-select>
+                </el-form-item>
+              </el-col>
+
+              <el-col :span="2">
+                <el-radio-group v-model="migrationParams.form.targetLevel" disabled>
+                  <el-form-item prop="targetLevel" label-width="0">
+                    <el-radio label="project"><span /></el-radio>
+                  </el-form-item>
+
+                  <el-form-item v-show="migrationParams.targetTaskList.length > 0" prop="targetLevel" label-width="0">
+                    <el-radio label="task"><span /></el-radio>
+                  </el-form-item>
+                </el-radio-group>
+              </el-col>
+            </el-col>
+          </el-row>
+        </el-form>
+        <div slot="footer" class="dialog-footer">
+          <el-button type="text" @click="closeMigration">取消</el-button>
+          <el-button :loading="migrationParams.loading" type="primary" @click="doMigration">确认</el-button>
+        </div>
+      </el-dialog>
+
       <!--表格渲染-->
       <el-table
         ref="table"
@@ -295,6 +384,7 @@
 
 <script>
 import crudTask from '@/api/task/task'
+import crudTaskUser from '@/api/task/taskUser'
 import CRUD, { presenter, header, form, crud } from '@crud/crud'
 import rrOperation from '@crud/RR.operation'
 import crudOperation from '@crud/CRUD.operation'
@@ -328,6 +418,29 @@
       } else {
         callback()
       }
+    }
+    var migrationValidate = (rule, value, callback) => {
+      const that = this
+      if (rule.field === 'sourceTaskId' && (that.migrationParams.form.sourceLevel === 'task' || that.migrationParams.form.sourceLevel === 'taskUser')) {
+        if (value == null || value === '' || value === undefined) {
+          callback(new Error('所属任务不能为空'))
+        } else if (that.migrationParams.form.sourceLevel === 'task' && that.migrationParams.form.sourceProjectId === that.migrationParams.form.targetProjectId) {
+          callback(new Error('所属任务已属于迁移目标所属项目'))
+        }
+      }
+      if (rule.field === 'sourceTaskUserId' && that.migrationParams.form.sourceLevel === 'taskUser') {
+        if (value == null || value === undefined || (value.length !== undefined && value.length === 0)) {
+          callback(new Error('分配任务不能为空'))
+        } else if (that.migrationParams.form.sourceTaskId === that.migrationParams.form.targetTaskId) {
+          callback(new Error('分配任务已属于迁移目标所属任务'))
+        }
+      }
+      if (rule.field === 'targetTaskId' && that.migrationParams.form.targetLevel === 'task') {
+        if (value == null || value === '' || value === undefined) {
+          callback(new Error('所属任务不能为空'))
+        }
+      }
+      callback()
     }
     return {
       props: { multiple: true },
@@ -515,7 +628,33 @@
       dialogVisible: false,
       taskDetailDisabled: true,
       calendarLoading: true,
-      isShow: false
+      isShow: false,
+      // 任务迁移参数
+      migrationParams: {
+        visible: false,
+        loading: false,
+        form: {
+          sourceProjectId: null,
+          sourceTaskId: null,
+          sourceTaskUserId: [],
+          sourceLevel: 'task',
+          targetProjectId: null,
+          targetTaskId: null,
+          targetLevel: 'project'
+        },
+        sourceTaskList: [],
+        targetTaskList: [],
+        sourceTaskUserList: [],
+        rules: {
+          sourceProjectId: [{ required: true, message: '所属项目不能为空', trigger: 'change' }],
+          sourceTaskId: [{ validator: migrationValidate, trigger: 'change' }],
+          sourceTaskUserId: [{ validator: migrationValidate, trigger: 'change' }],
+          sourceLevel: [{ required: true, message: '迁移来源类别不能为空', trigger: 'change' }],
+          targetProjectId: [{ required: true, message: '所属项目不能为空', trigger: 'change' }],
+          targetTaskId: [{ validator: migrationValidate, trigger: 'change' }],
+          targetLevel: [{ required: true, message: '迁移目标类别不能为空', trigger: 'change' }]
+        }
+      }
     }
   },
   computed: {
@@ -837,6 +976,116 @@
     },
     draw() {
       this.dialogVisible = true
+    },
+
+    // 开启任务迁移
+    toMigration() {
+      const that = this
+      that.$set(that.migrationParams, 'visible', true)
+    },
+
+    // 关闭任务迁移
+    closeMigration() {
+      const that = this
+
+      that.$refs.migrationForm.clearValidate()
+      that.$set(that.migrationParams, 'loading', false)
+      that.$set(that.migrationParams, 'visible', false)
+      that.$set(that.migrationParams, 'form', {
+        sourceProjectId: null,
+        sourceTaskId: null,
+        sourceTaskUserId: [],
+        sourceLevel: 'task',
+        targetProjectId: null,
+        targetTaskId: null,
+        targetLevel: 'project'
+      })
+      that.$set(that.migrationParams, 'sourceTaskList', [])
+      that.$set(that.migrationParams, 'targetTaskList', [])
+      that.$set(that.migrationParams, 'sourceTaskUserList', [])
+    },
+
+    // 执行任务迁移
+    doMigration() {
+      const that = this
+      that.$refs.migrationForm.validate((valid) => {
+        if (!valid) {
+          return
+        }
+
+        // 构建访问参数
+        that.$set(that.migrationParams, 'loading', true)
+        const data = {}
+        if (that.migrationParams.form.sourceLevel === 'task' && that.migrationParams.form.targetLevel === 'project') {
+          that.$set(data, 'sourceTaskId', that.migrationParams.form.sourceTaskId)
+          that.$set(data, 'targetProjectId', that.migrationParams.form.targetProjectId)
+        }
+        if (that.migrationParams.form.sourceLevel === 'taskUser' && that.migrationParams.form.targetLevel === 'task') {
+          that.$set(data, 'sourceTaskUserId', that.migrationParams.form.sourceTaskUserId)
+          that.$set(data, 'targetTaskId', that.migrationParams.form.targetTaskId)
+        }
+
+        // 执行迁移API
+        that.crud.crudMethod.migration(data).then(() => {
+          that.$message({ type: 'success', message: '迁移成功' })
+          that.closeMigration()
+        }).catch(() => {
+          that.$set(that.migrationParams, 'loading', false)
+        })
+      })
+    },
+
+    // 获取来源任务
+    sourceProjectChange(projectId) {
+      const that = this
+      that.$set(that.migrationParams, 'sourceTaskList', [])
+      that.$set(that.migrationParams.form, 'sourceTaskId', null)
+      that.getSecondTask(that.migrationParams, 'sourceTaskList', projectId)
+    },
+
+    // 获取目标任务
+    targetProjectChange(projectId) {
+      const that = this
+      that.$set(that.migrationParams, 'targetTaskList', [])
+      that.$set(that.migrationParams.form, 'targetTaskId', null)
+      that.getSecondTask(that.migrationParams, 'targetTaskList', projectId)
+    },
+
+    // 获取二级任务
+    getSecondTask(target, key, projectId) {
+      const that = this
+      if (projectId) {
+        const params = { isTop: true, projectId: projectId, sort: 'id,desc' }
+        crudTask.ChildrenTaskAnyParent(params).then(res => {
+          that.$set(target, key, res)
+        }).catch(() => {
+          that.$set(target, key, [])
+        })
+      } else {
+        that.$set(target, key, [])
+      }
+    },
+
+    // 获取来源任务分配
+    sourceTaskChange(taskId) {
+      const that = this
+      that.$set(that.migrationParams, 'sourceTaskUserList', [])
+      that.$set(that.migrationParams.form, 'sourceTaskUserId', [])
+      crudTaskUser.getAllSimple({ taskId }).then(res => {
+        that.$set(that.migrationParams, 'sourceTaskUserList', res)
+      }).catch(() => {
+        that.$set(that.migrationParams, 'sourceTaskUserList', [])
+      })
+    },
+
+    // 迁移层级变更
+    sourceLevelChange(level) {
+      const that = this
+      if (level === 'task') {
+        that.$set(that.migrationParams.form, 'targetLevel', 'project')
+      } else if (level === 'taskUser') {
+        that.$set(that.migrationParams.form, 'targetLevel', 'task')
+      }
     }
   }
 }
@@ -863,10 +1112,22 @@
     display: inline-block;
     vertical-align: middle;
     margin: 0 3px 10px 0;
+  }
+  .block input {
+    height: 30.5px;
+    line-height: 30.5px;
+  }
 
-      input {
-      height: 30.5px;
-      line-height: 30.5px;
-      }
-    }
+  .part-form-box {
+    border: 1px solid #dcdfe6;
+    border-radius: 10px;
+  }
+
+  .part-form-title {
+    font-size: 16px;
+    font-weight: 700;
+    color: #606266;
+    line-height: 52px;
+    text-align: center;
+  }
 </style>

--
Gitblit v1.9.3