Commit b6071009c009242ae9957b45ec113e92a771ad6f
1 parent
f51c6473
fix: 修改小程序选择TCP/UDP设备命令下发只支持json格式,不能直接下发命令请求(需加上字符串类型)
Showing
1 changed file
with
21 additions
and
7 deletions
@@ -126,8 +126,8 @@ | @@ -126,8 +126,8 @@ | ||
126 | </view> | 126 | </view> |
127 | <view style="margin-top: 28rpx;width: 100%;"> | 127 | <view style="margin-top: 28rpx;width: 100%;"> |
128 | <div class="u-flex u-row-between"> | 128 | <div class="u-flex u-row-between"> |
129 | - <u--textarea placeholder="请输入下发内容(json格式)" v-model="inputCommandVal" /> | ||
130 | - <u-icon @click="handleCopy(copyTextValue)" name="question-circle" color="#2979ff" size="28" | 129 | + <u--textarea :placeholder="`请输入下发内容${isShowTCP?'(字符串格式)':'(json格式)'}`" v-model="inputCommandVal" /> |
130 | + <u-icon v-if="!isShowTCP" @click="handleCopy(copyTextValue)" name="question-circle" color="#2979ff" size="28" | ||
131 | class="ml-10"> | 131 | class="ml-10"> |
132 | </u-icon> | 132 | </u-icon> |
133 | </div> | 133 | </div> |
@@ -187,7 +187,8 @@ | @@ -187,7 +187,8 @@ | ||
187 | showModel: false, | 187 | showModel: false, |
188 | commandType: 'OneWay', | 188 | commandType: 'OneWay', |
189 | commandValue: {}, | 189 | commandValue: {}, |
190 | - inputCommandVal: '' | 190 | + inputCommandVal: '', |
191 | + isShowTCP:false,//用于下发命令时判断是否是TCP/UDP | ||
191 | }; | 192 | }; |
192 | }, | 193 | }, |
193 | computed: { | 194 | computed: { |
@@ -257,11 +258,15 @@ | @@ -257,11 +258,15 @@ | ||
257 | }, | 258 | }, |
258 | showModal(e) { | 259 | showModal(e) { |
259 | this.modalName = e.currentTarget.dataset.target | 260 | this.modalName = e.currentTarget.dataset.target |
261 | + const {transportType} = this.deviceDetail.deviceProfile | ||
262 | + this.isShowTCP = transportType=='TCP'?true:false | ||
260 | this.showNodal = true | 263 | this.showNodal = true |
261 | }, | 264 | }, |
262 | showModalBtn() { | 265 | showModalBtn() { |
263 | this.showModel = true; | 266 | this.showModel = true; |
264 | this.inputCommandVal = ''; | 267 | this.inputCommandVal = ''; |
268 | + const {transportType} = this.deviceDetail.deviceProfile | ||
269 | + this.isShowTCP = transportType=='TCP'?true:false | ||
265 | }, | 270 | }, |
266 | disabledScroll() { | 271 | disabledScroll() { |
267 | return; | 272 | return; |
@@ -276,13 +281,22 @@ | @@ -276,13 +281,22 @@ | ||
276 | }, | 281 | }, |
277 | async confirmCommand() { | 282 | async confirmCommand() { |
278 | try { | 283 | try { |
279 | - const commandJsonValue = JSON.parse(this.inputCommandVal); | 284 | + this.commandValue.method = 'methodThingskit'; |
280 | this.commandValue.persistent = true; | 285 | this.commandValue.persistent = true; |
281 | this.commandValue.additionalInfo = { | 286 | this.commandValue.additionalInfo = { |
282 | cmdType: 'API' | 287 | cmdType: 'API' |
283 | }; | 288 | }; |
284 | - this.commandValue.method = 'methodThingskit'; | ||
285 | - this.commandValue.params = commandJsonValue | 289 | + if(this.isShowTCP){//TCP的格式只能是字符串 |
290 | + const zg = /^[0-9a-zA-Z]*$/ | ||
291 | + if(!zg.test(this.inputCommandVal)) { | ||
292 | + uni.$u.toast('输入的内容只能是字母和数字的组合') | ||
293 | + return | ||
294 | + } | ||
295 | + this.commandValue.params = this.inputCommandVal | ||
296 | + }else{ | ||
297 | + const commandJsonValue = JSON.parse(this.inputCommandVal); | ||
298 | + this.commandValue.params = commandJsonValue | ||
299 | + } | ||
286 | await issueCommand(this.commandType, this.deviceDetail.tbDeviceId, this.commandValue); | 300 | await issueCommand(this.commandType, this.deviceDetail.tbDeviceId, this.commandValue); |
287 | this.hiddenModal(); | 301 | this.hiddenModal(); |
288 | uni.$u.toast('下发成功~'); | 302 | uni.$u.toast('下发成功~'); |
@@ -395,4 +409,4 @@ | @@ -395,4 +409,4 @@ | ||
395 | width: 300rpx; | 409 | width: 300rpx; |
396 | } | 410 | } |
397 | } | 411 | } |
398 | -</style> | 412 | +</style> |