<template>
|
<a-modal :confirmLoading='confirmLoading' :maskClosable='false' :okButtonProps='{ props: {disabled: disableSubmit} }'
|
:visible='visible' :width='600'
|
cancelText='关闭' title='influxdb配置' @cancel='handleCancel' @ok='handleOk'>
|
<a-spin :spinning='confirmLoading'>
|
<a-form :form='form'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='地址'>
|
<a-input v-decorator="[ 'address', validatorRules.address]" :disabled='disableSubmit' :maxLength='20'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入地址' />
|
</a-form-item>
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='桶'>
|
<a-input v-decorator="['bucket', validatorRules.bucket]" :disabled='disableSubmit' :maxLength='15'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入桶' />
|
</a-form-item>
|
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='组织'>
|
<a-input v-decorator="[ 'organization', validatorRules.organization]" :disabled='disableSubmit'
|
:maxLength='20' :readOnly='disableSubmit'
|
allow-clear placeholder='请输组织' />
|
</a-form-item>
|
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='端口'>
|
<a-input v-decorator="[ 'port', validatorRules.port]" :disabled='disableSubmit' :maxLength='6'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入端口' />
|
</a-form-item>
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='授权码'>
|
<a-textarea v-decorator="[ 'authorizeCode', validatorRules.authorizeCode]" :disabled='disableSubmit'
|
:readOnly='disableSubmit' allow-clear
|
placeholder='请输入授权码' />
|
</a-form-item>
|
|
</a-form>
|
</a-spin>
|
<template slot='footer'>
|
<a-button :style="{ marginRight: '8px' }" @click='handleCancel'>关闭</a-button>
|
<a-button type='primary' @click='handleOk'>确定</a-button>
|
</template>
|
</a-modal>
|
</template>
|
|
<script>
|
import pick from 'lodash.pick'
|
import { httpAction } from '@/api/manage'
|
|
export default {
|
name: 'InfluxModel',
|
data() {
|
return {
|
visible: false,
|
model: {},
|
serverDeploy: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
authorizeCode: {
|
rules: [{
|
required: true,
|
message: '请输入授权码'
|
},
|
{
|
min: 0,
|
max: 100,
|
message: '长度不超过 100 个字符',
|
trigger: 'blur'
|
}
|
]
|
},
|
bucket: {
|
rules: [{
|
required: true,
|
message: '请输入桶'
|
},
|
{
|
min: 0,
|
max: 30,
|
message: '长度不超过 30 个字符',
|
trigger: 'blur'
|
}
|
]
|
},
|
organization: {
|
rules: [{
|
required: true,
|
message: '请输入组织'
|
}]
|
},
|
port: {
|
rules: [{
|
required: true,
|
message: '请输入端口'
|
}
|
]
|
},
|
address: {
|
rules: [{
|
required: true,
|
message: '请输入地址'
|
}
|
]
|
},
|
password: {
|
rules: [{
|
required: true,
|
message: '请输入密码'
|
}
|
]
|
}
|
},
|
url: {
|
add: '/serve/deploy/add/influxdb',
|
edit: '/serve/deploy/edit/influxdb'
|
},
|
disableSubmit: false
|
}
|
},
|
|
methods: {
|
add() {
|
this.edit({})
|
},
|
edit(record) {
|
this.form.resetFields()
|
this.serverDeploy = Object.assign({}, record)
|
this.model = Object.assign({}, this.serverDeploy.influxdbDeploy)
|
this.visible = true
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'authorizeCode', 'bucket', 'organization', 'port', 'address', 'password'))
|
})
|
},
|
close() {
|
this.$emit('close')
|
this.visible = false
|
},
|
handleOk() {
|
const that = this
|
// 触发表单验证
|
this.form.validateFields((err, values) => {
|
if (!err) {
|
that.confirmLoading = true
|
let formData = Object.assign(this.model, values)
|
let obj
|
if (!this.model.id) {
|
formData.projectClassifyId = this.serverDeploy.projectClassifyId
|
formData.serverDeployId = this.serverDeploy.id
|
obj = httpAction(this.url.add, formData, 'post')
|
} else {
|
obj = httpAction(this.url.edit, formData, 'put')
|
}
|
obj.then((res) => {
|
if (res.success) {
|
that.$message.success(res.message)
|
that.$emit('ok', res.result)
|
} else {
|
that.$message.warning(res.message)
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
that.close()
|
})
|
}
|
})
|
},
|
handleCancel() {
|
this.close()
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
/** 主表单行间距 */
|
.ant-form .ant-form-item {
|
margin-bottom: 10px;
|
}
|
|
/** Tab页面行间距 */
|
.ant-tabs-content .ant-form-item {
|
margin-bottom: 0px;
|
}
|
</style>
|