浇花器

This commit is contained in:
3321822538@qq.com 2025-02-19 17:42:28 +08:00
parent b8741c148b
commit 516e9c3da9
5 changed files with 542 additions and 222 deletions

View File

@ -912,8 +912,104 @@ function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data)
// var requestTask =
}
// 模拟一个异步操作,比如网络请求
function fetchData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Data fetched!');
}, 20); // 模拟网络延迟 2 秒
});
}
// 模拟一个异步操作,比如网络请求
function fetchData2() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Data fetched!');
}, 2000); // 模拟网络延迟 2 秒
});
}
async function main(res, my_sum, deviceId, serviceId, characteristicId) {
var address = 0;
var len = 0;
var buf = 0;
var dv = 0;
let result;
dv = new DataView(res.data);
var bufferLength = dv.byteLength;
var sum = 0;
for (var i = 0; i < bufferLength; i++) {
sum += dv.getUint8(i)
}
const data1 = await fetchData2();
result = dv
console.log(result);
console.log("content-length", bufferLength);
console.log("sum", sum);
len = bufferLength
if (sum != my_sum && my_sum != 100) {
console.log("不相等my_sum", my_sum);
return;
}
var p_data = 0;
var p_ii = 0;
while (address <= len) {
var offst = 176;
if (address + 176 > len) {
offst = len - address;
}
var value = util.write_ota_program(CMD_IAP_PROM, offst, address, result);
var typedArray = new Uint8Array(value);
// console.log("12121")
const data = await fetchData();
var qq = await send_ota_data_num(deviceId, serviceId, characteristicId, typedArray.buffer, (address /
len))
if (qq == false) {
console.log("返回", sum);
return
}
address = address + 176;
// //console.log("送数据", qq)
}
const data = await fetchData();
// return new Promise
var value2 = util.write_ota_sum(CMD_IAP_SUM, bufferLength, sum);
var typedArray2 = new Uint8Array(value2);
// console.log("送结束数据", value2)
send_ota_data_num(deviceId, serviceId, characteristicId, typedArray2.buffer, 100);
}
function write_cmd_program_sum(web, sum, deviceId, serviceId, characteristicId, data) {
var address = 0;
var len = 0;
var buf = 0;
var dv = 0;
let result;
console.log("更新122")
const mtu = 230;
var value1 = util.write_ota_erase(CMD_IAP_ERASE, 4, 0, 0);
var typedArray1 = new Uint8Array(value1);
console.log("翻盖柜", typedArray1)
console.log("翻盖柜", deviceId)
console.log("翻盖柜", serviceId)
console.log("翻盖柜", characteristicId)
send_ota_data(deviceId, serviceId, characteristicId, typedArray1.buffer);
// return;
setTimeout(function () {
uni.request({
url: web, //仅为示例,并非真实接口地址。
//url: 'https://www.zenghi.com/gj/BLE钉钉.bin', //仅为示例,并非真实接口地址。
// url: 'https://www.zenghi.com/gj/电子秤.bin', //仅为示例,并非真实接口地址。
responseType: 'arraybuffer',
success: (res) => {
main(res, sum, deviceId, serviceId, characteristicId)
},
fail: function (res) {
console.log("获取失败");
}
})
}
, 3000);
}
function writeCutomsData(deviceId, serviceId, characteristicId, data) {
// var obj = {},
@ -939,26 +1035,32 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) {
console.log("characteristicId", characteristicId)
// const buffer = new ArrayBuffer(8);
console.log("data", data)
if (data.indexOf("update") != -1 && data.indexOf("all_update") == -1) {
console.log("送数update据成功")
write_cmd_program(deviceId, serviceId, characteristicId, data)
}
else if (data.indexOf("upzydsm") != -1 ) {
console.log("送数upzydsm据成功")
write_cmd_program_zy(deviceId, serviceId, characteristicId, data)
}
else if (data.indexOf("upykdate") != -1 ) {
console.log("送数upykdate据成功")
write_cmd_program_yk(deviceId, serviceId, characteristicId, data)
}
else if (data.indexOf("fgdate") != -1 ) {
write_cmd_program_fg('https://fg.zenghi.com/gj/翻盖柜.bin',deviceId, serviceId, characteristicId, data)
}
// if (data.indexOf("update") != -1 && data.indexOf("all_update") == -1) {
// console.log("送数update据成功")
// write_cmd_program(deviceId, serviceId, characteristicId, data)
// }
// else if (data.indexOf("upzydsm") != -1 ) {
// console.log("送数upzydsm据成功")
// write_cmd_program_zy(deviceId, serviceId, characteristicId, data)
// }
// else if (data.indexOf("upykdate") != -1 ) {
// console.log("送数upykdate据成功")
// write_cmd_program_yk(deviceId, serviceId, characteristicId, data)
// }
// else if (data.indexOf("fgdate") != -1 ) {
// write_cmd_program_fg('https://fg.zenghi.com/gj/翻盖柜.bin',deviceId, serviceId, characteristicId, data)
// }
// else if (data.indexOf("ble_go7p") != -1 ) {
// console.log("送数update据成功")
// write_cmd_program7p(deviceId, serviceId, characteristicId, data)
// }
if(data.sum != undefined){
if(data.http != undefined){
console.log('升级');
write_cmd_program_sum(data.http, data.sum, deviceId, serviceId, characteristicId, data)
}
}
else {
var buffer = string2buffer(data)
uni.writeBLECharacteristicValue({
@ -1146,7 +1248,7 @@ function init() {
// && devices.devices[0].name != 'SMART_R2XS'
// && devices.devices[0].name != 'SMART_R2XS'
// )
if (devices.devices[0].name.indexOf("WATER") != -1){
if (devices.devices[0].name.indexOf("WATER") != -1 || devices.devices[0].name.indexOf("SMSJ:") != -1){
// if ( devices.devices[0].name.indexOf("gjkg") != -1 ){
// console.log("跳过",devices.devices[0].name)
// isnotexist = false;

View File

@ -12,17 +12,17 @@
如未找到想添加的设备点击重新搜索
</view>
<view class="list">
<view class="list_item" v-for="(item,index) in devicesList" :key="index">
<view class="list_item" v-for="(item,index) in jiaohuaqi" :key="index">
<image src="https://api.ccttiot.com/smartmeter/img/static/ufPWKlVzDbHNflX0jUIv" mode=""></image>
<view class="cen">
<view class="name">
丁丁浇花器
</view>
<view class="devmac">
MAC{{item.name}}
MAC{{item}}
</view>
</view>
<view class="add" @click="btnadd(item.name)">
<view class="add" @click="btnadd(item)">
添加
</view>
</view>
@ -64,9 +64,11 @@
devicesList:[],
deviceId:'',
name:'',
mac:'2952BB7A4EE0',
mac:'',
flags:true,
userid:''
userid:'',
arr:'',
jiaohuaqi:[]
}
},
//
@ -86,8 +88,11 @@
}
},
onLoad() {
},
onShow() {
this.getinfo()
this.btnss()
this.btnss()
},
methods:{
//
@ -108,7 +113,8 @@
let mac = e.slice(-12)
let data = {
mac:mac,
userId:this.userid
userId:this.userid,
pre:e.slice(0,5)
}
this.$u.post(`/app/bandDevice`,data).then((res) => {
if (res.code == 200) {
@ -129,11 +135,12 @@
}
})
},
btnss(){
btnss(){
uni.showLoading({
title: '搜索中...'
})
this.jiaohuaqi = []
this.flag = false
let that = this
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
@ -146,53 +153,48 @@
})
if (that.devicesList.length > 0) {
that.flags = true
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);
}
})
}
})
}
})
}else{
that.flags = false
// that.flags = false
}
uni.hideLoading()
that.flag = true
}, 5000)
},
}, 3000)
},
//
funListenDeviceMsgEvent: function(options) {
switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
// that.setData({
// connected: options.result
// })
if (!options.result) {
// uni.showModal({
// title: '',
// content: '',
// showCancel: false,
// //
// success: function(res) {
// }
// })
}
break
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) {
let devicesarr = options.data
this.devicesList = devicesarr
// console.log(devicesarr,'111');
// devicesarr.forEach(device => {
// const mac = device.name.substring(4);
// if (device.name.slice(5, 17) == this.mac) {
// this.deviceId = device.deviceId
// this.name = device.name
// console.log(device.name,this.mac,'222');
// this.devicesList.push(device);
// let uniqueDevicesList = Array.from(new Set(this.devicesList));
// this.devicesList = uniqueDevicesList;
// }
// })
let devicesarr = []
this.devicesList = options.data
options.data.forEach(item =>{
devicesarr.push(item.name.slice(-12))
})
this.arr = devicesarr.join(',')
}
break
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
console.log("连接回调:" + JSON.stringify(options));
console.log("连接回调:" + JSON.stringify(options))
if (options.result) {
{
xBlufi.notifyInitBleEsp32({
@ -206,17 +208,7 @@
}
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_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:
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) {
@ -233,26 +225,6 @@
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"
//
return {
voltage,
switchState,
current,
power,
remainingPower,
setMode
}
},
}
}
</script>

