浇花器完善
This commit is contained in:
parent
f6c4e7d835
commit
caf9895d28
|
@ -110,10 +110,10 @@ const install = (Vue, vm) => {
|
|||
if (res.code) {
|
||||
console.log('登录!', res);
|
||||
let data = {
|
||||
wxOpenId: res.code,
|
||||
jsCode: res.code,
|
||||
|
||||
};
|
||||
vm.$u.post('/app/auth/wxLogin',data).then(res=>{
|
||||
vm.$u.post(`/loginByopenid?jsCode=${res.code}`,data).then(res=>{
|
||||
if (res.code == 10003) {
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
|
|
|
@ -311,7 +311,8 @@
|
|||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||
console.log("1收到设备发来的自定义数据结果:", options.data)
|
||||
const inputString = options.data
|
||||
const inputString = options.data.slice(0, -1) + ";"
|
||||
console.log(inputString,'12121212100')
|
||||
const pairs = inputString.split(';')
|
||||
const showObject = {}
|
||||
const pSetObjects = {}
|
||||
|
|
|
@ -99,11 +99,11 @@
|
|||
'isStart': false
|
||||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
xBlufi.notifyConnectBle({
|
||||
isStart: true,
|
||||
deviceId: that.deviceId,
|
||||
name: that.name
|
||||
})
|
||||
// xBlufi.notifyConnectBle({
|
||||
// isStart: true,
|
||||
// deviceId: that.deviceId,
|
||||
// name: that.name
|
||||
// })
|
||||
}
|
||||
}, 2000)
|
||||
},
|
||||
|
@ -113,21 +113,26 @@
|
|||
this.$u.get(`/appVerify/profile`).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.userid = res.data.userId
|
||||
}else if(res.code == 401){
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 点击添加添加绑定设备
|
||||
btnadd(e){
|
||||
let mac = e.name.slice(5, 17)
|
||||
console.log(e,'0101');
|
||||
let mac = e.slice(5, 17)
|
||||
let data = {
|
||||
mac:mac,
|
||||
userId:this.userid
|
||||
}
|
||||
this.$u.get(`/app/bandDevice`,data).then((res) => {
|
||||
this.$u.post(`/app/bandDevice`,data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
uni.showToast({
|
||||
title: '添加成功',
|
||||
icon: 'none',
|
||||
icon: 'success',
|
||||
duration: 3000
|
||||
})
|
||||
}else{
|
||||
|
@ -157,11 +162,11 @@
|
|||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
that.flags = true
|
||||
xBlufi.notifyConnectBle({
|
||||
isStart: true,
|
||||
deviceId: that.deviceId,
|
||||
name: that.name
|
||||
})
|
||||
// xBlufi.notifyConnectBle({
|
||||
// isStart: true,
|
||||
// deviceId: that.deviceId,
|
||||
// name: that.name
|
||||
// })
|
||||
}else{
|
||||
that.flags = false
|
||||
}
|
||||
|
@ -188,7 +193,7 @@
|
|||
}
|
||||
})
|
||||
}
|
||||
break;
|
||||
break
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
||||
if (options.result) {
|
||||
let devicesarr = options.data
|
||||
|
@ -206,7 +211,7 @@
|
|||
// }
|
||||
// })
|
||||
}
|
||||
break;
|
||||
break
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
|
||||
console.log("连接回调:" + JSON.stringify(options));
|
||||
if (options.result) {
|
||||
|
@ -220,9 +225,10 @@
|
|||
}else{
|
||||
|
||||
}
|
||||
break;
|
||||
break
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||
this.ver_data = this.parseCustomData(options.data)
|
||||
// this.ver_data = this.parseCustomData(options.data)
|
||||
this.ver_data = options.data
|
||||
console.log("1收到设备发来的自定义数据结果:", this.ver_data)
|
||||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
||||
|
@ -245,19 +251,19 @@
|
|||
} else {
|
||||
|
||||
}
|
||||
break;
|
||||
break
|
||||
}
|
||||
},
|
||||
// 从蓝牙拿到数据进行解析
|
||||
parseCustomData(data) {
|
||||
// 将字符串按照 "@" 分割成数组
|
||||
const dataArray = data.split('@');
|
||||
const voltage = parseFloat(dataArray[0].substring(1)); // 去除前缀 "V",并将字符串转换为浮点数
|
||||
const switchState = dataArray[1].substring(1); // 去除前缀 "S"
|
||||
const current = parseFloat(dataArray[2].substring(1)); // 去除前缀 "A",并将字符串转换为浮点数
|
||||
const power = parseFloat(dataArray[4].substring(1)); // 去除前缀 "P",并将字符串转换为浮点数
|
||||
const remainingPower = parseFloat(dataArray[5].substring(1)); // 去除前缀 "M",并将字符串转换为浮点数
|
||||
const setMode = dataArray[6].substring(1); // 去除前缀 "T"
|
||||
const dataArray = data.split('@')
|
||||
const voltage = parseFloat(dataArray[0].substring(1)) // 去除前缀 "V",并将字符串转换为浮点数
|
||||
const switchState = dataArray[1].substring(1) // 去除前缀 "S"
|
||||
const current = parseFloat(dataArray[2].substring(1)) // 去除前缀 "A",并将字符串转换为浮点数
|
||||
const power = parseFloat(dataArray[4].substring(1)) // 去除前缀 "P",并将字符串转换为浮点数
|
||||
const remainingPower = parseFloat(dataArray[5].substring(1)) // 去除前缀 "M",并将字符串转换为浮点数
|
||||
const setMode = dataArray[6].substring(1) // 去除前缀 "T"
|
||||
// 返回解析后的数据对象
|
||||
return {
|
||||
voltage,
|
||||
|
|
|
@ -347,16 +347,12 @@
|
|||
top: 18rpx;
|
||||
left: 38rpx;
|
||||
color: #999;
|
||||
/* placeholder颜色 */
|
||||
pointer-events: none;
|
||||
/* 确保点击事件可以穿透到textarea上 */
|
||||
}
|
||||
.custom-textarea {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* 设置一个合适高度 */
|
||||
padding-top: 18rpx;
|
||||
/* 为placeholder留出空间 */
|
||||
padding-left: 38rpx;
|
||||
padding-bottom: 54rpx;
|
||||
overflow: hidden;
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
<image class="img" src="https://api.ccttiot.com/smartmeter/img/static/uVKucPVDjxjaCDCpFKvw" mode=""></image>
|
||||
</view>
|
||||
<view class="name" @click="nameflag = true">
|
||||
<view class="">小发财树1号</view>
|
||||
<view class="">{{user.deviceName == undefined ? '--' : user.deviceName}}</view>
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uL6FHnMGWFrdptmDokDI" mode=""></image>
|
||||
</view>
|
||||
<view class="model">
|
||||
<text class="one">型号</text> <text>G-1232161</text>
|
||||
<text class="one">型号</text> <text>{{user.model == undefined ? '--' : user.model}}</text>
|
||||
</view>
|
||||
<view class="model" style="margin-top: 24rpx;">
|
||||
<text class="one" style="margin-right: 124rpx;">MAC</text> <text>2131897412</text>
|
||||
<text class="one" style="margin-right: 124rpx;">MAC</text> <text>{{user.mac == undefined ? '--' : user.mac}}</text>
|
||||
</view>
|
||||
<view class="wifi">
|
||||
<view class="">WIFI</view>
|
||||
|
@ -92,6 +92,8 @@
|
|||
value: '2',
|
||||
label: 'v2.1.3'
|
||||
}],
|
||||
deviceid:'',
|
||||
user:{}
|
||||
}
|
||||
},
|
||||
// 分享到好友(会话)
|
||||
|
@ -110,10 +112,20 @@
|
|||
path: '/pages/index/index'
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
onLoad(option) {
|
||||
this.deviceid = option.deviceid
|
||||
this.getshebxq()
|
||||
},
|
||||
methods: {
|
||||
// 获取设备信息
|
||||
getshebxq(){
|
||||
this.$u.get(`/app/getDeviceInfo/${this.deviceid}`).then(res => {
|
||||
if(res.code == 200){
|
||||
this.user = res.data
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 选择息屏时间
|
||||
xpconfirm(e){
|
||||
this.xptxt = e[0].label
|
||||
|
@ -144,8 +156,8 @@
|
|||
margin-bottom: 22rpx;
|
||||
}
|
||||
.editname{
|
||||
width: 440rpx;
|
||||
height: 320rpx;
|
||||
width: 530rpx;
|
||||
height: 340rpx;
|
||||
background-color: #fff;
|
||||
position: fixed;
|
||||
top: 600rpx;
|
||||
|
@ -164,7 +176,7 @@
|
|||
font-weight: 600;
|
||||
}
|
||||
input{
|
||||
width: 360rpx;
|
||||
width: 450rpx;
|
||||
height: 80rpx;
|
||||
background-color: #eee;
|
||||
border-radius: 10rpx;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<!-- 选择设备 -->
|
||||
<view class="selectbox">
|
||||
<view class="selectname" @click="btnksxz">
|
||||
小发财树1号 <image src="https://api.ccttiot.com/smartmeter/img/static/uwHOBxvbJjkhx1uDiQHI" mode="">
|
||||
切换设备 <image src="https://api.ccttiot.com/smartmeter/img/static/uwHOBxvbJjkhx1uDiQHI" mode="">
|
||||
</image>
|
||||
</view>
|
||||
<view class="selectshezhi" @click="btnsz">
|
||||
|
@ -31,7 +31,7 @@
|
|||
</view>
|
||||
<view class="selectbox">
|
||||
<view class="shebeiname" @click="btnlj">
|
||||
丁丁浇花器 <text></text>
|
||||
{{user.deviceName == undefined ? '--' : user.deviceName}} <text style="background-color: red;box-shadow: 0rpx 0rpx 10rpx 0rpx red, 0rpx 0rpx 30rpx 0rpx red" v-if="datalist == ''"></text> <text v-else></text>
|
||||
</view>
|
||||
<view class="shebeiadd" @click="btnaddsb">
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/udlX67UXzuRUZCuEtWDH" mode=""></image>
|
||||
|
@ -43,8 +43,8 @@
|
|||
<view class="devicelt">
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uVKucPVDjxjaCDCpFKvw" mode=""></image>
|
||||
<view class="xinghao">
|
||||
<view class="one">型号:G-145255445</view>
|
||||
<view class="">SN:G-145255445</view>
|
||||
<view class="one">型号:{{user.model == undefined ? '--' : user.model}}</view>
|
||||
<view class="">MAC:{{user.mac == undefined ? '--' : user.mac}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="devicert">
|
||||
|
@ -73,7 +73,9 @@
|
|||
P1
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set0[0],ver_data.p_set0[1])== xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set0[0],ver_data.p_set0[1])== xctimesj || formattedTime(ver_data.p_set0[0],Number(ver_data.p_set0[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -88,7 +90,9 @@
|
|||
P2
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set1[0],ver_data.p_set1[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set1[0],ver_data.p_set1[1]) == xctimesj || formattedTime(ver_data.p_set1[0],Number(ver_data.p_set1[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -103,7 +107,9 @@
|
|||
P3
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set2[0],ver_data.p_set2[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set2[0],ver_data.p_set2[1]) == xctimesj || formattedTime(ver_data.p_set2[0],Number(ver_data.p_set2[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -118,7 +124,9 @@
|
|||
P4
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set3[0],ver_data.p_set3[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set3[0],ver_data.p_set3[1]) == xctimesj || formattedTime(ver_data.p_set3[0],Number(ver_data.p_set3[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -133,7 +141,9 @@
|
|||
P5
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set4[0],ver_data.p_set4[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set4[0],ver_data.p_set4[1]) == xctimesj || formattedTime(ver_data.p_set4[0],Number(ver_data.p_set4[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -148,7 +158,9 @@
|
|||
P6
|
||||
</view>
|
||||
<view class="img">
|
||||
<image v-if="formattedTime(ver_data.p_set5[0],ver_data.p_set5[1]) == xctimesj" src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
<image
|
||||
v-if="formattedTime(ver_data.p_set5[0],ver_data.p_set5[1]) == xctimesj || formattedTime(ver_data.p_set5[0],Number(ver_data.p_set5[1]) + 1) == xctimesj"
|
||||
src="https://api.ccttiot.com/smartmeter/img/static/u9iZpd6bW6bUsUay4uvH" mode="">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -161,15 +173,19 @@
|
|||
<image src="https://api.ccttiot.com/smartmeter/img/static/u7NwkNOoQYYsvHVMkDlu" mode=""></image>
|
||||
<view class="yushui">
|
||||
雨水感应
|
||||
<u-switch v-if="yschecked" v-model="one" @change="btnyushui" inactive-color="#eee" active-color="#eee" size="40"></u-switch>
|
||||
<u-switch v-else v-model="ones" @change="btnyushuis" active-color="#7FAD76" inactive-color="#7FAD76" size="40"></u-switch>
|
||||
<u-switch v-if="yschecked" v-model="one" @change="btnyushui" inactive-color="#eee"
|
||||
active-color="#eee" size="40"></u-switch>
|
||||
<u-switch v-else v-model="ones" @change="btnyushuis" active-color="#7FAD76"
|
||||
inactive-color="#7FAD76" size="40"></u-switch>
|
||||
</view>
|
||||
</view>
|
||||
<view class="switch_he">
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/u7kd92ocUgDN052nhp4R" mode=""></image>
|
||||
<view class="yushui">
|
||||
儿童锁 <u-switch v-if="etchecked" v-model="two" @change="btnertong" inactive-color="#eee" active-color="#eee" size="40"></u-switch>
|
||||
<u-switch v-else v-model="twos" @change="btnertongs" active-color="#7FAD76" inactive-color="#7FAD76" size="40"></u-switch>
|
||||
儿童锁 <u-switch v-if="etchecked" v-model="two" @change="btnertong" inactive-color="#eee"
|
||||
active-color="#eee" size="40"></u-switch>
|
||||
<u-switch v-else v-model="twos" @change="btnertongs" active-color="#7FAD76"
|
||||
inactive-color="#7FAD76" size="40"></u-switch>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -205,11 +221,11 @@
|
|||
<!-- 切换设备 -->
|
||||
<view class="tabsb" v-if="xuanzeflag">
|
||||
<view class="sblist">
|
||||
<view class="sbist_val" v-for="(item,index) in 2" :key="index"
|
||||
:id="activeshu == index ? 'activebor' : ''" @click="btnactive(index)">
|
||||
<view class="sbist_val" v-for="(item,index) in devicelist" :key="index"
|
||||
:id="activeshu == index ? 'activebor' : ''" @click="btnactive(item.deviceId,index)">
|
||||
<view class="lt">
|
||||
<view class="">小发财树1号</view>
|
||||
<view class="" style="margin-top: 14rpx;">型号:12354121</view>
|
||||
<view class="">{{item.deviceName}}</view>
|
||||
<view class="" style="margin-top: 14rpx;">型号:{{item.model}}</view>
|
||||
</view>
|
||||
<view class="rt">
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uVKucPVDjxjaCDCpFKvw" mode=""></image>
|
||||
|
@ -280,7 +296,7 @@
|
|||
devicesList: [],
|
||||
deviceId: '',
|
||||
name: '',
|
||||
mac:'2952BB7A4EE0',
|
||||
mac: '',
|
||||
jstime: '',
|
||||
ver_data: {},
|
||||
showobj: {},
|
||||
|
@ -289,7 +305,12 @@
|
|||
xctimesc: '--',
|
||||
xctimesj: '',
|
||||
sdminutes: '',
|
||||
sdseconds:''
|
||||
sdseconds: '',
|
||||
datalist: '',
|
||||
devicelist:[],
|
||||
shebid:'',
|
||||
user:{},
|
||||
lastChar:''
|
||||
}
|
||||
},
|
||||
// 分享到好友(会话)
|
||||
|
@ -309,24 +330,7 @@
|
|||
}
|
||||
},
|
||||
onLoad() {
|
||||
let that = this
|
||||
xBlufi.initXBlufi(1)
|
||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
})
|
||||
setTimeout(() => {
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': false
|
||||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
xBlufi.notifyConnectBle({
|
||||
isStart: true,
|
||||
deviceId: that.deviceId,
|
||||
name: that.name
|
||||
})
|
||||
}
|
||||
}, 2000)
|
||||
|
||||
},
|
||||
onShow() {
|
||||
this.getinfo()
|
||||
|
@ -354,6 +358,7 @@
|
|||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
})
|
||||
this.getchao()
|
||||
setTimeout(() => {
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': false
|
||||
|
@ -367,17 +372,83 @@
|
|||
}
|
||||
}, 2000)
|
||||
},
|
||||
// 连接超时提示
|
||||
getchao(){
|
||||
uni.showLoading({
|
||||
title: '浇花器连接中...'
|
||||
})
|
||||
this.getshebxq()
|
||||
setTimeout(()=>{
|
||||
uni.hideLoading()
|
||||
|
||||
if(this.datalist == ''){
|
||||
let that = this
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '未连接成功,是否重新连接,重新连接请确保设备在附近5米范围内',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
that.getinfo()
|
||||
} else if (res.cancel) {
|
||||
uni.showToast({
|
||||
title: '已取消连接',
|
||||
icon: 'none',
|
||||
duration:2000
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}else{
|
||||
uni.showToast({
|
||||
title: '设备连接成功',
|
||||
icon: 'success',
|
||||
duration:2000
|
||||
})
|
||||
}
|
||||
},15000)
|
||||
},
|
||||
// 静默登录
|
||||
jmlogin() {
|
||||
let taht = this
|
||||
wx.login({
|
||||
success(res) {
|
||||
if (res.code) {
|
||||
let data = {
|
||||
jsCode: res.code,
|
||||
}
|
||||
taht.$u.post(`/loginByopenid?jsCode=${res.code}`, data).then(res => {
|
||||
if (res.code == 200) {
|
||||
taht.getinfo()
|
||||
uni.setStorageSync('token', res.token)
|
||||
}else{
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '您还未登录,是否前去登录?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
// 获取用户信息
|
||||
getinfo() {
|
||||
this.$u.get(`/appVerify/profile`).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.userobj = res.data
|
||||
// 根据用户id获取当前用户
|
||||
this.$u.get(`/app/getDeviceInfoByUser?userId=${this.userobj.userId}`).then((res) => {
|
||||
if (res.code == 200) {
|
||||
|
||||
}
|
||||
})
|
||||
this.getlist()
|
||||
}else if(res.code == 401){
|
||||
this.jmlogin()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -484,6 +555,10 @@
|
|||
|
||||
// 点击添加设备
|
||||
btnaddsb() {
|
||||
//跳转后清空数据 重新进行连接
|
||||
this.datalist = ''
|
||||
this.mac = ''
|
||||
this.ver_data = {}
|
||||
uni.navigateTo({
|
||||
url: '/page_user/lanya'
|
||||
})
|
||||
|
@ -545,7 +620,7 @@
|
|||
|
||||
// 手动浇水定时器
|
||||
startTimer(totalSeconds) {
|
||||
let remainingSeconds = totalSeconds
|
||||
let sdseconds = totalSeconds
|
||||
console.log(remainingSeconds, '000');
|
||||
const timer = setInterval(() => {
|
||||
// 计算分钟和秒
|
||||
|
@ -579,6 +654,9 @@
|
|||
xBlufi.notifySendCustomData({
|
||||
customData: "11close"
|
||||
})
|
||||
that.startTimer(0)
|
||||
that.sdminutes = ''
|
||||
that.sdseconds = ''
|
||||
that.kgflag = false
|
||||
}, 1500)
|
||||
},
|
||||
|
@ -590,7 +668,7 @@
|
|||
}
|
||||
})
|
||||
},
|
||||
// 开启
|
||||
// 开启手动浇水
|
||||
btngb() {
|
||||
this.sdjsflag = true
|
||||
},
|
||||
|
@ -598,16 +676,101 @@
|
|||
// 跳转到设置
|
||||
btnsz() {
|
||||
uni.navigateTo({
|
||||
url: '/page_user/upload'
|
||||
url: '/page_user/upload?deviceid=' + this.shebid
|
||||
})
|
||||
},
|
||||
// 选择设备
|
||||
btnactive(index) {
|
||||
btnactive(deviceId,index) {
|
||||
this.shebid = deviceId
|
||||
this.activeshu = index
|
||||
},
|
||||
// 选择确定设备
|
||||
// 选择确定设备 shebid
|
||||
btnxuanze() {
|
||||
this.$u.put(`/app/toggleDevice?userId=${this.userobj.userId}&deviceId=${this.shebid}`).then(res => {
|
||||
if(res.code == 200){
|
||||
wx.closeBLEConnection({
|
||||
deviceId: this.mac,
|
||||
})
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.datalist = ''
|
||||
this.mac = ''
|
||||
this.ver_data = {}
|
||||
this.xuanzeflag = false
|
||||
let that = this
|
||||
xBlufi.initXBlufi(1)
|
||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
})
|
||||
setTimeout(() => {
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': false
|
||||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
xBlufi.notifyConnectBle({
|
||||
isStart: true,
|
||||
deviceId: that.deviceId,
|
||||
name: that.name
|
||||
})
|
||||
}
|
||||
}, 2000)
|
||||
that.getchao()
|
||||
}else{
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 获取设备信息
|
||||
getshebxq(){
|
||||
this.$u.get(`/app/getDeviceInfo/${this.shebid}`).then(res => {
|
||||
if(res.code == 200){
|
||||
this.mac = res.data.mac
|
||||
this.user = res.data
|
||||
uni.showLoading({
|
||||
title: '浇花器连接中...'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 获取设备列表
|
||||
getlist(){
|
||||
this.$u.get(`/app/getDeviceInfoByUser?userId=${this.userobj.userId}`).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.devicelist = res.data
|
||||
this.mac = res.data[0].mac
|
||||
this.user = res.data[0]
|
||||
this.shebid = res.data[0].deviceId
|
||||
if(this.datalist == ''){
|
||||
let that = this
|
||||
xBlufi.initXBlufi(1)
|
||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
})
|
||||
setTimeout(() => {
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': false
|
||||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
xBlufi.notifyConnectBle({
|
||||
isStart: true,
|
||||
deviceId: that.deviceId,
|
||||
name: that.name
|
||||
})
|
||||
}
|
||||
}, 2000)
|
||||
that.getchao()
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
btnksxz() {
|
||||
if (this.xuanzeflag == true) {
|
||||
|
@ -636,7 +799,8 @@
|
|||
//是否显示取消按钮
|
||||
success: function(res) {
|
||||
uni.hideLoading()
|
||||
uni.removeStorage({key:'device_key'})
|
||||
this.datalist = ''
|
||||
this.ver_data = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -692,23 +856,95 @@
|
|||
}
|
||||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||
console.log("1收到设备发来的自定义数据结果:", options.data)
|
||||
const inputString = options.data
|
||||
console.log("1收到设备发来的自定义数据结果:", options.data,options.data.length)
|
||||
this.datalist = options.data.slice(0, -1) + ";"
|
||||
this.getchuli()
|
||||
break
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
||||
if (options.result) {
|
||||
let uniqueDevicesList = Array.from(new Set(this.devicesList))
|
||||
let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) ===
|
||||
"WATER")
|
||||
// 将过滤后的数组重新赋值给 this.devicesList
|
||||
this.devicesList = filteredDevices
|
||||
}
|
||||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
||||
if (!options.result) {
|
||||
uni.showToast({
|
||||
title: '蓝牙未开启',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
// uni.showModal({
|
||||
// title: '提示',
|
||||
// content: '请打开蓝牙和位置信息',
|
||||
// success: function (res) {
|
||||
// if (res.confirm) {
|
||||
// that.getinfo()
|
||||
// } else if (res.cancel) {
|
||||
// uni.showToast({
|
||||
// title: '已取消连接',
|
||||
// icon: 'none',
|
||||
// duration:2000
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
// 每隔一分钟发送一次获取数据
|
||||
getshuju() {
|
||||
let that = this
|
||||
const intervalId = setInterval(() => {
|
||||
uni.getNetworkType({
|
||||
success(res) {
|
||||
if (res.networkType !== 'none') {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
success(res) {
|
||||
setTimeout(() => {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
console.log(that.ver_data,'000');
|
||||
if(that.ver_data != ''){
|
||||
that.getchuli()
|
||||
}
|
||||
}, 1000)
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取已连接蓝牙设备信息失败:', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log("定时器每分钟执行一次")
|
||||
}, 60000)
|
||||
},
|
||||
|
||||
// 处理接收数据
|
||||
getchuli() {
|
||||
const inputString = this.datalist
|
||||
const pairs = inputString.split(';')
|
||||
const showObject = {}
|
||||
const pSetObjects = {}
|
||||
pairs.forEach(pair => {
|
||||
const [key, value] = pair.split(':');
|
||||
const [key, value] = pair.split(':')
|
||||
if (key === 'show') {
|
||||
showObject.showArray = value.split(',').map(Number);
|
||||
showObject.showArray = value.split(',').map(Number)
|
||||
} else if (key.startsWith('p_set')) {
|
||||
const numbers = value.split(',').map(Number);
|
||||
const numbers = value.split(',').map(Number)
|
||||
pSetObjects[key] = numbers
|
||||
}
|
||||
})
|
||||
this.ver_data = pSetObjects //六个浇水时间段
|
||||
console.log(this.ver_data,'002002002')
|
||||
|
||||
// this.ver_data.p_set5[3] = this.lastChar
|
||||
console.log(inputString,this.ver_data, '002002002')
|
||||
this.showobj = showObject //雨滴,锁,等是否开启
|
||||
if (this.showobj.showArray[1] == 1) {
|
||||
this.yschecked = false
|
||||
|
@ -723,128 +959,78 @@
|
|||
// 计算浇水时间
|
||||
const ver_Data = this.ver_data
|
||||
function secondsToMinutesAndSeconds(seconds) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}分${remainingSeconds}秒`;
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const remainingSeconds = seconds % 60
|
||||
return `${minutes}分${remainingSeconds}秒`
|
||||
}
|
||||
// 获取当前时间
|
||||
const now = new Date();
|
||||
// 辅助函数:将时间数组转换为 Date 对象
|
||||
function timeArrayToDate(timeArray) {
|
||||
const [hour, minute, second] = timeArray.slice(0, 3);
|
||||
const date = new Date();
|
||||
date.setHours(hour, minute, second, 0); // 毫秒设为0
|
||||
return date;
|
||||
const [hour, minute,minutes, second, /* other fields */ ] = timeArray
|
||||
const date = new Date()
|
||||
date.setHours(hour, minute,minute, second, 0) // 毫秒设为0
|
||||
console.log(date,'11111');
|
||||
return date
|
||||
}
|
||||
// 辅助函数:计算两个时间之间的差值(以小时和分钟表示)
|
||||
function timeDifference(date1, date2) {
|
||||
const diffMs = Math.abs(date1 - date2);
|
||||
const diffSeconds = Math.floor(diffMs / 1000);
|
||||
const diffMinutes = Math.floor(diffSeconds / 60);
|
||||
const diffHours = Math.floor(diffMinutes / 60);
|
||||
const remainingMinutes = diffMinutes % 60;
|
||||
return { hours: diffHours, minutes: remainingMinutes };
|
||||
const diffMs = Math.abs(date1 - date2)
|
||||
const diffSeconds = Math.floor(diffMs / 1000)
|
||||
const diffMinutes = Math.floor(diffSeconds / 60)
|
||||
const diffHours = Math.floor(diffMinutes / 60)
|
||||
const remainingMinutes = diffMinutes % 60
|
||||
return {
|
||||
hours: diffHours,
|
||||
minutes: remainingMinutes
|
||||
}
|
||||
// 遍历 ver_Data 对象
|
||||
let nextTimeDiff = null;
|
||||
let nextTime = null;
|
||||
let prevTimeDiff = null;
|
||||
let prevTime = null;
|
||||
let nextWaterDuration = null; // 用于存储下次浇水时长
|
||||
}
|
||||
let nextTimeDiff = null
|
||||
let nextTime = null
|
||||
let prevTimeDiff = null
|
||||
let prevTime = null
|
||||
let nextWaterDuration = null
|
||||
for (const key in ver_Data) {
|
||||
if (ver_Data.hasOwnProperty(key) && ver_Data[key][3] === 1) {
|
||||
const timeArray = ver_Data[key];
|
||||
const timeDate = timeArrayToDate(timeArray);
|
||||
// 计算与当前时间的差值
|
||||
const diff = timeDifference(timeDate, now);
|
||||
// 判断是下一次时间还是上一次时间
|
||||
if (timeDate > now) {
|
||||
if (!nextTime || diff.hours * 60 + diff.minutes < nextTimeDiff.hours * 60 + nextTimeDiff.minutes) {
|
||||
nextTimeDiff = diff;
|
||||
nextTime = timeDate;
|
||||
nextWaterDuration = secondsToMinutesAndSeconds(timeArray[2]); // 获取并转换浇水时长
|
||||
const timeArray = ver_Data[key]
|
||||
console.log(timeArray,'00000');
|
||||
const timeDate = timeArrayToDate(timeArray)
|
||||
|
||||
const diff = timeDifference(timeDate, new Date())
|
||||
if (timeDate > new Date()) {
|
||||
if (!nextTime || (diff.hours * 60 + diff.minutes < (nextTimeDiff.hours || 0) * 60 + (
|
||||
nextTimeDiff.minutes || 0))) {
|
||||
nextTimeDiff = diff
|
||||
nextTime = timeDate
|
||||
nextWaterDuration = secondsToMinutesAndSeconds(timeArray[2])
|
||||
}
|
||||
} else {
|
||||
if (!prevTime || (now.getTime() - timeDate.getTime()) < (now.getTime() - prevTime.getTime())) {
|
||||
prevTimeDiff = timeDifference(now, timeDate); // 注意这里要反过来算
|
||||
prevTime = timeDate;
|
||||
if (!prevTime || (new Date() - timeDate < new Date() - (prevTime || new Date(0)))) {
|
||||
prevTimeDiff = timeDifference(new Date(), timeDate)
|
||||
prevTime = timeDate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 输出结果
|
||||
this.xctime = `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分`
|
||||
this.xctimesc = nextWaterDuration
|
||||
let timesc = prevTime.toTimeString().split(' ')[0]
|
||||
this.sctimejs = timesc.slice(0,-3)
|
||||
let xcjs = nextTime.toTimeString().split(' ')[0]
|
||||
this.xctimesj = xcjs.slice(0,-3)
|
||||
console.log(xcjs,'121212',this.formattedTime(this.ver_data.p_set5[0],this.ver_data.p_set5[1]))
|
||||
// 输出结果,确保在访问 null 值之前进行检查
|
||||
this.xctime = nextTime ? `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分` : '无距离下次浇水时间';
|
||||
this.xctimesc = nextWaterDuration || '未知';
|
||||
this.sctimejs = prevTime ? prevTime.toTimeString().split(' ')[0].slice(0, -3) : '无上次浇水时间';
|
||||
this.xctimesj = nextTime ? nextTime.toTimeString().split(' ')[0].slice(0, -3) : '无下次浇水时间';
|
||||
console.log('下次浇水时间',this.xctimesj,'距离下次浇水时间',this.xctime,'上次浇水时间',this.sctimejs)
|
||||
// console.log('距离下次最近的时间差:', nextTimeDiff ? `${nextTimeDiff.hours}时${nextTimeDiff.minutes}分` : '无');
|
||||
// console.log('下次时间:', nextTime ? nextTime.toTimeString().split(' ')[0] : '无');
|
||||
// console.log('下次浇水时长:', nextWaterDuration || '无');
|
||||
// console.log('距离上次最近的时间差:', prevTimeDiff ? `${prevTimeDiff.hours}时${prevTimeDiff.minutes}分` : '无');
|
||||
// console.log('上次时间:', prevTime ? prevTime.toTimeString().split(' ')[0] : '无')
|
||||
|
||||
|
||||
break
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
||||
if (options.result) {
|
||||
let uniqueDevicesList = Array.from(new Set(this.devicesList))
|
||||
let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "WATER")
|
||||
// 将过滤后的数组重新赋值给 this.devicesList
|
||||
this.devicesList = filteredDevices
|
||||
}
|
||||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
||||
if (!options.result) {
|
||||
uni.showToast({
|
||||
title: '蓝牙未开启',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
return
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
// 每隔一分钟发送一次获取数据
|
||||
getshuju(){
|
||||
const intervalId = setInterval(() => {
|
||||
uni.getNetworkType({
|
||||
success(res) {
|
||||
if (res.networkType !== 'none') {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
success(res) {
|
||||
setTimeout(()=> {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
},1000)
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log("定时器每分钟执行一次");
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 22rpx;
|
||||
|
||||
view {
|
||||
width: 242rpx;
|
||||
height: 208rpx;
|
||||
|
@ -856,16 +1042,19 @@
|
|||
font-size: 44rpx;
|
||||
color: #3D3D3D;
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 80rpx;
|
||||
margin-left: 46rpx;
|
||||
margin-right: 46rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.anniu {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 58rpx;
|
||||
|
||||
.qx {
|
||||
width: 278rpx;
|
||||
height: 80rpx;
|
||||
|
@ -877,6 +1066,7 @@
|
|||
line-height: 80rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.qd {
|
||||
width: 278rpx;
|
||||
height: 80rpx;
|
||||
|
@ -889,6 +1079,7 @@
|
|||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.selected-time {
|
||||
margin-top: 20px;
|
||||
font-size: 20px;
|
||||
|
@ -1327,5 +1518,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user