toApiInput()

in ui-vue3/src/views/traffic/dynamicConfig/model/ConfigModel.ts [317:400]


  toApiInput(check = false) {
    this.errorMsg = []
    let newVal = {
      ruleName:
        this.basicInfo.ruleName === '_tmp'
          ? this.basicInfo.key + '.configurators'
          : this.basicInfo.ruleName,
      scope: this.basicInfo.scope,
      key: this.basicInfo.key,
      enabled: this.basicInfo.enabled,
      configVersion: this.basicInfo.configVerison || 'v3.0',
      configs: this.config.map((x: configModel, idx: number) => {
        const match: any = {}
        const parameters: any = {}
        if (check) {
          if (x.parametersKeys.length === 0) {
            this.errorMsg.push(
              `配置 ${idx + 1}${i18n.global.t('dynamicConfigDomain.configType')} 不能为空`
            )
            loading.value = false
            throw new Error('数据检查失败')
          }
          if (
            !(
              x.checkArrConfig(
                `配置 ${idx + 1}${i18n.global.t('dynamicConfigDomain.matchType')} 检查失败`,
                x.matchesKeys,
                x.matchesValue,
                this.errorMsg
              ) &&
              x.checkArrConfig(
                `配置 ${idx + 1}${i18n.global.t('dynamicConfigDomain.configType')}  检查失败`,
                x.parametersKeys,
                x.parametersValue,
                this.errorMsg
              )
            )
          ) {
            throw new Error('数据检查失败')
          }
        }
        for (let key of x.matchesKeys) {
          let tmp = x.matchesValue[key]
          if (tmp.type === 'obj') {
            match[key] = { [tmp.relation]: tmp.value }
          } else if (tmp.type === 'arr') {
            match[key] = {
              oneof: tmp.arr.map((xx: any) => {
                return {
                  [xx.relation]: xx.value
                }
              })
            }
          } else {
            match[key] = []
            for (let arrElement of tmp.arr) {
              match[key].push({
                key: arrElement.key,
                value: { [arrElement.relation]: arrElement.value }
              })
            }
          }
        }
        for (let key of x.parametersKeys) {
          let tmp = x.parametersValue[key]
          if (tmp.type === 'obj') {
            parameters[key] = tmp.value
          } else {
            match[key] = {}
            for (let arrElement of tmp.arr) {
              parameters[arrElement.key] = arrElement.value
            }
          }
        }
        return {
          match,
          parameters,
          enabled: x.enabled,
          side: x.side
        }
      })
    }
    return newVal
  }