View File

@ -23,10 +23,10 @@
<image src="https://api.ccttiot.com/smartmeter/img/static/uiTIUYnR3ClrmqOTyF8F" mode=""></image>
</view>
</view>
<view class="wifi" style="margin-top: 24rpx;" @click="gjshow = true">
<view class="wifi" style="margin-top: 24rpx;" @click="gjconfirm">
<view class="">固件更新</view>
<view class="flex">{{gjtxt}}
<image src="https://api.ccttiot.com/smartmeter/img/static/uiTIUYnR3ClrmqOTyF8F" mode=""></image>
<view class="flex">
<!-- <image src="https://api.ccttiot.com/smartmeter/img/static/uiTIUYnR3ClrmqOTyF8F" mode=""></image> -->
</view>
</view>
<!-- 息屏选择器 -->
@ -54,11 +54,30 @@
</view>
<!-- 修改名称蒙层 -->
<view class="mask" v-if="nameflag"></view>
<!-- 进度条 -->
<view class="container" v-if="shengjiflag">
<image src="https://api.ccttiot.com/smartmeter/img/static/uquIy7wJmrNhjvy2maJf" mode=""></image>
<!-- 进度条背景 -->
<view class="progress-bar">
<!-- 进度条填充部分 -->
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
<!-- 显示进度百分比 -->
<view class="progress-text">{{ progress }}%</view>
<view class="wz">
固件升级中请保持蓝牙连接
</view>
<view class="wz">
切记在蓝牙范围内以防升级失败
</view>
</view>
</view>
</template>
<script>
var xBlufi = require("@/components/blufi/xBlufi.js")
export default {
data() {
return {
@ -85,17 +104,21 @@
}
],
gjlist: [{
value: '1',
label: 'v2.1.2'
value: '1',
label: 'v2.1.2'
},
{
value: '2',
label: 'v2.1.3'
}
],
value: '2',
label: 'v2.1.3'
}],
deviceid: '',
user: {},
namesb: ''
namesb: '',
ver:'',
file:'',
intervalId: null,
progress:0,
shengjiflag:false
}
},
//
@ -114,7 +137,12 @@
}
},
onLoad(option) {
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
this.deviceid = option.deviceid
if(option.ver != undefined && option.ver != null){
this.ver = option.ver
this.getbanben()
}
this.getshebxq()
},
methods: {
@ -169,9 +197,53 @@
xpconfirm(e) {
this.xptxt = e[0].label
},
getbanben(){
this.$u.get(`/app/getVersion?version=${this.ver.slice(3)}`).then(res => {
if (res.code == 200) {
this.file = res.data.file
console.log(this.file);
// this.file = 'https://www.zenghi.com/gj/water_flower.bin'
}
})
},
startProgress() {
this.intervalId = setInterval(() => {
if (this.progress < 100) {
} else {
clearInterval(this.intervalId); // 100%
console.log("加载完成");
}
}, 30); // 30
},
//
gjconfirm(e) {
this.gjtxt = e[0].label
// this.gjtxt = e[0].label
if(this.ver != ''){
if(this.file != ''){
var data = {
sum: 100,
http: this.file
}
xBlufi.notifySendCustomData({
customData: data
})
this.shengjiflag = true
this.startProgress()
}else{
uni.showToast({
title: '暂无新版本',
icon: 'none',
duration: 2000
})
}
}else{
uni.showToast({
title: '请连接蓝牙获取版本号',
icon: 'none',
duration: 2000
})
}
},
//
btnqx() {
@ -197,11 +269,136 @@
}
})
},
//
funListenDeviceMsgEvent: function(options) {
switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
console.log('duankai');
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) {
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
console.log("连接回调:" + JSON.stringify(options))
if (options.result == true){
}else{
}
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
console.log("选择固件升级收信息:", options.data, options.data.length);
if (typeof options.data === 'string') {
if (options.data.indexOf("prom:") !== -1) {
console.log('固件升级中')
var indexOld = options.data.substring(options.data.indexOf('prom:'))
console.log("indexOld", indexOld);
var load_num = indexOld.substring(
indexOld.indexOf("prom:") + 5,
indexOld.indexOf("@")
)
this.progress = Number(load_num);
console.log("load_num", load_num);
console.log("升级进度:", this.progress)
if (this.progress === 6000) {
console.log('固件成功')
this.progress = 100
uni.showToast({
title: '固件升级成功',
icon: 'success',
duration: 2000
})
setTimeout(()=>{
this.shengjiflag = false
uni.reLaunch({
url:'/pages/index/index'
})
},2000)
}
if (this.progress === 9000) {
console.log('固件升级失败')
this.progress = 99
uni.showToast({
title: '固件升级失败',
icon: 'none',
duration: 2000
})
setTimeout(()=>{
this.shengjiflag = false
uni.reLaunch({
url:'/pages/index/index'
})
},1000)
}
}
} else {
console.error("options.data 不是字符串:", options.data);
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
if (!options.result) {
console.log('蓝牙未开启')
return
}
break
}
},
}
}
</script>
<style lang="less">
.container {
display: flex;
flex-direction: column;
align-items: center;
height: 100vh; /* 全屏高度 */
background-color: #f0f0f0; /* 背景颜色 */
position: fixed;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 100%;
image{
width: 400rpx;
height: 500rpx;
margin-top: 260rpx;
margin-bottom: 80rpx;
}
.wz{
color: red;
margin-top: 20rpx;
}
}
/* 进度条背景 */
.progress-bar {
width: 80%; /* 进度条宽度 */
height: 20px; /* 进度条高度 */
background-color: #e0e0e0; /* 背景颜色 */
border-radius: 10px; /* 圆角 */
overflow: hidden; /* 隐藏超出部分 */
}
/* 进度条填充部分 */
.progress-fill {
height: 100%;
background-color: #7FAD76; /* 填充颜色 */
transition: width 0.1s ease; /* 平滑过渡 */
}
/* 进度百分比文字 */
.progress-text {
margin-top: 20px;
font-size: 24px;
color: #333;
}
.annius {
padding: 0 40rpx;
width: 100%;

View File

@ -25,12 +25,12 @@
<!-- 选择设备 -->
<view class="selectbox">
<view class="selectname" @click="btnksxz">
切换设备 <image src="https://api.ccttiot.com/smartmeter/img/static/uwHOBxvbJjkhx1uDiQHI" mode="">
</image>
切换设备 <image v-if="!xuanzeflag" src="https://api.ccttiot.com/smartmeter/img/static/uwHOBxvbJjkhx1uDiQHI" mode=""></image>
<image v-else class="rotated-image" src="https://api.ccttiot.com/smartmeter/img/static/uwHOBxvbJjkhx1uDiQHI" mode=""></image>
</view>
<view class="selectshezhi" style="display: flex;">
<!-- <view class="selectnames" @click="btnluru" v-if="userobj.userType == 00">
<!-- <view class="selectnames" @click="btnluru" v-if="userobj.userType == 00">
录入设备
</view> -->
<image @click="btnsz" src="https://api.ccttiot.com/smartmeter/img/static/uvCJ8ro0MpfGZd53vypJ" mode=""></image>
@ -49,9 +49,9 @@
已连接
</view>
</view>
<view class="shebeiadd" @click="btnaddsb">
<!-- <view class="shebeiadd" @click="btnaddsb">
<image src="https://api.ccttiot.com/smartmeter/img/static/udlX67UXzuRUZCuEtWDH" mode=""></image>
</view>
</view> -->
</view>
<!-- 设备信息 -->
<view class="devicebox">
@ -63,7 +63,7 @@
<view class="">MAC{{user.mac == undefined ? '--' : user.mac}}</view>
</view>
</view>
<view class="devicert">
<!-- <view class="devicert">
<view class="shoudong">
<image @click="btnkq" v-if="kgflag"
src="https://api.ccttiot.com/smartmeter/img/static/uIiHf1LAHhLyVZODV9Pc" mode="">
@ -75,7 +75,7 @@
<view class="shengyu">
剩余{{ sdminutes ? sdminutes + ':' : '' }}{{ sdseconds ? sdseconds : '--' }}
</view>
</view>
</view> -->
</view>
<view class="deviceweek">
<view class="weeklist">
@ -194,7 +194,6 @@
</view>
</view>
</view>
<!-- <button @click="kq">开启</button><button @click="gb">关闭</button><button @click="hq">获取</button> -->
<!-- 开关选择 -->
<view class="switchbox">
<view class="switch_he">
@ -217,14 +216,28 @@
</view>
</view>
</view>
<!-- 定时 -->
<view class="dingshi_he" @click="btntime">
<view class="naoz">
<image src="https://api.ccttiot.com/smartmeter/img/static/uJPgzMejk9gaogWnCO9M" mode=""></image> 6
<view class="" style="display: flex;justify-content: space-between;">
<!-- 定时 -->
<view class="dingshi_he" @click="btntime">
<view class="naoz">
<image src="https://api.ccttiot.com/smartmeter/img/static/uJPgzMejk9gaogWnCO9M" mode=""></image> 6
</view>
<view class="dstime">
定时管理 <image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode="">
</image>
</view>
</view>
<view class="dstime">
定时管理 <image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode="">
</image>
<!-- 手动浇水 -->
<view class="dingshi_he">
<view class="naoz" style="font-weight: 400;font-size: 26rpx;align-items: center;">
<image style="width: 170rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uVYXvo4F6U6fJ5fP27BT" mode="aspectFill"></image>{{ sdminutes ? sdminutes + ':' : '' }}{{ sdseconds ? sdseconds : '' }}
</view>
<view class="dstime">
手动浇水 <u-switch v-if="kgflag" v-model="jskeds" @change="btngb" inactive-color="#eee"
active-color="#eee" size="40"></u-switch>
<u-switch v-else v-model="jsked" @change="btnkq" active-color="#7FAD76"
inactive-color="#7FAD76" size="40"></u-switch>
</view>
</view>
</view>
<!-- 浇水日志 -->
@ -249,11 +262,10 @@
<!-- 切换设备 -->
<view class="tabsb" v-if="xuanzeflag">
<view class="sblist">
<view class="sbist_val" v-for="(item,index) in devicelist" :key="index"
:id="activeshu == index ? 'activebor' : ''" @click="btnactive(item.deviceId,index)">
<view class="sbist_val" v-for="(item,index) in devicelist" :key="index" @click="btnactive(item.deviceId,index)">
<view class="lt">
<view class="">{{item.deviceName}}</view>
<view class="" style="margin-top: 14rpx;">型号:{{item.model}}</view>
<!-- <view class="" style="margin-top: 14rpx;">型号:{{item.model}}</view> -->
<view class="" style="margin-top: 14rpx;">MAC:{{item.mac}}</view>
</view>
<view class="rt">
@ -261,10 +273,11 @@
</view>
</view>
</view>
<view class="qdan" @click="btnxuanze">
确定
<view class="qdan" @click="btnaddsb">
添加新设备
</view>
</view>
<view class="mask" v-if="xuanzeflag"></view>
<!-- 手动浇水 -->
<view class="manualjs" v-if="sdjsflag">
<view class="toptit">
@ -286,7 +299,7 @@
</view>
<view class="manualmask" v-if="sdjsflag"></view>
<!-- 选择浇水时间-->
<u-picker v-model="showjs" mode="time" :params="params" @confirm="confirm"></u-picker>
<u-picker v-model="showjs" mode="time" :default-time="00" :params="params" @confirm="confirm"></u-picker>
<tab-bar :indexs='0'></tab-bar>
@ -302,9 +315,11 @@
ones: true,
two: false,
twos: true,
jsked:true,
jskeds:false,
yschecked: true,
etchecked: true,
kgflag: false,
kgflag: true,
activeshu: 0,
xuanzeflag: false,
selectedMinute: '1',
@ -343,10 +358,12 @@
user:{},
lastChar:'',
timer:'',
bjflag:false,
bjflag:true,
userobj:{},
devicesarr:[],
intervalId: null,
imgflag:true,
ver:''
}
},
//
@ -379,19 +396,30 @@
})
}
})
this.vardataflag = 1
xBlufi.initXBlufi(1)
},
onShow() {
let that = this
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
xBlufi.notifyStartDiscoverBle({
'isStart': true
})
},
onShow() {
//
this.getinfo()
this.getinfo()
this.getshuju() //
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
},
mounted() {
this.getshuju(); //
},
onHide() {
//
this.clearTimer()
},
onUnload() {
//
this.clearTimer()
},
methods: {
//
@ -406,14 +434,14 @@
//
btnshowjs() {
this.showjs = true
},
},
//
formattedTime(minutes, seconds) {
//
const formattedMinutes = String(minutes).padStart(2, '0');
const formattedSeconds = String(seconds).padStart(2, '0');
const formattedMinutes = String(minutes).padStart(2, '0')
const formattedSeconds = String(seconds).padStart(2, '0')
//
console.log(`${formattedMinutes}:${formattedSeconds}`,'111111111');
console.log(`${formattedMinutes}:${formattedSeconds}`,'111111111')
return `${formattedMinutes}:${formattedSeconds}`
},
//
@ -664,6 +692,11 @@
//
btnqx() {
this.sdjsflag = false
this.sdminutes = ''
this.sdseconds = ''
this.kgflag = true
this.jsked = true
this.jskeds = false
},
//
btnqd() {
@ -684,7 +717,6 @@
uni.hideLoading()
this.startTimer(this.jstime)
this.sdjsflag = false
this.kgflag = true
}, 1500)
}
},
@ -715,6 +747,7 @@
//
btnkq() {
console.log('关闭')
if(this.vardataflag != 3){
uni.showToast({
title: '设备未连接',
@ -732,34 +765,41 @@
clearInterval(this.timer)
this.sdminutes = ''
this.sdseconds = ''
this.kgflag = false
this.kgflag = true
this.jsked = true
this.jskeds = false
uni.hideLoading()
}, 1500)
}
},
//
btngb() {
console.log('开启')
if(this.vardataflag != 3){
uni.showToast({
title: '设备未连接',
icon: 'none',
duration:2000
})
this.jsked = true
this.jskeds = false
}else{
this.sdjsflag = true
this.kgflag = false
}
},
//
btnsz() {
xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent)
uni.navigateTo({
url: '/page_user/upload?deviceid=' + this.shebid
url: '/page_user/upload?deviceid=' + this.shebid + '&ver=' + this.ver
})
},
//
btnactive(deviceId,index) {
this.shebid = deviceId
this.activeshu = index
this.btnxuanze()
},
// shebid
btnxuanze() {
@ -787,7 +827,9 @@
this.vardataflag = 1
this.sdseconds = ''
this.sdminutes = ''
this.kgflag = false
this.kgflag = true
this.jsked = true
this.jskeds = false
this.getshebxq()
}else{
uni.showToast({
@ -867,111 +909,110 @@
break
}
},
//
//
getshuju() {
const that = this;
const that = this
that.intervalId = setInterval(() => {
if (that.vardataflag == 3) {
xBlufi.notifySendCustomData({
customData: "11get"
});
})
}
console.log("定时器一段时间执行一次");
}, 10000);
console.log("定时器一段时间执行一次")
}, 10000)
},
//
clearTimer() {
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null; // ID
console.log("定时器已清除");
}
},
//
getchuli() {
const inputString = this.datalist
const pairs = inputString.split(';')
const showObject = {}
const pSetObjects = {}
pairs.forEach(pair => {
const [key, value] = pair.split(':')
if (key === 'show') {
showObject.showArray = value.split(',').map(Number)
} else if (key.startsWith('p_set')) {
const numbers = value.split(',').map(Number)
pSetObjects[key] = numbers
}
})
this.ver_data = pSetObjects //
this.jstimeobj = pSetObjects
console.log(inputString,this.ver_data, '002002002')
this.showobj = showObject //
if (this.showobj.showArray[1] == 1) {
this.yschecked = false
} else {
this.yschecked = true
}
if (this.showobj.showArray[0] == 1) {
this.etchecked = false
} else {
this.etchecked = true
}
const inputString = this.datalist
const [ver, restOfString] = inputString.split('@')
this.ver = ver || ''
console.log(this.ver, restOfString, 'ververver')
const processedString = restOfString
const pairs = processedString.split(';')
console.log(pairs,'10101010');
const showObject = {}
const pSetObjects = {}
//
pairs.forEach(pair => {
const [key, value] = pair.split(':')
if (key === 'show') {
showObject.showArray = value.split(',').map(Number)
} else if (key.startsWith('p_set')) {
pSetObjects[key] = value.split(',').map(Number)
}
})
this.ver_data = pSetObjects //
this.jstimeobj = pSetObjects
this.showobj = showObject//
//
this.yschecked = this.showobj.showArray[1] !== 1
this.etchecked = this.showobj.showArray[0] !== 1
//
const ver_Data = this.ver_data
function secondsToMinutesAndSeconds(seconds) {
const minutes = Math.floor(seconds / 60)
const remainingSeconds = seconds % 60
return `${minutes}${remainingSeconds}`
const calculateTimeDifference = (date1, date2) => {
const diffMs = Math.abs(date1 - date2)
const diffMinutes = Math.floor(diffMs / (1000 * 60))
const diffHours = Math.floor(diffMinutes / 60)
const remainingMinutes = diffMinutes % 60
return { hours: diffHours, minutes: remainingMinutes }
}
function timeArrayToDate(timeArray) {
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
const formatTime = (seconds) => {
const minutes = Math.floor(seconds / 60)
const remainingSeconds = seconds % 60
return `${minutes}${remainingSeconds}`
}
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 getTimeFromArray = (timeArray) => {
const [hour, minute, , second] = timeArray
const date = new Date()
date.setHours(hour, minute, second, 0) // 0
return date
}
let nextTimeDiff = null
let nextTime = null
let prevTimeDiff = null
let prevTime = null
let nextTimeDiff = 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]
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 || (new Date() - timeDate < new Date() - (prevTime || new Date(0)))) {
prevTimeDiff = timeDifference(new Date(), timeDate)
prevTime = timeDate
}
}
}
let prevTime = null
for (const key in this.ver_data) {
if (this.ver_data.hasOwnProperty(key) && this.ver_data[key][3] === 1) {
const timeArray = this.ver_data[key]
const timeDate = getTimeFromArray(timeArray)
const diff = calculateTimeDifference(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 = formatTime(timeArray[2])
}
} else if (!prevTime || timeDate > prevTime) {
prevTime = timeDate;
}
}
}
// 访 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)
this.sctimejs = prevTime ? prevTime.toTimeString().slice(0, 5) : '无上次浇水时间'
this.xctimesj = nextTime ? nextTime.toTimeString().slice(0, 5) : '无下次浇水时间'
console.log('下次浇水时间', this.xctimesj, '距离下次浇水时间', this.xctime, '上次浇水时间', this.sctimejs)
}
}
}
</script>
<style lang="scss">
.rotated-image {
transform: rotate(180deg); /* 旋转 180 度 */
transition: transform 1s ease;
}
.container {
display: flex;
align-items: center;
@ -1040,6 +1081,16 @@
/* 最终位置 */
}
}
.mask{
width: 100%;
height: 100vh;
background: #3D3D3D;
opacity: 0.2;
position: fixed;
top: 20%;
left: 0;
z-index: 1;
}
.manualmask {
width: 100%;
height: 100vh;
@ -1074,10 +1125,9 @@
.page {
padding: 0 40rpx;
box-sizing: border-box;
// background-color: #FFFFFF;
.tabsb {
width: 750rpx;
height: 90vh;
max-height: 90vh;
background: #FFFFFF;
position: fixed;
top: 270rpx;
@ -1086,7 +1136,7 @@
padding-bottom: 60rpx !important;
box-sizing: border-box;
border-radius: 0rpx 0rpx 50rpx 50rpx;
z-index: 1;
z-index: 2;
padding-top: 48rpx;
box-sizing: border-box;
animation: fadeInDown .5s ease-out forwards;
@ -1095,7 +1145,7 @@
height: 102rpx;
font-size: 48rpx;
color: #FFFFFF;
font-weight: 600;
font-weight: 500;
line-height: 102rpx;
text-align: center;
background-color: #48893B;
@ -1104,13 +1154,13 @@
}
.sblist {
width: 100%;
height: 68vh;
max-height: 68vh;
overflow: scroll;
.sbist_val {
display: flex;
justify-content: space-between;
align-items: center;
padding: 40rpx 34rpx;
padding: 20rpx 30rpx;
margin-bottom: 28rpx;
box-sizing: border-box;
background: #F7F7F7;
@ -1381,6 +1431,7 @@
font-size: 48rpx;
color: #3D3D3D;
font-weight: 600;
z-index: 2;
image {
width: 32rpx;
height: 26rpx;

View File

@ -166,8 +166,6 @@
},
watch: {
},
methods: {
btns(){