2024-10-17 18:00:05 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view>
|
|
|
|
|
<u-navbar :is-back="true" title='添加设备' title-color="#000" :border-bottom="false" :background="bgc"
|
|
|
|
|
id="navbar">
|
|
|
|
|
</u-navbar>
|
2024-10-18 17:59:38 +08:00
|
|
|
|
<!-- 有搜索到设备 -->
|
|
|
|
|
<view class="you" v-if="flags">
|
|
|
|
|
<view class="topone">
|
|
|
|
|
<image src="https://api.ccttiot.com/smartmeter/img/static/ubrPcpGQEXTadkBa1gKh" mode=""></image> 扫描到以下设备,点击添加!
|
|
|
|
|
</view>
|
|
|
|
|
<view class="toptwo">
|
|
|
|
|
如未找到想添加的设备,点击重新搜索
|
|
|
|
|
</view>
|
|
|
|
|
<view class="list">
|
2025-02-19 17:42:28 +08:00
|
|
|
|
<view class="list_item" v-for="(item,index) in jiaohuaqi" :key="index">
|
2024-10-18 17:59:38 +08:00
|
|
|
|
<image src="https://api.ccttiot.com/smartmeter/img/static/ufPWKlVzDbHNflX0jUIv" mode=""></image>
|
|
|
|
|
<view class="cen">
|
|
|
|
|
<view class="name">
|
|
|
|
|
丁丁浇花器
|
|
|
|
|
</view>
|
|
|
|
|
<view class="devmac">
|
2025-02-19 17:42:28 +08:00
|
|
|
|
MAC:{{item}}
|
2024-10-18 17:59:38 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2025-02-19 17:42:28 +08:00
|
|
|
|
<view class="add" @click="btnadd(item)">
|
2024-10-18 17:59:38 +08:00
|
|
|
|
添加
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 未搜索到设备 -->
|
|
|
|
|
<view class="wei" v-else>
|
|
|
|
|
<image src="https://api.ccttiot.com/smartmeter/img/static/uQ4g6A27FGtF34ebOtea" mode=""></image>
|
|
|
|
|
<view class="sbname">
|
|
|
|
|
搜索附近的设备失败
|
|
|
|
|
</view>
|
|
|
|
|
<view class="sbwz">
|
|
|
|
|
搜索失败点击重新搜索注意打开蓝牙
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 点击搜索 -->
|
|
|
|
|
<view class="btnss" @click="btnss" v-if="flag">
|
|
|
|
|
重新搜索
|
|
|
|
|
</view>
|
|
|
|
|
<view class="btnss" v-else>
|
|
|
|
|
重新搜索
|
|
|
|
|
</view>
|
2024-10-17 18:00:05 +08:00
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var xBlufi = require("@/components/blufi/xBlufi.js");
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
bgc: {
|
|
|
|
|
backgroundColor: "#fff",
|
|
|
|
|
},
|
|
|
|
|
active:1,
|
2024-10-18 17:59:38 +08:00
|
|
|
|
flag:true,
|
2024-10-17 18:00:05 +08:00
|
|
|
|
devicesList:[],
|
|
|
|
|
deviceId:'',
|
|
|
|
|
name:'',
|
2025-02-19 17:42:28 +08:00
|
|
|
|
mac:'',
|
2024-10-23 18:04:30 +08:00
|
|
|
|
flags:true,
|
2025-02-19 17:42:28 +08:00
|
|
|
|
userid:'',
|
|
|
|
|
arr:'',
|
|
|
|
|
jiaohuaqi:[]
|
2024-10-18 17:59:38 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 分享到好友(会话)
|
|
|
|
|
onShareAppMessage: function() {
|
|
|
|
|
return {
|
|
|
|
|
title: '绿小能',
|
|
|
|
|
path: '/pages/index/index'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 分享到朋友圈
|
|
|
|
|
onShareTimeline: function() {
|
|
|
|
|
return {
|
|
|
|
|
title: '绿小能',
|
|
|
|
|
query: '',
|
|
|
|
|
path: '/pages/index/index'
|
2024-10-17 18:00:05 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLoad() {
|
2025-02-19 17:42:28 +08:00
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onShow() {
|
2024-10-23 18:04:30 +08:00
|
|
|
|
this.getinfo()
|
2025-02-19 17:42:28 +08:00
|
|
|
|
this.btnss()
|
2024-10-17 18:00:05 +08:00
|
|
|
|
},
|
|
|
|
|
methods:{
|
2024-10-23 18:04:30 +08:00
|
|
|
|
// 获取用户信息
|
|
|
|
|
getinfo() {
|
|
|
|
|
this.$u.get(`/appVerify/profile`).then((res) => {
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
this.userid = res.data.userId
|
2024-10-31 17:57:18 +08:00
|
|
|
|
}else if(res.code == 401){
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url:'/pages/login/login'
|
|
|
|
|
})
|
2024-10-23 18:04:30 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
// 点击添加添加绑定设备
|
|
|
|
|
btnadd(e){
|
2024-10-31 17:57:18 +08:00
|
|
|
|
console.log(e,'0101');
|
2025-02-11 17:33:33 +08:00
|
|
|
|
let mac = e.slice(-12)
|
2024-10-23 18:04:30 +08:00
|
|
|
|
let data = {
|
|
|
|
|
mac:mac,
|
2025-02-19 17:42:28 +08:00
|
|
|
|
userId:this.userid,
|
|
|
|
|
pre:e.slice(0,5)
|
2024-10-23 18:04:30 +08:00
|
|
|
|
}
|
2024-10-31 17:57:18 +08:00
|
|
|
|
this.$u.post(`/app/bandDevice`,data).then((res) => {
|
2024-10-23 18:04:30 +08:00
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '添加成功',
|
2024-10-31 17:57:18 +08:00
|
|
|
|
icon: 'success',
|
2024-10-23 18:04:30 +08:00
|
|
|
|
duration: 3000
|
|
|
|
|
})
|
2024-11-08 18:02:11 +08:00
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
uni.navigateBack()
|
|
|
|
|
},2000)
|
2024-10-23 18:04:30 +08:00
|
|
|
|
}else{
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: res.msg,
|
|
|
|
|
icon: 'none',
|
|
|
|
|
duration: 3000
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2025-02-19 17:42:28 +08:00
|
|
|
|
|
|
|
|
|
btnss(){
|
2024-10-18 17:59:38 +08:00
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '搜索中...'
|
|
|
|
|
})
|
2025-02-19 17:42:28 +08:00
|
|
|
|
this.jiaohuaqi = []
|
2024-10-18 17:59:38 +08:00
|
|
|
|
this.flag = false
|
|
|
|
|
let that = this
|
2024-10-22 18:01:20 +08:00
|
|
|
|
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
2024-10-18 17:59:38 +08:00
|
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
|
|
'isStart': true
|
|
|
|
|
})
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
|
|
'isStart': false
|
|
|
|
|
})
|
|
|
|
|
if (that.devicesList.length > 0) {
|
|
|
|
|
that.flags = true
|
2025-02-19 17:42:28 +08:00
|
|
|
|
this.$u.get(`/app/device/isBand/${this.arr}`).then(res =>{
|
|
|
|
|
if(res.code == 200){
|
|
|
|
|
res.data.forEach(item =>{
|
|
|
|
|
if(item.isBand == false){
|
|
|
|
|
that.devicesList.forEach(val =>{
|
|
|
|
|
if(val.name.slice(-12) == item.mac){
|
|
|
|
|
that.jiaohuaqi.push(val.name)
|
|
|
|
|
console.log(that.jiaohuaqi);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-10-18 17:59:38 +08:00
|
|
|
|
}else{
|
2025-02-19 17:42:28 +08:00
|
|
|
|
// that.flags = false
|
2024-10-18 17:59:38 +08:00
|
|
|
|
}
|
|
|
|
|
uni.hideLoading()
|
|
|
|
|
that.flag = true
|
2025-02-19 17:42:28 +08:00
|
|
|
|
}, 3000)
|
|
|
|
|
},
|
2024-10-17 18:00:05 +08:00
|
|
|
|
|
|
|
|
|
// 获取附近蓝牙设备列表
|
|
|
|
|
funListenDeviceMsgEvent: function(options) {
|
|
|
|
|
switch (options.type) {
|
|
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
|
|
|
|
if (!options.result) {
|
2025-02-19 17:42:28 +08:00
|
|
|
|
|
2024-10-17 18:00:05 +08:00
|
|
|
|
}
|
2024-10-31 17:57:18 +08:00
|
|
|
|
break
|
2024-10-17 18:00:05 +08:00
|
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
|
|
|
|
if (options.result) {
|
2025-02-19 17:42:28 +08:00
|
|
|
|
let devicesarr = []
|
|
|
|
|
this.devicesList = options.data
|
|
|
|
|
options.data.forEach(item =>{
|
|
|
|
|
devicesarr.push(item.name.slice(-12))
|
|
|
|
|
})
|
|
|
|
|
this.arr = devicesarr.join(',')
|
2024-10-17 18:00:05 +08:00
|
|
|
|
}
|
2024-10-31 17:57:18 +08:00
|
|
|
|
break
|
2024-10-17 18:00:05 +08:00
|
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
|
2025-02-19 17:42:28 +08:00
|
|
|
|
console.log("连接回调:" + JSON.stringify(options))
|
2024-10-17 18:00:05 +08:00
|
|
|
|
if (options.result) {
|
|
|
|
|
{
|
|
|
|
|
xBlufi.notifyInitBleEsp32({
|
|
|
|
|
deviceId: this.deviceId
|
|
|
|
|
})
|
|
|
|
|
this.deviceIds = options.data.deviceId
|
|
|
|
|
this.name = this.name
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-31 17:57:18 +08:00
|
|
|
|
break
|
2024-10-17 18:00:05 +08:00
|
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
2025-02-19 17:42:28 +08:00
|
|
|
|
|
2024-10-17 18:00:05 +08:00
|
|
|
|
break;
|
|
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
|
|
|
|
if (!options.result) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '蓝牙未开启',
|
|
|
|
|
icon: 'none',
|
|
|
|
|
duration: 3000
|
2024-10-18 17:59:38 +08:00
|
|
|
|
})
|
|
|
|
|
this.flags = false
|
2024-10-17 18:00:05 +08:00
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-31 17:57:18 +08:00
|
|
|
|
break
|
2024-10-17 18:00:05 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less">
|
|
|
|
|
/deep/ .u-title{
|
|
|
|
|
margin-bottom: 22rpx;
|
|
|
|
|
}
|
|
|
|
|
/deep/ .uicon-nav-back{
|
|
|
|
|
margin-bottom: 22rpx;
|
|
|
|
|
}
|
2024-10-18 17:59:38 +08:00
|
|
|
|
.wei{
|
|
|
|
|
text-align: center;
|
|
|
|
|
image{
|
|
|
|
|
width: 380rpx;
|
|
|
|
|
height: 394rpx;
|
|
|
|
|
}
|
|
|
|
|
.sbname{
|
|
|
|
|
font-size: 40rpx;
|
|
|
|
|
color: #3D3D3D;
|
|
|
|
|
margin-top: 80rpx;
|
|
|
|
|
width: 100%;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
.sbwz{
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #737B80;
|
|
|
|
|
margin-top: 24rpx;
|
|
|
|
|
width: 100%;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.btnss{
|
|
|
|
|
width: 512rpx;
|
|
|
|
|
height: 92rpx;
|
|
|
|
|
background: #48893B;
|
|
|
|
|
border-radius: 46rpx 46rpx 46rpx 46rpx;
|
|
|
|
|
border-radius: 50rpx;
|
|
|
|
|
text-align: center;
|
|
|
|
|
line-height: 92rpx;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
font-size: 40rpx;
|
|
|
|
|
color: #FFFFFF;
|
|
|
|
|
position: fixed;
|
|
|
|
|
left: 50%;
|
|
|
|
|
transform: translateX(-50%);
|
|
|
|
|
bottom: 106rpx;
|
|
|
|
|
}
|
|
|
|
|
.list{
|
|
|
|
|
width: 100%;
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
margin: auto;
|
|
|
|
|
margin-top: 72rpx;
|
|
|
|
|
.list_item{
|
|
|
|
|
margin-top: 18rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 152rpx;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
box-shadow: 0rpx 10rpx 64rpx 0rpx rgba(0,0,0,0.08);
|
|
|
|
|
padding: 18rpx 30rpx;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
image{
|
|
|
|
|
width: 96rpx;
|
|
|
|
|
height: 94rpx;
|
|
|
|
|
}
|
|
|
|
|
.cen{
|
|
|
|
|
.name{
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
color: #50565A;
|
|
|
|
|
}
|
|
|
|
|
.devmac{
|
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
color: #BDBCBC;
|
|
|
|
|
margin-top: 6rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.add{
|
|
|
|
|
width: 108rpx;
|
|
|
|
|
height: 60rpx;
|
|
|
|
|
background: #FFFFFF;
|
|
|
|
|
border: 3rpx solid #48893B;
|
|
|
|
|
filter: blur(0px);
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
text-align: center;
|
|
|
|
|
line-height: 60rpx;
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #48893B;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-17 18:00:05 +08:00
|
|
|
|
page{
|
|
|
|
|
width: 100%;
|
2024-10-18 17:59:38 +08:00
|
|
|
|
padding: 20rpx 64rpx;
|
2024-10-17 18:00:05 +08:00
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
}
|
2024-10-18 17:59:38 +08:00
|
|
|
|
.topone{
|
|
|
|
|
font-size: 36rpx;
|
|
|
|
|
color: #3D3D3D;
|
|
|
|
|
display: flex;
|
|
|
|
|
image{
|
|
|
|
|
width: 48rpx;
|
|
|
|
|
height: 48rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.toptwo{
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #737B7F;
|
|
|
|
|
margin-top: 14rpx;
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding-left: 48rpx;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
2024-10-17 18:00:05 +08:00
|
|
|
|
|
|
|
|
|
</style>
|