分类
javascript

FTS迁移代码优化

接口从多变少

从前在写fts的时候会有转办,加签,同意,驳回等接口。每个步骤的转办都不是同一个接口。因此为每个接口都写了一个api和store。现在,需要让接口精简,所有的转办都用同一个接口,但接口地址不同。

以转办举例

  // 转办api
  entrustTask(param) {
    let path = '';
    if (Reflect.has(param, 'path')) {
      path = Reflect.get(param, 'path');
      Reflect.deleteProperty(param, 'path');
    }
    return db.post(path, param);
  },
 // 转办store
    entrustTask(store, param) {
      return db.entrustTask(param);
    },
// 转办调用
this.entrustTask({
                remarks,
                entrustUsers: people.toString(),
                nodeId: this.$route.params.nodeId,
                requestId: this.$route.params.id,
                taskId: this.$route.params.taskId,
                path,
              }).then((req) => {
                this.modal.visible = false;
                this.$message.success(req.msg);
                this.closePage();
              });

使用查表

现在的方式

 const pathConfig = {
        11: 'new/mqf/wfMarketIssueTrack/rejectDelay',
        12: 'new/mqf/wfMarketIssueApplyClose/rejectTask',
        13: 'new/mqf/wfMarketIssueRespDeptLeaderApproval/rejectTask',
        14: 'new/mqf/wfMarketIssueMgtDeptApproval/rejectTask',
        15: 'new/mqf/wfMarketIssueMgtDeptLeaderApproval/rejectTask',
      };
      this.approveForm.validateFieldsAndScroll((err, values) => {
        if (!err) {
          this.loading.reject = true;
          const { remarks } = values;
          this.rejectApproval({
            path: pathConfig[this.$route.params.status],
            nodeId: this.$route.params.nodeId,
            remarks,
            requestId: this.$route.params.id,
            taskId: this.$route.params.taskId,
          }).then((res) => {
            this.$message.success(res.msg);
            setTimeout(window.close, 2000);
          }).catch((error) => {
            this.$message.error(error.meta.message);
            this.loading.reject = false;
          });
        }
      });

曾经的方式

switch (this.$route.params.status) {
                  case '10':
                    this.entrustTaskTaskTrack({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  case '11':
                    this.entrustTaskDelay({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  case '12':
                    this.entrustTaskApplyClose({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  case '13':
                    this.respDeptLeaderEntrustTask({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  case '14':
                    this.mgtDeptEntrustTask({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  case '15':
                    this.mgtDeptLeaderEntrustTask({
                      remarks,
                      entrustUsers: people.toString(),
                      nodeId: this.$route.params.nodeId,
                      requestId: this.$route.params.id,
                      taskId: this.$route.params.taskId,
                    }).then((req) => {
                      this.modal.visible = false;
                      this.$message.success(req.msg);
                      setTimeout(window.close, 2000);
                    }).catch((error) => {
                      this.$message.error(error.meta.message);
                    });
                    break;
                  default:
                }

代码质量显而易见的提升了(完)

由zhuishao

github:https://github.com/zhuishao/

发表评论

电子邮件地址不会被公开。 必填项已用*标注