Commit 62a3bd84b05d044e1ddb7dd02cdae5dd3c449bfc
Merge branch 'fix/DEFECT-1440' into 'main_dev'
fix: 修改小程序选择TCP/UDP设备命令下发只支持json格式,不能直接下发命令请求(需加上字符串类型) See merge request yunteng/thingskit-app!113
Showing
1 changed file
with
21 additions
and
7 deletions
| ... | ... | @@ -126,8 +126,8 @@ |
| 126 | 126 | </view> |
| 127 | 127 | <view style="margin-top: 28rpx;width: 100%;"> |
| 128 | 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 | 131 | class="ml-10"> |
| 132 | 132 | </u-icon> |
| 133 | 133 | </div> |
| ... | ... | @@ -187,7 +187,8 @@ |
| 187 | 187 | showModel: false, |
| 188 | 188 | commandType: 'OneWay', |
| 189 | 189 | commandValue: {}, |
| 190 | - inputCommandVal: '' | |
| 190 | + inputCommandVal: '', | |
| 191 | + isShowTCP:false,//用于下发命令时判断是否是TCP/UDP | |
| 191 | 192 | }; |
| 192 | 193 | }, |
| 193 | 194 | computed: { |
| ... | ... | @@ -257,11 +258,15 @@ |
| 257 | 258 | }, |
| 258 | 259 | showModal(e) { |
| 259 | 260 | this.modalName = e.currentTarget.dataset.target |
| 261 | + const {transportType} = this.deviceDetail.deviceProfile | |
| 262 | + this.isShowTCP = transportType=='TCP'?true:false | |
| 260 | 263 | this.showNodal = true |
| 261 | 264 | }, |
| 262 | 265 | showModalBtn() { |
| 263 | 266 | this.showModel = true; |
| 264 | 267 | this.inputCommandVal = ''; |
| 268 | + const {transportType} = this.deviceDetail.deviceProfile | |
| 269 | + this.isShowTCP = transportType=='TCP'?true:false | |
| 265 | 270 | }, |
| 266 | 271 | disabledScroll() { |
| 267 | 272 | return; |
| ... | ... | @@ -276,13 +281,22 @@ |
| 276 | 281 | }, |
| 277 | 282 | async confirmCommand() { |
| 278 | 283 | try { |
| 279 | - const commandJsonValue = JSON.parse(this.inputCommandVal); | |
| 284 | + this.commandValue.method = 'methodThingskit'; | |
| 280 | 285 | this.commandValue.persistent = true; |
| 281 | 286 | this.commandValue.additionalInfo = { |
| 282 | 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 | 300 | await issueCommand(this.commandType, this.deviceDetail.tbDeviceId, this.commandValue); |
| 287 | 301 | this.hiddenModal(); |
| 288 | 302 | uni.$u.toast('下发成功~'); |
| ... | ... | @@ -395,4 +409,4 @@ |
| 395 | 409 | width: 300rpx; |
| 396 | 410 | } |
| 397 | 411 | } |
| 398 | -</style> | |
| 412 | +</style> | ... | ... |