Javascript——循环调接口

需求:同一个接口每个输入框的code传参数不一样,填一个接口成功后循环♻️调接口

Javascript——循环调接口_第1张图片

 <div class="inching-box-radio-btn">
                        <!-- 启动 -->
                        <el-button
                          :disabled="noSecValue === true"
                          class="inching-btn inching-open"
                          @click="sectionClick(1)"
                          :value="firstOpenValue"
                          :class="
                            firstColorActive
                              ? firstColorActive === true
                                ? 'isColorActive'
                                : ''
                              : ''
                          "
                          >启动</el-button
                        >

                        <el-button
                          :disabled="noSecValue === true"
                          class="inching-btn"
                          @click="sectionClick(2)"
                          :value="firstCloseValue"
                          >关闭</el-button
                        >
                      </div>
                    </div>
                    <div class="inching-ipt inching-ipt-wap">
                      <div class="section-box-flex">
                        <div class="section-box">
                          <el-input
                            class="inching-text"
                            placeholder=""
                            v-model="firstValue"
                            :disabled="optValue === false || noSecValue === true"
                            @input="firstValueIpt"
                          >value1</el-input>
                        </div>
                        <div class="section-box">
                          <el-input
                            class="inching-text"
                            placeholder=""
                            v-model="secondValue"
                            :disabled="optValue === false || noSecValue === true"
                            @input="secondValueIpt"
                          >value2</el-input>
                        </div>
                      </div>
                      <div class="section-box-flex">
                        <div class="section-box box">
                          <el-input
                            class="inching-text"
                            placeholder=""
                            v-model="threeValue"
                            :disabled="optValue === false || noSecValue === true"
                            @input="threeValueIpt"
                          >value3 </el-input>
                        </div>

                        <div class="section-box box">
                          <el-input
                            class="inching-text"
                            placeholder=""
                            v-model.number="fourValue"
                            :disabled="optValue === false || noSecValue === true"
                            @input="fourValueIpt"
                          >value4 </el-input>
                        </div>
                      </div>
                    </div>
 //区间控制
    sectionClick(value) {
        if (value === 1) {//点击启动
          this.getSectioList('first');//循环接口
          this.secBtnValue = 1;
          this.sectionClickBtn = true;
        } else if (value === 2) {
          //关闭
          this.secBtnValue = 0;
          this.getSectioList('first');//循环接口
          this.secCloseClickBtn = true;
        }
    },

//循环♻️写值的接口
    getSectioList(item1) {
      let value = '';
      let functionCode = '';
      let secondShow = '';//定义一个变量控制调几次
      if (item1 === 'first') {
        value = this.firstValue;
        functionCode = this.openAreaCode; //74
        secondShow = 0;
      } else if (item1 === 'second') {
        value = this.secondValue;
        functionCode = this.speedAreaCode; //76
        secondShow = 1;
      } else if (item1 === 'three') {
        value = this.threeValue;
        functionCode = this.sunAreaCode; //75
        secondShow = 2;
      } else if (item1 === 'four') {
        value = this.fourValue; //77
        functionCode = this.sunSpeedAreaCode;
        secondShow = 3;
      } else if (item1 === 'btnStart') {
        secondShow = '';
        return;
      }
      let params = {
        slaveId: this.slaveIdCopy,
        valueDTO: [
          {
            functionCode: functionCode,//传参functionCode每一个输入框都不一样
            value: Number(value)
          }
        ]
      };
      writeInfo(params).then(res => {
        if (res.code === 200) {
          this.$message.success('操作成功');
          if (secondShow === 0) {
            this.getSectioList('second');
          } else if (secondShow === 1) {
            this.getSectioList('three');
          } else if (secondShow === 2) {
            this.getSectioList('four');
          } else if (secondShow === 3) {
            this.getSectioList('btnStart');
        
          }
        }
      });
    },

你可能感兴趣的:(javascript,前端)