<template>
|
<a-modal :confirmLoading='confirmLoading' :maskClosable='false' :okButtonProps='{ props: {disabled: disableSubmit} }'
|
:visible='visible' :width='600'
|
cancelText='关闭' title='MQTT配置' @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='15'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入服务端地址' />
|
</a-form-item>
|
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='客户端ID'>
|
<a-input v-decorator="[ 'clintId', validatorRules.clintId]" :disabled='disableSubmit' :maxLength='20'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入客户端ID' />
|
</a-form-item>
|
|
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='端口'>
|
<a-input v-decorator="['port', validatorRules.port]" :disabled='disableSubmit' :readOnly='disableSubmit'
|
allow-clear
|
placeholder='请输入端口' />
|
</a-form-item>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='用户名'>
|
<a-input v-decorator="[ 'userName', validatorRules.userName]" :disabled='disableSubmit' :maxLength='6'
|
:readOnly='disableSubmit'
|
allow-clear placeholder='请输入用户名' />
|
</a-form-item>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='密码'>
|
<a-input v-decorator="['userPassword', validatorRules.userPassword]" :disabled='disableSubmit'
|
:readOnly='disableSubmit' allow-clear
|
placeholder='请输入密码' />
|
</a-form-item>
|
|
</a-form>
|
</a-spin>
|
<template v-if='disableSubmit == false' 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'
|
|
let validatorCodeTimer = null
|
|
export default {
|
name: 'MqttModel',
|
data() {
|
return {
|
visible: false,
|
model: {},
|
serverDeploy: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 7 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 14 }
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
address: {
|
rules: [{
|
required: true,
|
message: '请输入服务端地址'
|
}]
|
},
|
clintId: {
|
rules: [{
|
required: true,
|
message: '请输入客户端ID'
|
}]
|
},
|
port: {
|
rules: [{
|
required: true,
|
message: '请输入端口'
|
}]
|
},
|
userName: {
|
rules: [{
|
required: true,
|
message: '请输入用户名'
|
}]
|
},
|
userPassword: {
|
rules: [{
|
required: true,
|
message: '请输入密码'
|
}]
|
}
|
|
},
|
url: {
|
add: '/serve/deploy/add/mqtt',
|
edit: '/serve/deploy/edit/mqtt'
|
},
|
disableSubmit: false
|
}
|
},
|
|
methods: {
|
add() {
|
this.edit({})
|
},
|
edit(record) {
|
this.form.resetFields()
|
this.serverDeploy = Object.assign({}, record)
|
this.model = Object.assign({}, this.serverDeploy.mqttDeploy)
|
this.visible = true
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'serverName', 'address', 'clintId', 'port', 'userName', 'userPassword'))
|
})
|
},
|
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-btn {
|
padding: 0 10px;
|
margin-left: 3px;
|
}
|
|
.ant-form-item-control {
|
line-height: 0px;
|
}
|
|
/** 主表单行间距 */
|
.ant-form .ant-form-item {
|
margin-bottom: 10px;
|
}
|
|
/** Tab页面行间距 */
|
.ant-tabs-content .ant-form-item {
|
margin-bottom: 0px;
|
}
|
</style>
|