提交 | 用户 | 时间
|
850106
|
1 |
<template> |
H |
2 |
<el-dialog |
|
3 |
:title="!dataForm.id ? '新增' : '修改'" |
|
4 |
:close-on-click-modal="false" |
|
5 |
:visible.sync="visible" |
|
6 |
append-to-body |
|
7 |
> |
|
8 |
<el-form |
|
9 |
:model="dataForm" |
|
10 |
:rules="dataRule" |
|
11 |
ref="dataForm" |
|
12 |
@keyup.enter.native="dataFormSubmit()" |
|
13 |
label-width="120px" |
|
14 |
> |
|
15 |
<el-row :gutter="20"> |
|
16 |
<el-col :span="12"> |
|
17 |
<el-form-item label="设备名称" prop="name"> |
|
18 |
<el-input v-model="dataForm.name" placeholder="设备名称"></el-input> |
|
19 |
</el-form-item> |
|
20 |
</el-col> |
|
21 |
<el-col :span="12"> |
|
22 |
<el-form-item label="IP地址" prop="address"> |
|
23 |
<el-input |
|
24 |
v-model="dataForm.address" |
|
25 |
placeholder="IP地址" |
|
26 |
></el-input> |
|
27 |
</el-form-item> |
|
28 |
</el-col> |
|
29 |
</el-row> |
|
30 |
<el-row :gutter="20"> |
|
31 |
<el-col :span="12"> |
|
32 |
<el-form-item label="端口" prop="port"> |
|
33 |
<el-input-number |
|
34 |
:min=0 |
|
35 |
:max="100000" |
|
36 |
v-model="dataForm.port" |
|
37 |
placeholder="端口" |
|
38 |
dictCode="clock-type" |
|
39 |
/> |
|
40 |
</el-form-item> |
|
41 |
</el-col> |
|
42 |
<el-col :span="12"> |
|
43 |
<el-form-item label="不活动超时(ms)" prop="connectInactivityTimeout"> |
|
44 |
<el-input-number |
|
45 |
:min=0 |
|
46 |
:max="1000000" |
|
47 |
v-model="dataForm.connectInactivityTimeout" |
|
48 |
placeholder="不活动超时(ms)" |
|
49 |
dictCode="enable" |
|
50 |
/> |
|
51 |
</el-form-item> |
|
52 |
</el-col> |
|
53 |
</el-row> |
|
54 |
<el-row :gutter="20"> |
|
55 |
<el-col :span="12"> |
|
56 |
<el-form-item label="重连超时(ms)" prop="reconnectInterval"> |
|
57 |
<el-input-number |
|
58 |
:min=0 |
|
59 |
:max="100000" |
|
60 |
v-model="dataForm.reconnectInterval" |
|
61 |
placeholder="重连超时(ms)" |
|
62 |
></el-input-number > |
|
63 |
</el-form-item> |
|
64 |
</el-col> |
|
65 |
<el-col :span="12"> |
|
66 |
<el-form-item label="重试次数" prop="attemptsBeforeTimeout"> |
|
67 |
<el-input-number |
|
68 |
:min=0 |
|
69 |
:max="100" |
|
70 |
v-model="dataForm.attemptsBeforeTimeout" |
|
71 |
placeholder="重试次数" |
|
72 |
></el-input-number > |
|
73 |
</el-form-item> |
|
74 |
</el-col> |
|
75 |
</el-row> |
|
76 |
<el-row :gutter="20"> |
|
77 |
<el-col :span="12"> |
|
78 |
<el-form-item label="重试间隔(ms)" prop="waitToRetryMilliseconds"> |
|
79 |
<el-input-number |
|
80 |
:min=0 |
|
81 |
:max="100000" |
|
82 |
v-model="dataForm.waitToRetryMilliseconds" |
|
83 |
placeholder="重试间隔(ms)" |
|
84 |
></el-input-number > |
|
85 |
</el-form-item> |
|
86 |
</el-col> |
|
87 |
|
|
88 |
<el-col :span="12"> |
|
89 |
<el-form-item label="读超时(ms)" prop="readTimeout"> |
|
90 |
<el-input-number |
|
91 |
:min=0 |
|
92 |
:max="100000" |
|
93 |
v-model="dataForm.readTimeout" |
|
94 |
placeholder="读超时(ms)" |
|
95 |
></el-input-number > |
|
96 |
</el-form-item> |
|
97 |
</el-col> |
|
98 |
</el-row> |
|
99 |
<el-row :gutter="20"> |
|
100 |
<el-col :span="12"> |
|
101 |
<el-form-item label="写超时(ms)" prop="writeTimeout"> |
|
102 |
<el-input-number |
|
103 |
:min=0 |
|
104 |
:max="100000" |
|
105 |
v-model="dataForm.writeTimeout" |
|
106 |
placeholder="写超时(ms)" |
|
107 |
></el-input-number > |
|
108 |
</el-form-item> |
|
109 |
</el-col> |
|
110 |
|
|
111 |
<el-col :span="12"> |
|
112 |
<el-form-item label="是否使用优化" prop="useOptimizedBlockRead"> |
|
113 |
<dict-select-tag |
|
114 |
v-model="dataForm.useOptimizedBlockRead" |
|
115 |
placeholder="是否使用优化" |
|
116 |
dictCode="oadp-sf" |
|
117 |
/> |
|
118 |
</el-form-item> |
|
119 |
</el-col> |
|
120 |
</el-row> |
|
121 |
</el-form> |
|
122 |
<span slot="footer" class="dialog-footer"> |
|
123 |
<el-button @click="visible = false">取消</el-button> |
|
124 |
<el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button> |
|
125 |
</span> |
|
126 |
</el-dialog> |
|
127 |
</template> |
|
128 |
|
|
129 |
<script> |
|
130 |
import DictSelectTag from "@/components/dict/dict-select-tag"; |
|
131 |
export default { |
|
132 |
components: { |
|
133 |
DictSelectTag, |
|
134 |
}, |
|
135 |
data() { |
|
136 |
return { |
|
137 |
loading: false, |
|
138 |
visible: false, |
|
139 |
dataForm: { |
|
140 |
name: "", |
|
141 |
address: "", |
|
142 |
port: "", |
|
143 |
connectInactivityTimeout: "", |
|
144 |
reconnectInterval: "5000", |
|
145 |
attemptsBeforeTimeout: "3", |
|
146 |
waitToRetryMilliseconds: "250", |
|
147 |
readTimeout: "3000", |
|
148 |
writeTimeout: "3000", |
|
149 |
useOptimizedBlockRead: "true", |
|
150 |
}, |
|
151 |
dataRule: { |
|
152 |
name: [ |
|
153 |
{ required: true, message: "设备名称不能为空", trigger: "blur" }, |
|
154 |
], |
|
155 |
address: [ |
|
156 |
{ required: true, message: "IP地址不能为空", trigger: "blur" }, |
|
157 |
], |
|
158 |
port: [{ required: true, message: "端口号不能为空", trigger: "blur" }], |
|
159 |
connectInactivityTimeout: [ |
|
160 |
{ required: true, message: "不活动超时不能为空", trigger: "blur" }, |
|
161 |
], |
|
162 |
reconnectInterval: [ |
|
163 |
{ required: true, message: "重连超时不能为空", trigger: "blur" }, |
|
164 |
], |
|
165 |
attemptsBeforeTimeout: [ |
|
166 |
{ required: true, message: "重试次数不能为空", trigger: "blur" }, |
|
167 |
], |
|
168 |
waitToRetryMilliseconds: [ |
|
169 |
{ required: true, message: "重试间隔不能为空", trigger: "blur" }, |
|
170 |
], |
|
171 |
readTimeout: [ |
|
172 |
{ required: true, message: "读超时不能为空", trigger: "blur" }, |
|
173 |
], |
|
174 |
writeTimeout: [ |
|
175 |
{ required: true, message: "写超时不能为空", trigger: "blur" }, |
|
176 |
], |
|
177 |
useOptimizedBlockRead: [ |
|
178 |
{ required: true, message: "是否使用优化不能为空", trigger: "blur" }, |
|
179 |
], |
|
180 |
}, |
|
181 |
}; |
|
182 |
}, |
|
183 |
methods: { |
|
184 |
init(id) { |
|
185 |
this.dataForm.id = id || 0; |
|
186 |
this.visible = true; |
|
187 |
this.$nextTick(() => { |
|
188 |
this.$refs["dataForm"].resetFields(); |
|
189 |
if (this.dataForm.id) { |
|
190 |
this.$http({ |
|
191 |
url: `/data/channel/modbus/device/info/${this.dataForm.id}`, |
|
192 |
method: "get", |
|
193 |
params: this.$http.adornParams(), |
|
194 |
}).then(({ code, data }) => { |
|
195 |
if (data && code === 0) { |
|
196 |
this.dataForm.name = data.name; |
|
197 |
this.dataForm.address = data.address; |
|
198 |
this.dataForm.port = data.port; |
|
199 |
this.dataForm.connectInactivityTimeout = |
|
200 |
data.connectInactivityTimeout; |
|
201 |
this.dataForm.reconnectInterval = data.reconnectInterval; |
|
202 |
this.dataForm.attemptsBeforeTimeout = |
|
203 |
data.attemptsBeforeTimeout; |
|
204 |
this.dataForm.waitToRetryMilliseconds = |
|
205 |
data.waitToRetryMilliseconds; |
|
206 |
this.dataForm.readTimeout = data.readTimeout; |
|
207 |
this.dataForm.writeTimeout = data.writeTimeout; |
|
208 |
this.dataForm.useOptimizedBlockRead = |
|
209 |
data.useOptimizedBlockRead; |
|
210 |
} |
|
211 |
}); |
|
212 |
} |
|
213 |
}); |
|
214 |
}, |
|
215 |
// 表单提交 |
|
216 |
dataFormSubmit() { |
|
217 |
this.$refs["dataForm"].validate((valid) => { |
|
218 |
if (valid) { |
|
219 |
this.loading = true; |
|
220 |
this.$http({ |
|
221 |
headers: { |
|
222 |
"Content-Type": "application/json", |
|
223 |
}, |
|
224 |
url: `/data/channel/modbus/device/${ |
|
225 |
!this.dataForm.id ? "add" : "update" |
|
226 |
}`, |
|
227 |
method: "post", |
|
228 |
data: this.$http.adornData({ |
|
229 |
id: this.dataForm.id || undefined, |
|
230 |
name: this.dataForm.name, |
|
231 |
address: this.dataForm.address, |
|
232 |
port: this.dataForm.port, |
|
233 |
connectInactivityTimeout: this.dataForm.connectInactivityTimeout, |
|
234 |
reconnectInterval: this.dataForm.reconnectInterval, |
|
235 |
attemptsBeforeTimeout: this.dataForm.attemptsBeforeTimeout, |
|
236 |
waitToRetryMilliseconds: this.dataForm.waitToRetryMilliseconds, |
|
237 |
readTimeout: this.dataForm.readTimeout, |
|
238 |
writeTimeout: this.dataForm.writeTimeout, |
|
239 |
useOptimizedBlockRead: this.dataForm.useOptimizedBlockRead, |
|
240 |
}), |
|
241 |
}).then(({ code, msg }) => { |
|
242 |
if (code === 0) { |
|
243 |
this.$message({ |
|
244 |
message: "操作成功", |
|
245 |
type: "success", |
|
246 |
duration: 1500, |
|
247 |
onClose: () => { |
|
248 |
this.$emit("refreshDataList"); |
|
249 |
this.visible = false; |
|
250 |
}, |
|
251 |
}) |
|
252 |
this.loading = false; |
|
253 |
} else { |
|
254 |
this.$message.error(msg); |
|
255 |
} |
|
256 |
}); |
|
257 |
} |
|
258 |
}); |
|
259 |
}, |
|
260 |
}, |
|
261 |
}; |
|
262 |
</script> |
|
263 |
<style> |
|
264 |
.el-select { |
|
265 |
width: 100%; |
|
266 |
} |
|
267 |
.el-input-group__append { |
|
268 |
padding: 0 5px 0 5px; |
|
269 |
} |
|
270 |
.el-input-group__prepend { |
|
271 |
padding: 0 5px 0 5px; |
|
272 |
} |
|
273 |
</style> |