iot-ui-app/pages/index/scan.vue

95 lines
2.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
</template>
<script>
import request from '@/network/request.js'
export default {
data() {
return {
on: true
}
},
methods: {
},
onLoad() {
},
onShow() {
// tab除了第一次后面只触发show增加on防止重复触发
var that = this
if (that.on) {
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
success: function (res) {
console.log("获取二维码数据",res)
if(res.result){
let [type,prodKey,devKey] = res.result.split(':')
if(prodKey&&devKey){
let opt = {
url: '/prod-api/iot/device/get/device',
method: "GET",
}
let params={
devKey,
pd:prodKey
}
// this.$request调用为空应该是onLaunch时$request还未挂载直接引入request使用
request.TokenRequest(opt,params).then(res => {
console.log('res',res)
if(res.code==200){
if(res.data){
let deviceId=res.data.deviceId;
uni.navigateTo({
url:'/pages/device/detail?deviceId='+deviceId,
success: (res) => {
uni.showToast({
title: '跳转成功',
icon: 'none'
});
},
fail: (err) => {
uni.showToast({
title: '跳转失败',
icon: 'none'
});
}
})
}else{
uni.showToast({
title: '未查询到设备id',
icon: 'none'
});
}
}else{
uni.showToast({
title: res.msg,
icon: 'none'
});
}
}, error => {
uni.showToast({
title: '服务器开小差了呢,请您稍后再试',
icon: 'none'
});
})
}
}
}
});
}
},
onHide: function() {
console.log("扫一扫onHide")
this.on = !this.on;
uni.switchTab({
url:'./home'
})
},
}
</script>
<style>
</style>