churf
2023-08-23 6b1c6be17e4c0cbb9bf0bc76d2c4c18b996496c7
表单校验效果优化
5 files modified
137 ■■■■■ changed files
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/rest/TaskDaliyController.java 4 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/TaskDaliyService.java 2 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java 22 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/api/task/taskDaliy.js 3 ●●●●● patch | view | raw | blame | history
eladmin-web-master/src/views/task/taskDaliy/index.vue 106 ●●●●● patch | view | raw | blame | history
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/rest/TaskDaliyController.java
@@ -137,7 +137,7 @@
    @Log("查询任务的总消耗工时")
    @ApiOperation("判断当前这个日报填写的这个进度是否合法")
    @PreAuthorize("@el.check('taskDaliy:list')")
    public ResponseEntity<Object> checkTask(Long taskProgress, String taskUserId) {
        return new ResponseEntity<>(taskDaliyService.checkTask(taskProgress, taskUserId.split(",")[0]),HttpStatus.OK);
    public ResponseEntity<Object> checkTask(Long taskProgress, String taskUserId, String fillDate) {
        return new ResponseEntity<>(taskDaliyService.checkTask(taskProgress, taskUserId.split(",")[0],fillDate.split(",")[0]),HttpStatus.OK);
    }
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/TaskDaliyService.java
@@ -118,6 +118,6 @@
    TaskDaliyMongo getDailyDetail(String taskUserId, String fillDate);
    boolean checkTask(Long taskProgress, String taskUserId);
    boolean checkTask(Long taskProgress, String taskUserId, String fillDate);
}
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskDaliyServiceImpl.java
@@ -595,15 +595,21 @@
    }
    @Override
    public boolean checkTask(Long taskProgress, String taskUserId) {
        //获取当前用户,当前任务,所有的日报
        List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(taskUserId)), TaskDaliyMongo.class);
        for (int i = 0; i < daliyMongoList.size(); i++) {
            //如果有一个日报的任务进度要比这个大,就返回假
            if(daliyMongoList.get(i).getTaskProgress() > taskProgress){
                return false;
    public boolean checkTask(Long taskProgress, String taskUserId, String fillDate) {
        try {
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
            Date date = ft.parse(fillDate);
            //获取当前用户,当前任务,所有的日报
            List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(new Query(new Criteria("userId").is(SecurityUtils.getCurrentUserId()).and("taskUserMongo.id").is(taskUserId)), TaskDaliyMongo.class);
            for (int i = 0; i < daliyMongoList.size(); i++) {
                //如果有一个日报的任务进度要比这个大,就返回假
                if(daliyMongoList.get(i).getTaskProgress() > taskProgress && date.after(daliyMongoList.get(i).getFillDate())){
                    return false;
                }
            }
            return true;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
eladmin-web-master/src/api/task/taskDaliy.js
@@ -82,9 +82,8 @@
export function checkTaskHours(params) {
  return request({
    url: 'api/taskDaliy/checkTask?taskProgress=' + params.taskProgress + '&taskUserId=' + params.taskUserId,
    url: 'api/taskDaliy/checkTask?taskProgress=' + params.taskProgress + '&taskUserId=' + params.taskUserId + '&fillDate=' + params.fillDate,
    method: 'get',
    async: false,
    params
  })
}
eladmin-web-master/src/views/task/taskDaliy/index.vue
@@ -180,7 +180,7 @@
                :value="item.id"
              />
            </el-select>
            <el-select v-else filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
            <el-select v-else v-model="form" filterable clearable placeholder="请选择" style="width: 340px;" :disabled="form.flag" @change="formTaskUserChange">
              <el-option
                v-for="item in formTaskUserIds"
                :key="item.id"
@@ -218,7 +218,7 @@
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="checkForm(1)">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
@@ -442,6 +442,12 @@
    'form.consumedHours': function(newVal, oldVal) {
      this.newValue = newVal
      this.oldValue = oldVal
    },
    'confirmProgress': function(newVal) {
      this.confirmProgress = newVal
    },
    'confirmHours': function(newVal) {
      this.confirmHours = newVal
    }
  },
  methods: {
@@ -584,33 +590,58 @@
      this.taskLoading = false
    },
    [CRUD.HOOK.beforeSubmit]() {
      // 先check一下
      this.resData = this.getCheckResult(this.form.taskProgress, this.form.taskUserMongo.id)
      console.log(2)
      console.log(this.resData)
      if (this.resData === false && !this.confirmProgress) {
        // 为假
        this.centerDialogVisibleTaskProgress = true
        this.waitForPropertyConfirmProgress()
        return false
      }
      const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
      if (result > this.form.taskHours && !this.confirmHours) {
        this.centerDialogVisibleTaskHours = true
        this.waitForPropertyConfirmHours()
        return false
      }
      return true
    },
    getCheckResult(taskProgress, taskUserId) {
      return (async function() {
        console.log(1)
        const result = await crudTaskDaliy.checkTaskHours({ 'taskProgress': taskProgress, 'taskUserId': taskUserId })
        console.log(3)
        return result
      })()
    checkForm(flag) {
      crudTaskDaliy.checkTaskHours({ 'taskProgress': this.form.taskProgress, 'taskUserId': this.form.taskUserMongo.id, 'fillDate': this.form.fillDate }).then(res => {
        if (res === false && !this.confirmProgress) {
          flag++
          // 为假
          this.centerDialogVisibleTaskProgress = true
          if (this.confirmProgress) {
            // 如果确定了
            const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
            if (result > this.form.taskHours && !this.confirmHours) {
              this.centerDialogVisibleTaskHours = true
              if (this.confirmHours) {
                this.crud.submitCU()
              } else {
                if (flag > 1) {
                  return
                } else {
                  this.checkForm()
                }
              }
            } else {
              this.crud.submitCU()
            }
          } else {
            if (flag > 1) {
              return
            } else {
              // 没确定
              this.checkForm()
            }
          }
        } else {
          flag++
          // 判读时间
          const result = (this.form.alreadyConsumedHours - 0) + (this.newValue - 0) - (this.oldValue - 0)
          if (result > this.form.taskHours && !this.confirmHours) {
            this.centerDialogVisibleTaskHours = true
            if (this.confirmHours) {
              this.crud.submitCU()
            } else {
              if (flag > 1) {
                return
              } else {
                this.checkForm()
              }
            }
          } else {
            this.crud.submitCU()
          }
        }
      })
    },
    getAdventTasks() {
      crudTaskUser.getAdventTasks().then(res => {
@@ -755,25 +786,6 @@
    submitDialogTaskProgress() {
      this.centerDialogVisibleTaskProgress = false
      this.confirmProgress = true
    },
    waitForPropertyConfirmHours() {
      new Promise(resolve => {
        this.$watch('confirmHours', (newValue) => {
          if (newValue === true) {
            console.log(newValue)
            resolve(this.crud.submitCU())
          }
        })
      })
    },
    waitForPropertyConfirmProgress() {
      new Promise(resolve => {
        this.$watch('confirmProgress', (newValue) => {
          if (newValue === true) {
            resolve(this.crud.submitCU())
          }
        })
      })
    }
  }
}