<template>
|
<a-modal title='influxdb配置' :width='600' :visible='visible' :maskClosable='false' :confirmLoading='confirmLoading'
|
:okButtonProps='{ props: {disabled: disableSubmit} }' @ok='handleOk' @cancel='handleCancel' cancelText='关闭'>
|
<a-spin :spinning='confirmLoading'>
|
<a-form :form='form'>
|
<a-row :gutter='24'>
|
<a-col :span='12'>
|
<a-form-item label='地址' :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<a-input :disabled='disableSubmit' :readOnly='disableSubmit' placeholder='请输入地址' allow-clear
|
:maxLength='20' v-decorator="[ 'address', validatorRules.address]" />
|
</a-form-item>
|
</a-col>
|
<a-col :span='12'>
|
<a-form-item label='桶' :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<a-input :disabled='disableSubmit' :readOnly='disableSubmit' placeholder='请输入桶' allow-clear
|
:maxLength='15' v-decorator="['bucket', validatorRules.bucket]" />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='24'>
|
<a-col :span='12'>
|
<a-form-item label='组织' :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<a-input :disabled='disableSubmit' :readOnly='disableSubmit' placeholder='请输组织' allow-clear
|
:maxLength='20' v-decorator="[ 'organization', validatorRules.organization]" />
|
</a-form-item>
|
</a-col>
|
<a-col :span='12'>
|
<a-form-item label='端口' :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<a-input :disabled='disableSubmit' :readOnly='disableSubmit' placeholder='请输入端口' allow-clear
|
:maxLength='6' v-decorator="[ 'port', validatorRules.port]" />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='24'>
|
<a-col :span='12'>
|
<a-form-item label='授权码' :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<a-textarea :disabled='disableSubmit' :readOnly='disableSubmit' placeholder='请输入授权码' allow-clear
|
v-decorator="[ 'authorizeCode', validatorRules.authorizeCode]" />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
</a-form>
|
</a-spin>
|
<template slot='footer'>
|
<a-button :style="{ marginRight: '8px' }" @click='handleCancel'>关闭</a-button>
|
<a-button @click='handleOk' type='primary'>确定</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: 7 },
|
},
|
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>
|