<template>
|
<a-modal :confirmLoading='confirmLoading' :maskClosable='false' :okButtonProps='{ props: {disabled: disableSubmit} }'
|
:title='title' :visible='visible'
|
:width='500' cancelText='关闭' @cancel='handleCancel' @ok='handleOk'>
|
<a-spin :spinning='confirmLoading'>
|
<a-form :form='form'>
|
<a-row :gutter='12'>
|
<a-col :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='参数名称'>
|
<a-input v-decorator="[ 'parameterName', validatorRules.parameterName]" :disabled='disableSubmit'
|
:maxLength='20' :readOnly='disableSubmit'
|
allow-clear placeholder='请输入参数名称' />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='12'>
|
<a-col :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='参数描述'>
|
<a-input v-decorator="[ 'parameterDescribe', validatorRules.parameterDescribe]" :disabled='disableSubmit'
|
:maxLength='20' :readOnly='disableSubmit'
|
allow-clear placeholder='请输入参数描述' />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<!-- 自定义参数,默认参数-->
|
<a-row :gutter='12'>
|
<a-col :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='参数类型'>
|
<a-radio-group v-model='radio' @change='onChange'>
|
<a-radio :value='false'>
|
默认参数
|
</a-radio>
|
<a-radio :value='true'>
|
自定义参数
|
</a-radio>
|
</a-radio-group>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='12'>
|
<a-col v-if='radio' :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='存储区域类型'>
|
<a-select v-model='customizeType' style='width: 287px' @change='customizeHandleChange'>
|
<a-select-option v-for='drive in customizeList' :key='drive.default1'>
|
{{ drive.name }}
|
</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<dev v-for='(item, index) in caseList' :key='index'>
|
<a-row :gutter='12'>
|
<a-col v-if='radio' :span='32'>
|
<a-form-item :label=item :labelCol='labelCol' :wrapperCol='wrapperCol'>
|
<!-- <a-input v-decorator="[`case_${index}`,{rules: [{ required: true, message: '请输入'}],'initialValue': item+index }]" />-->
|
<a-input v-decorator="[ `case_${index}`, {rules: [{ required: true, message: '请输入'}]}]"
|
:maxLength='20' :readOnly='disableSubmit' allow-clear @change='addressSplicing' />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
</dev>
|
<a-col v-if='disableBoole' :span='24'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='位地址'>
|
<a-input-number
|
v-decorator="['unaddressed',{rules: [{ required: true, message: '请输入位地址'}],'initialValue':this.model.unaddressed}]"
|
:max='200'
|
:min='1' @change='unaddressedSplicing' />
|
</a-form-item>
|
|
</a-col>
|
<a-row :gutter='12'>
|
<a-col :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='{xs: { span: 24 },sm: { span: 14 }}' label='参数地址'>
|
<a-input-search v-decorator="[ 'address', validatorRules.address]" :disabled='disableSubmit'
|
:maxLength='50'
|
:readOnly='disableSubmit' allow-clear
|
enter-button placeholder='请输入参数地址'
|
style='display: inline-block' @search='onSearch' />
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='12'>
|
<a-col v-if='disableDataLength' :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='数据类型'>
|
<a-select v-model='readWriteType' style='width: 287px' @change='handleChange'>
|
<a-select-option v-for='drive in readWriteTypeList' :key='drive.default1'>
|
{{ drive.default1 }}
|
</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-col>
|
<a-col v-else :span='32'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='数据类型'>
|
<a-select v-model='readWriteType' style='width: 287px' @change='handleChange'>
|
<a-select-option v-for='drive in readWriteTypeList' :key='drive.default1'>
|
{{ drive.default1 }}
|
</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-col>
|
</a-row>
|
<a-row :gutter='12'>
|
<a-col :span='24'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='读写类型'>
|
<a-select v-model='parameterType' style='width: 287px'>
|
<a-select-option v-for='drive in parameterTypeList' :key='drive.key'>
|
{{ drive.key }}
|
</a-select-option>
|
</a-select>
|
</a-form-item>
|
</a-col>
|
<a-col v-if='disableDataLength' :span='24'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='字符串长度'>
|
<a-input-number
|
v-decorator="['dataLength',{rules: [{ required: true, message: '请输入字符串长度'}],'initialValue':this.model.dataLength}]"
|
:max='200'
|
:min='1' />
|
</a-form-item>
|
|
</a-col>
|
<a-col v-if='disableFloatScale' :span='24'>
|
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='缩放倍率'>
|
<a-input-number
|
v-decorator="['floatScale',{rules: [{ required: true, message: '请输入缩放倍率'}],'initialValue':this.model.floatScale}]"
|
:min='1' />
|
</a-form-item>
|
|
</a-col>
|
</a-row>
|
</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>
|
<parameter-address ref='modalAddress' :server-id='serverId' @ok='modalFormOk' />
|
|
</a-modal>
|
</template>
|
|
<script>
|
import pick from 'lodash.pick'
|
import { getAction, httpAction } from '@/api/manage'
|
import ParameterAddress from './ParameterAddress'
|
|
export default {
|
components: { ParameterAddress },
|
props: [
|
'serverId'
|
],
|
name: 'SolidParameterModel',
|
data() {
|
return {
|
caseList: [],
|
customizeType: '',
|
customizeList: [], // 自定义参数
|
radio: false,
|
dataLength: 1,
|
indexStyle: false,
|
readWriteType: '',
|
parameterType: '只读',
|
title: '',
|
visible: false,
|
model: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 7 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 14 }
|
},
|
confirmLoading: false,
|
form: this.$form.createForm(this),
|
readWriteTypeList: [],
|
parameterTypeList: [
|
{ key: '只读' },
|
{ key: '读写' }
|
],
|
validatorRules: {
|
parameterType: {
|
rules: [{
|
required: true,
|
message: '请选择读写类型'
|
}]
|
},
|
readWriteType: {
|
rules: [{
|
required: true,
|
message: '请输入数据类型'
|
}]
|
},
|
parameterName: {
|
rules: [{
|
required: true,
|
message: '此输入框仅允许输入数字和字母',
|
pattern: /^[a-zA-Z0-9]+$/
|
}]
|
},
|
parameterDescribe: {
|
rules: [{
|
message: '此输入框仅允许输入中文和字母',
|
pattern: /^[a-zA-Z\u4e00-\u9fa50-9]+$/
|
}]
|
},
|
dataLength: {
|
rules: [{
|
required: true,
|
message: '请输入字符串长度'
|
}]
|
},
|
parameterCode: {
|
rules: [{
|
required: true,
|
message: '请输入参数组编号'
|
}]
|
},
|
address: {
|
rules: [{
|
required: true,
|
message: '请输入数据地址'
|
}]
|
}
|
},
|
url: {
|
add: '/real/parameter/add',
|
edit: '/real/parameter/edit',
|
dataType: '/equipment/queryDataType',
|
customize: '/equipment/customize/queryParameter',
|
parameterId: '/parameter/group/queryById'
|
},
|
disableSubmit: false,
|
disableBoole: false,
|
disableDataLength: false,
|
disableFloatScale: false
|
}
|
},
|
|
methods: {
|
unaddressedSplicing() {
|
let address = this.customizeType
|
this.customizeList.forEach(u => {
|
if (u.default1 == this.customizeType) {
|
address = u.default1
|
}
|
})
|
const mArray = address.split('.')
|
const formData = this.form.getFieldsValue()
|
// 回显填写过的数据
|
for (let j = 0; j < this.caseList.length; j++) {
|
let case1 = `case_${j}`
|
if (formData[case1] !== undefined) {
|
mArray[j + 1] = formData[case1]
|
}
|
}
|
// 使用 join 方法将数组元素用 . 连接成字符串
|
address = mArray.join('.')
|
if (this.readWriteType === 'Bool') {
|
if (formData.unaddressed === undefined) {
|
address = address + '.1'
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
unaddressed: 1
|
})
|
})
|
} else {
|
address = address + '.' + formData.unaddressed
|
}
|
|
}
|
// 赋值
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
address: address
|
})
|
})
|
},
|
addressSplicing(value) {
|
let address = this.customizeType
|
this.customizeList.forEach(u => {
|
if (u.default1 == this.customizeType) {
|
address = u.default1
|
}
|
})
|
const mArray = address.includes('.') ? [address] : address.split('.')
|
const formData = this.form.getFieldsValue()
|
// 处理刚填写的数据
|
for (let j = 0; j < this.caseList.length; j++) {
|
if (value.currentTarget.id === `case_${j}`) {
|
let case1 = `case_${j}`
|
formData[case1] = value.currentTarget.value
|
}
|
}
|
// 回显填写过的数据
|
for (let j = 0; j < this.caseList.length; j++) {
|
let case1 = `case_${j}`
|
if (formData[case1] !== undefined) {
|
mArray[j + 1] = formData[case1]
|
}
|
}
|
// 使用 join 方法将数组元素用 . 连接成字符串
|
address = mArray.join('.')
|
if (this.readWriteType === 'Bool') {
|
address = address + '.' + formData.unaddressed
|
}
|
// 赋值
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
address: address
|
})
|
})
|
},
|
onChange(e) {
|
if (this.radio) {
|
getAction(this.url.customize, { id: this.serverId }).then((res) => {
|
if (res.success) {
|
this.customizeList = res.result
|
if (this.customizeList.length > 0) {
|
this.customizeType = this.customizeList[0].default1
|
// 查看有几个✳
|
const matches = this.customizeList[0].default1.split('*').length - 1
|
// 分隔名称
|
this.caseList = this.customizeList[0].case1.split(':')
|
// 参数地址
|
// this.modal.address = this.customizeType
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
address: this.customizeList[0].default1
|
})
|
})
|
|
}
|
}
|
if (res.code === 510) {
|
this.$message.warning(res.message)
|
}
|
})
|
if (this.readWriteType === 'Bool' && this.radio === true) {
|
this.model.unaddressed = 1
|
this.disableBoole = true
|
}
|
} else {
|
this.disableBoole = false
|
}
|
|
},
|
onSearch() {
|
// if (!this.disableDataLength)
|
this.$refs.modalAddress.visible1 = true
|
},
|
// 切换存储区域类型
|
customizeHandleChange(value) {
|
for (let i = 0; i < this.caseList.length; i++) {
|
this.$nextTick(() => {
|
let case1 = `case_${i}`
|
this.form.setFieldsValue({
|
[case1]: undefined
|
})
|
})
|
}
|
this.customizeList.forEach(c => {
|
if (c.default1 === value) {
|
this.caseList = c.case1.split(':')
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
address: c.default1
|
})
|
})
|
}
|
})
|
},
|
handleChange() {
|
if (this.readWriteType === 'Float16(x)' || this.readWriteType === 'Float32(x)') {
|
this.disableFloatScale = true
|
} else {
|
this.disableFloatScale = false
|
}
|
if (this.readWriteType === 'String') {
|
this.disableDataLength = true
|
} else {
|
this.disableDataLength = false
|
}
|
if (this.radio) {
|
this.unaddressedSplicing()
|
if (this.readWriteType === 'Bool') {
|
this.disableBoole = true
|
} else {
|
this.disableBoole = false
|
}
|
}
|
|
},
|
add() {
|
// this.
|
this.edit({})
|
this.model.dataLength = 1
|
},
|
modalFormOk(record) {
|
let model = Object.assign({}, record)
|
this.$nextTick(() => {
|
this.form.setFieldsValue({
|
parameterDescribe: model.describe,
|
address: model.default1,
|
parameterName: model.default1
|
})
|
})
|
this.readWriteType = model.dataType
|
if (this.readWriteType === 'String') {
|
this.disableDataLength = true
|
} else {
|
this.disableDataLength = false
|
}
|
},
|
edit(record) {
|
this.disableDataLength = false
|
// 查询系统类型
|
getAction(this.url.dataType, { id: this.serverId }).then((res) => {
|
if (res.success) {
|
this.readWriteTypeList = res.result
|
if (!this.model.id) {
|
this.readWriteType = this.readWriteTypeList[0].default1
|
}
|
}
|
})
|
// 查询设备信息
|
getAction(this.url.parameterId, { id: this.serverId }).then((res) => {
|
if (res.success) {
|
if (res.result.eqptType === 'PLC' && this.readWriteType === 'String') {
|
this.disableDataLength = true
|
}
|
}
|
})
|
this.form.resetFields()
|
this.model = Object.assign({}, record)
|
this.model.dataLength = 1
|
this.visible = true
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'parameterCode', 'parameterName', 'parameterDescribe', 'address', 'dataLength'))
|
})
|
this.dataLength = this.model.dataLength
|
this.readWriteType = this.model.parameterType
|
if (this.readWriteType === 'String') {
|
this.disableDataLength = true
|
} else {
|
this.disableDataLength = false
|
}
|
},
|
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.readWriteTypeList.length > 0) {
|
this.readWriteTypeList.forEach(r => {
|
if (r.default1 === this.readWriteType) {
|
formData.systemDataType = r.systemDataType
|
}
|
})
|
}
|
formData.parameterType = this.readWriteType
|
formData.readWriteType = this.parameterType
|
if (this.readWriteType !== 'String') {
|
formData.dataLength = 1
|
}
|
if (this.readWriteType === 'Float16(x)' || this.readWriteType === 'Float32(x)') {
|
formData.parameterType = this.readWriteType.slice(0,8)+formData.floatScale+')';
|
}
|
if (!this.model.id) {
|
formData.parameterGroupId = this.serverId
|
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)
|
that.close()
|
} else {
|
that.$message.warning(res.message)
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
})
|
}
|
})
|
},
|
handleCancel() {
|
this.close()
|
}
|
}
|
}
|
</script>
|