ApiLogForm.vue 5.98 KB
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.apiName')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiName">
              <a-input v-model="model.apiName" :placeholder="$t('api.inputApiName')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.apiMethod')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiMethod">
              <a-input v-model="model.apiMethod" :placeholder="$t('api.inputApiMethod')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.requestFrom')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="requestFrom" >
              <a-input v-model="model.requestFrom" :placeholder="$t('api.inputRequestFrom')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.ip')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ip">
              <a-input v-model="model.ip" :placeholder="$t('api.inputIp')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.url')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="url">
              <a-input v-model="model.url" :placeholder="$t('api.inputUrl')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.responseBy')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="responseBy">
              <a-input v-model="model.responseBy" :placeholder="$t('api.inputResponseBy')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.requestBody')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="requestBody">
              <a-input v-model="model.requestBody" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.responseBody')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="responseBody">
              <a-input v-model="model.responseBody" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.requestTime')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="requestTime">
              <j-date
                v-model="model.requestTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.responseTime')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="responseTime">
              <j-date
                v-model="model.responseTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.duration')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="duration">
              <a-input v-model="model.duration"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="httpCode" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="httpCode">
              <a-input-number v-model="model.httpCode" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('api.exception')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exception">
              <a-input v-model="model.exception"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'ApiLogForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/monitor/apiLog/add',
        edit: '/monitor/apiLog/edit',
        queryById: '/monitor/apiLog/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>