smartswrtch-app/page_user/sbdetail.vue
2025-03-31 17:41:24 +08:00

2492 lines
68 KiB
Vue
Raw Permalink 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>
<view class="page">
<u-navbar :title="tittxt" :border-bottom="false" :background="bgc" back-icon-color="#000" title-color='#000'
title-size='36' height='50' id="navbar" :custom-back="btns">
</u-navbar>
<view class="zhuhu">
<view class="card1">
<view class="mid">
<view class="mid_right">
<view class="mid_top" @click="btnxgname">
{{ deviceInfo.deviceName == null ? '' : deviceInfo.deviceName }} <u-icon name="edit-pen-fill" color="#333" size="32"></u-icon>
</view>
<view class="txt" v-if="deviceInfo" style="width: 100%;margin-top: 6rpx;">
S / N{{ deviceInfo.deviceNo == null ? '' : deviceInfo.deviceNo }}</view>
<view class="txt" v-if="deviceInfo" style="width: 100%;margin-top: 6rpx;">
MAC{{ deviceInfo.mac == null ? '' : deviceInfo.mac }}</view>
<view class="mid_bot">
<div class="tip" v-if="deviceInfo.onlineStatus==1">
<text style="color: #00BA88;border: 1px solid #00BA88;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">在线</text>
</div>
<div class="tip" v-if="deviceInfo.onlineStatus==0">
<text style="color: #F76D6D;border: 1px solid #F76D6D;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">离线</text>
</div>
<div class="tip" v-if="deviceInfo.status==1">
<text style="color: #00BA88;border: 1px solid #00BA88;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">空闲</text>
</div>
<div class="tip" v-if="deviceInfo.status==2">
<text style="color: #00BA88;border: 1px solid #00BA88;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">使用中</text>
</div>
<div class="tip" v-if="deviceInfo.status==3">
<text style="color: red;border: 1px solid red;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">调试中</text>
</div>
<div class="tip" v-if="deviceInfo.storeName != null">
<text style="color: #8883F0;border: 1px solid #8883F0;padding: 2rpx 8rpx;box-sizing: border-box;border-radius: 10rpx;">{{deviceInfo.storeName.length > 5 ? deviceInfo.storeName.slice(0,5) + '...' : deviceInfo.storeName}}</text>
</div>
</view>
<view style="font-size: 28rpx;color: #95989D;margin-top: 18rpx;">
<view style="display: flex;align-items: center;">
<image style="width: 38rpx;height: 38rpx;margin-right: 10rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uFCAaWnRnqQK4SwPp7dm" mode=""></image>
<text style="color: #00BA88;" v-if="ver_dataflag == 3">蓝牙已连接</text>
<text style="color: #0079F5;" v-if="ver_dataflag == 2">蓝牙连接中</text>
<text style="color: #F76D6D;" v-if="ver_dataflag == 1">蓝牙未连接</text>
</view>
</view>
</view>
<view class="mid_left" style="position: relative;">
<view v-if="opflag"
style="border: 0;outline: none;width: 196rpx;padding-left: 0rpx;height: 196rpx;border-radius: 16rpx;"
@click="btnpic">
<image :src="imglist" mode="aspectFit"
style="width: 196rpx;height: 196rpx;border-radius: 10rpx;"></image>
</view>
<image v-else :src="imglist" mode="aspectFit"
style="width: 196rpx;height: 196rpx;border-radius: 0rpx;"></image>
<text class="lanyalx">{{deviceInfo.model == undefined ? '' : deviceInfo.model}}</text>
<ksp-cropper mode="free" :width="142" :height="142" :maxWidth="1024" :maxHeight="1024"
:url="url" @cancel="oncancel" @ok="onok"></ksp-cropper>
</view>
</view>
<view class="bot">
</view>
</view>
<view class="card2">
<view class="" style="display: flex;justify-content: space-between;padding-right: 66rpx;box-sizing: border-box;align-items: center;">
<view class="tit" style="border-left: 14rpx solid #8883F0;padding-left: 24rpx;">实时参数</view>
<view @click="shuaxin" style="display: flex;color: #8883F0;justify-content: center;align-items: center;box-sizing: border-box;">
<!-- 点击刷新 -->
<image style="width: 60rpx;height: 60rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uOXH8rIsA5tSRyYynLgD" mode="aspectFit"></image>
</view>
</view>
<view class="bot_right">
<view class="cont" style="text-align: center;">
<view class="tit">
{{deviceInfo.voltage == null ? 0 : deviceInfo.voltage}}
</view>
<view class="txt">
电压V
</view>
</view>
<view class="cont" style="text-align: center;">
<view class="tit">
{{deviceInfo.electricity == null ? 0 : deviceInfo.electricity}}
</view>
<view class="txt">
电流A
</view>
</view>
<view class="cont" style="text-align: center;">
<view class="tit">
{{deviceInfo.realTimePower == null ? 0 : deviceInfo.realTimePower}}
</view>
<view class="txt">
功率W
</view>
</view>
</view>
<view class="" style="display: flex;margin-top: 20rpx;padding: 50rpx;box-sizing: border-box;width: 100%;
height: 80rpx;align-items: center;justify-content: space-between;background-color: #fff;border-radius: 20rpx;font-size: 32rpx;color: #3D3D3D;">
<view class="bot">开关状态:{{tdtxt}}</view>
<view class="cont" @click="btnkq">
<view class="top" style="padding-top: 10rpx;">
<view class="rt">
<image v-if="imgflag" style="width: 160rpx;height: 80rpx;"
src="https://api.ccttiot.com/smartmeter/img/static/uccaWar4FDp37op7haWM " mode="aspectFit">
</image>
<image style="width: 160rpx;height: 80rpx;" v-else
src="https://api.ccttiot.com/smartmeter/img/static/ur9HRtZKY7YcxGewJARz" mode="aspectFit">
</image>
</view>
</view>
</view>
</view>
</view>
<view class="card2" style="padding-bottom: 40rpx;">
<view class="tit" style="border-left: 14rpx solid #8883F0;padding-left: 24rpx;">设备剩余</view>
<view class="bot_right">
<view class="cont" style="text-align: center;">
<view class="tit">
{{deviceInfo.surplusEleDb == null || Number(deviceInfo.surplusEleDb) < 0 ? '--' : deviceInfo.surplusEleDb}}
</view>
<view class="txt">
剩余度数
</view>
</view>
<view class="cont" style="text-align: center;">
<view class="tit">
{{formattedTime}}
</view>
<view class="txt">
剩余时长
</view>
</view>
</view>
</view>
<!-- 当前订单 -->
<view v-if="sklistflag" @click="btnshdd" class="card2" style="padding-bottom: 30rpx;box-sizing: border-box;margin-top: 20rpx;">
<view class="tit" style="border-left: 14rpx solid #8883F0;padding-left: 24rpx;display: flex;justify-content: space-between;padding-right: 40rpx;margin-bottom: 20rpx;">当前订单 <text style="color: #8883F0;font-size: 32rpx;font-weight: 400;">查看</text> </view>
<view class="aa">
<text>用户</text> <text>{{sklist.userName}}</text>
</view>
<view class="aa">
<text>计价方式</text> <text v-if="sklist.suitFeeType == 1">计时收费</text>
<text v-if="sklist.suitFeeType == 2">按量收费</text>
<text v-if="sklist.suitFeeType == 3">分时段按量收费</text>
<text v-if="sklist.suitFeeType == 4">分时段按时收费</text>
</view>
<view class="aa">
<text>下单时间</text> <text>{{sklist.suitStartTime}}</text>
</view>
</view>
<view class="card3" v-if="opflag">
<view class="tit" style="border-left: 14rpx solid #8883F0;padding-left: 24rpx;font-weight: 600;">其他功能</view>
<view class="cont_box">
<view class="cont" @click="topage(0)">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/u2ALEsvAJrHnW7nhrTVD" mode="aspectFit"
style="width: 44rpx;height: 40rpx;"></image>
<view class="bot">充值记录</view>
</view>
</view>
<view class="cont" @click="topage(3)" v-if="userTpye_userid == deviceInfo.userId">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/uJmpaxyrv34a1EW5lWQv" mode="aspectFit"
style="width: 44rpx;height: 44rpx;"></image>
<view class="bot">收费方式</view>
</view>
</view>
<view class="cont" @click="topage(1)">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/uhsqQVT62DOTdW8qW7ez" mode="aspectFit"
style="width: 44rpx;height: 44rpx;"></image>
<view class="bot">归零</view>
</view>
</view>
<view class="cont" @click="topage(6)" v-if="deviceInfo.allowSwitch == true">
<view class="top">
<image style="width: 44rpx;height: 44rpx;"
src="https://api.ccttiot.com/smartmeter/img/static/u9vzIeLLorfYuoZnxBDZ" mode="aspectFit">
</image>
<view class="bot">充值</view>
</view>
</view>
<view class="cont" @click="topage(5)" v-if="modelId.some(tag => tag == 2)">
<view class="top">
<image style="width: 44rpx;height: 44rpx;"
src="https://api.ccttiot.com/smartmeter/img/static/ule3wEEDaXzfXCUCM1Ks" mode="aspectFit">
</image>
<view class="bot">配网</view>
</view>
</view>
<view class="cont" @click="qrFun">
<view class="top">
<image style="width: 44rpx;height: 44rpx;"
src="https://api.ccttiot.com/smartmeter/img/static/uGjm0qpPFeDJZ2hUFexi" mode="aspectFit">
</image>
<view class="bot">二维码</view>
</view>
</view>
<view class="cont" @click="topage(2)">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/ueQ5V8QAidDZGt0FpqXb" mode="aspectFit"
style="width: 44rpx;height: 40rpx;"></image>
<view class="bot">上报异常</view>
</view>
</view>
<view class="cont" @click="sremakes">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/u6iXsrzPKTQXsY1Zq1i7" mode="aspectFit"
style="width: 44rpx;height: 40rpx;"></image>
<view class="bot">所属店铺</view>
</view>
</view>
<view class="cont" @click="deldevice">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/ucjqb5QAYLn1694aY5LX" mode="aspectFit"
style="width: 44rpx;height: 40rpx;"></image>
<view class="bot">解除绑定</view>
</view>
</view>
<view class="cont" @click="jiaozhunflag = true">
<view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/uIIu0awWVaCskkQMyJYp" mode="aspectFit"
style="width: 44rpx;height: 40rpx;"></image>
<view class="bot">电量校准</view>
</view>
</view>
<view class="cont" @click="btngengxin">
<view class="top" style="border: 0;">
<image style="width: 44rpx;height: 44rpx;"
src="https://api.ccttiot.com/smartmeter/img/static/uOUM2aclDz2ZnRxOll9g" mode="aspectFit">
</image>
<view class="bot">固件升级</view>
</view>
</view>
</view>
</view>
</view>
<view class="tanc" v-if="vipflag">
<view class="tit">请输入您需要充值的时长或度数</view>
<input type="number" :focus="focus" v-model="cztime" placeholder="请输入时长或度数" />
<view class="inpss" @click="btnxzdw">{{danwei}}</view>
<!-- #ifdef MP-WEIXIN -->
<u-icon name="arrow-down" style="position: fixed;top: 234rpx;right: 60rpx;" color="#999" size="28"></u-icon>
<!-- #endif -->
<view class="xian"></view>
<view class="anniu">
<text @click="btnqx">取消</text> <text style="border-left: 1px solid #eee;color: #8883F0;"
@click="trueje">确定</text>
</view>
</view>
<view class="maskss" v-if="vipflag"></view>
<!-- 蓝牙连接 -->
<view class="bluetoothbox" v-if="bluetoothflag">
<view class="stop">
正在连接该设备蓝牙
</view>
<view class="xtop">
请将手机与设备尽量靠近
</view>
<image src="https://api.ccttiot.com/smartmeter/img/static/ucDphMKsozqwwllJTAKL" mode="aspectFit"></image>
</view>
<!-- 蓝牙连接失败 -->
<view class="bluetoothbox" v-if="shibaiflag">
<image class="img" src="https://api.ccttiot.com/smartmeter/img/static/uTb3vSlbcHdPMFQMBjyL" mode="aspectFit"></image>
<view class="one">
蓝牙连接失败
</view>
<view class="two">
请确保手机足够靠近设备
</view>
<view class="thr">
并且设备处于上电状态
</view>
<view class="anfour">
<view class="qx" @click="btnlyqx">
取消
</view>
<view class="cx" @click="btnkq">
重新连接
</view>
</view>
</view>
<!-- 选择单位 -->
<u-select v-model="showflag" :list="listdanwei" title='选择单位' @confirm="btnconfirm"></u-select>
<!-- 选择店铺 -->
<u-select v-model="showshop" :list="wateringList" @confirm="confirms"></u-select>
<!-- 展示二维码 -->
<view class="imgewm" v-if="wemflag" @longpress="saveCanvas">
<canvas canvas-id="qrcode" style="height: 100%;margin: 0 auto;" />
<view class="" style="width: 100%;text-align: center;margin-top: 20rpx;">
SN:{{deviceNo}}
</view>
<view class=""
style="border: 1px solid; padding: 20rpx;box-sizing: border-box;width: 100%;text-align: center;margin-top: 40rpx;"
@click="wemflag = false">
关闭二维码
</view>
</view>
<view class="imgewmflag" v-if="wemflag" @click.stop="ewmyc"></view>
<view v-if="btnmsk"
style="width: 100%;height: 100vh;position: fixed;top: 0;left: 0;background-color: #000;opacity: .1;z-index: 999;">
</view>
<u-popup v-model="showmc" mode="center" border-radius='20'>
<view class="popcard" v-if="showmc">
<view class="tit">
修改名称
</view>
<view class="ipt">
<u-input v-model="xgname" placeholder=" " border='surround' placeholder-style='font-size: 24rpx;' />
</view>
<view class="btnbox">
<view class="btn2" @click="close">
取消
</view>
<view class="btn1" @click="subname">
确定
</view>
</view>
</view>
</u-popup>
<!-- 电量校准 -->
<view class="dianliang" v-if="jiaozhunflag">
<image class="bj" src="https://api.ccttiot.com/smartmeter/img/static/uvJFkqJb264nOgRunshs" mode=""></image>
<view class="shuru">
<image @click="btnjian" src="https://api.ccttiot.com/smartmeter/img/static/umGCPelSgd4GAwClNYcN" mode=""></image>
<input type="text" v-model="wxs" :disabled="true"/>
<image @click="btnadd" src="https://api.ccttiot.com/smartmeter/img/static/uyHk8ogQq0MPOURwPXbT" mode=""></image>
</view>
<view class="anniu" @click="btndian">
确认校准
</view>
</view>
<view class="maskss" v-if="jiaozhunflag" @click="jiaozhunflag = false"></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("@/page_components/blufi/xBlufi.js")
export default {
data() {
return {
showmc:false,
xgname:'',
suitSurplus:'',
showflag: false,
imgflag: false,
wemflag: false,
btnmsk: false,
bluetoothflag: false,
shibaiflag: false,
danwei: '请选择时长单位',
wateringList: [],
listdanwei: [{
value: 2,
label: '小时'
}, {
value: 3,
label: '分钟'
}, {
value: 4,
label: '秒钟'
}, {
value: 0,
label: '度'
}],
bgc: {
backgroundColor: "#F9F8FF",
},
ec: {
lazyLoad: true
},
deviceInfo: {},
loadings: false,
info: '',
checked: false,
tittxt: "设备详情",
titlist: [],
tdtxt: '开启',
curtitidx: 0,
id: '',
focus: false,
timeday: '',
imglist: '',
token: '',
userImgs: '',
imgflag: true,
mac: "",
name: '',
deviceId: '',
storeId: '',
qrResult: '',
devicesList: [],
setMode: null,
vipflag: false,
cztime: '',
opflag: true,
timer: null,
url: "",
deviceNo: '',
modelId: [],
damweiid: '',
intervalId: null,
sklist:{},
sklistflag:false,
ljtype:'2',
userTpye_userid:'',
ver_dataflag:2,
showshop: false,
devicesarr:[],
fanhui:'',
xishu:1,
wxs:'',
jiaozhunflag:false,
file:'' ,//固件升级地址
intervalId: null,
progress:0,
shengjiflag:false,
lanyaobj:{},
benbencode:'',
modelChip:''
}
},
onLoad(option) {
xBlufi.notifyStartDiscoverBle({'isStart': true})
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
let id = option.id
this.id = id
this.gettanc()
if(option.fanhui){
this.fanhui = option.fanhui
}
if (option.flag) {
this.opflag = false
} else {
this.opflag = true
}
},
// 分享到好友(会话)
onShareAppMessage: function() {
return {
title: '创想物联',
path: '/pages/shouye/index'
}
},
// 分享到朋友圈
onShareTimeline: function() {
return {
title: '创想物联',
query: '',
path: '/pages/shouye/index'
}
},
computed: {
formattedTime() {
if (this.timeday.days > 0) {
// 只展示天和小时
return `${this.timeday.days}天${this.timeday.hours}小时`
} else if (this.timeday.hours > 0) {
// 展示小时和分钟
return `${this.timeday.hours}小时${this.timeday.minutes}分钟`
} else if (this.timeday.minutes > 0) {
// 展示分钟和秒
return `${this.timeday.minutes}分钟${this.timeday.seconds}秒`
} else if (this.timeday.seconds == 0) {
this.deviceInfo.status = 1
this.imgflag = false
this.tdtxt = '关闭'
return this.timeday.seconds > 0 ? `${this.timeday.seconds}秒` : '0'
} else {
// 展示秒或0如果秒也为0
return this.timeday.seconds > 0 ? `${this.timeday.seconds}秒` : '0'
}
}
},
beforeDestroy() {
// 组件销毁前清除定时器,防止内存泄漏
if (this.timer) {
clearInterval(this.timer)
this.timer = null
console.log('已销毁')
}
},
onHide() {
if (this.timer || this.intervalId) {
clearInterval(this.intervalId)
clearInterval(this.timer)
this.timer = null
this.intervalId = null
console.log('已销毁')
}
},
onUnload: function() {
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
xBlufi.notifyConnectBle({
isStart: false,
deviceId: this.deviceId,
name: this.name
})
if (this.timer || this.intervalId) {
clearInterval(this.intervalId)
clearInterval(this.timer)
this.timer = null
this.intervalId = null
console.log('已销毁')
}
},
onShow() {
this.userTpye_userid = uni.getStorageSync('userType').userId
this.shibaiflag = false
this.getshuax()
this.getQiniuToken()
},
mounted() {
this.drawCanvas()
},
methods: {
// 请求固件更新文件
getwenjian(){
this.$u.get(`/app/hardVersion/lastOne?modelId=${this.deviceInfo.modelId}&code=`).then(res =>{
if(res.code == 200){
if(res.data.fileUrl == null || res.data.fileUrl == ''){
uni.showToast({
title: '暂无最新版本文件',
icon: 'none',
duration: 2000
})
}else{
this.file = res.data.fileUrl
this.benbencode = res.data.code
}
}
})
},
// 点击进行固件更新
btngengxin(){
if(this.ver_dataflag != 3){
uni.showToast({
title: '请在蓝牙连接的情况下进行',
icon: 'none',
duration: 2000
})
}else{
if(this.lanyaobj.ver && this.lanyaobj.ver != ''){
let that = this
uni.showModal({
title: `当前版本${this.lanyaobj.ver}`,
content: `您是否要升级到${this.benbencode}版本?`,
success: (resModal) => {
if (resModal.confirm) {
var data = {
sum: 100,
http: that.file
}
xBlufi.notifySendCustomData({
customData: data
})
that.shengjiflag = true
that.startProgress()
} else if (resModal.cancel) {
}
}
})
}else{
uni.showToast({
title: '该设备暂无新版本',
icon: 'none',
duration: 2000
})
}
}
},
// 点击减电量系数
btnjian() {
const value = Number(this.wxs.slice(0, -1)) - 0.05
this.wxs = value.toFixed(2) + '%'
},
btnadd() {
const value = Number(this.wxs.slice(0, -1)) + 0.05
this.wxs = value.toFixed(2) + '%'
},
// 点击校准电量
btndian(){
let data = {
deviceId: this.id,
wxs: this.wxs.slice(0,-1) / 100,
}
this.$u.put('/mch/device/setWxs', data).then(res => {
if (res.code == 200) {
this.jiaozhunflag = false
uni.showToast({
title: '校准成功',
icon: 'success',
duration: 2000
})
}else{
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
},
// 点击修改名称
btnxgname(){
this.xgname = this.deviceInfo.deviceName
this.showmc = true
},
// 点击修改名称
subname(){
let data = {
deviceId: this.id,
deviceName: this.xgname,
}
this.$u.put('/app/device', data).then(res => {
if (res.code == 200) {
this.showmc = false
this.getshuax()
uni.showToast({
title: '修改成功',
icon: 'success',
duration: 2000
})
}
})
},
// 点击取消修改名称
close() {
this.showmc = false
},
// 点击更换店铺
confirms(e){
let data = {
deviceId: this.id,
storeId:e[0].value
}
this.$u.put('/app/device', data).then(res => {
if (res.code == 200) {
this.getshuax()
uni.showToast({
title: '修改成功',
icon: 'success',
duration: 2000
})
}
})
},
sremakes() {
this.showshop = true
},
gettanc(){
this.$u.get('/app/store/listCount').then((res) => {
if (res.code == 200) {
this.total = res.total
if (res.data.length > 0) {
let arr = res.data.map(row => ({
value: row.storeId,
label: row.name
}))
this.wateringList = arr.slice(1)
}
}
})
},
// 解绑设备
deldevice() {
uni.showModal({
title: '确认解绑',
content: '您确定要解绑设备吗?',
success: (resModal) => {
if (resModal.confirm) {
this.$u.delete(`/app/device/mch/unbind/${this.id}`).then((res) => {
if (res.code == 200) {
uni.showToast({
title: '解除成功',
icon: 'success',
duration: 2000
})
uni.reLaunch({
url:'/pages/index/index'
})
} else if(res.code == 500){
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
} else if (resModal.cancel) {
}
}
})
},
// 自定义返回
btns(){
uni.reLaunch({
url:'/pages/index/index'
})
},
// 商户跳转进行中订单
btnshdd(){
uni.navigateTo({
url:'/pages/shanghudd?id=' + this.sklist.billNo
})
},
// 刷新
getshuax() {
this.$u.get(`/app/device/${this.id}/refreshIot`).then((res) => {
this.$u.get("/app/device/" + this.id).then((res) => {
if (res.code == 200) {
if(res.data.wxs != null){
this.wxs = (res.data.wxs * 100).toFixed(2) + '%'
}else{
this.wxs = 100 + '%'
}
this.deviceInfo = res.data
this.getwenjian() //获取固件版本
this.qrResult = res.data.mac
this.modelId = res.data.modelTags
this.modelChip = res.data.modelChip
this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
console.log(this.deviceId,'02022')
if (this.ver_dataflag != 3) { //判断离线默认连蓝牙
this.getlanya()
}
this.storeId = res.data.storeId
this.deviceNo = res.data.deviceNo
this.getshoukuan()
if (res.data.customPicture != null) {
this.imglist = res.data.customPicture
} else {
this.imglist = res.data.picture
}
if (this.deviceInfo.expireTime == null) {
this.timeday = 0
} else {
let expireTimeStr = this.deviceInfo.expireTime
let expireTimeParts = expireTimeStr.split(" ")
let expireDateParts = expireTimeParts[0].split("-")
let expireTimePartsTime = expireTimeParts[1].split(":")
let expireDate = new Date(expireDateParts[0], expireDateParts[1] - 1, expireDateParts[2], expireTimePartsTime[0], expireTimePartsTime[1], expireTimePartsTime[2])
let now = new Date()
let differenceInMs = expireDate - now
if (differenceInMs <= 0) {
this.timeday = 0
} else {
clearInterval(this.timer)
this.timer = null
this.timeday = this.formatMilliseconds(differenceInMs)
this.startTimer()
}
}
if (res.data.powerStatus == 0) {
this.imgflag = false
this.tdtxt = '关闭'
} else {
this.imgflag = true
this.tdtxt = '开启'
}
this.loadings = true
}
})
})
},
getshoukuan(){
this.$u.get(`/app/bill/incomeList?isUsing=true&deviceId=${this.deviceInfo.deviceId}`).then((res) => {
if(res.code == 200){
if(res.rows == null || res.rows.length == 0){
this.sklistflag = false
}else{
this.sklistflag = true
this.sklist = res.rows[0]
this.suitSurplus = res.rows[0].surplusEle
}
}else{
// uni.showToast({
// title: res.msg,
// icon: 'none',
// duration: 1500
// })
}
})
},
// 点击刷新
shuaxin(){
this.$u.get(`/app/device/${this.id}/refreshIot`).then((res) => {
if(res.code == 200){
this.$u.get("/app/device/" + this.id).then((res) => {
if (res.code == 200) {
if(res.data.wxs != null){
this.wxs = (res.data.wxs * 100).toFixed(2) + '%'
}else{
this.wxs = 100 + '%'
}
this.deviceInfo = res.data
this.qrResult = res.data.mac
this.modelId = res.data.modelTags
this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
console.log(this.deviceId,'02022')
if (this.ver_dataflag != 3) { //判断离线默认连蓝牙
this.getlanya()
}
this.storeId = res.data.storeId
this.deviceNo = res.data.deviceNo
this.getshoukuan()
if (res.data.customPicture != null) {
this.imglist = res.data.customPicture
} else {
this.imglist = res.data.picture
}
if (this.deviceInfo.expireTime == null) {
this.timeday = 0
} else {
let expireTimeStr = this.deviceInfo.expireTime
let expireTimeParts = expireTimeStr.split(" ")
let expireDateParts = expireTimeParts[0].split("-")
let expireTimePartsTime = expireTimeParts[1].split(":")
let expireDate = new Date(expireDateParts[0], expireDateParts[1] - 1, expireDateParts[2], expireTimePartsTime[0], expireTimePartsTime[1], expireTimePartsTime[2])
let now = new Date()
let differenceInMs = expireDate - now
if (differenceInMs <= 0) {
this.timeday = 0
} else {
clearInterval(this.timer)
this.timer = null
this.timeday = this.formatMilliseconds(differenceInMs)
this.startTimer()
}
}
if (res.data.powerStatus == 0) {
this.imgflag = false
this.tdtxt = '关闭'
} else {
this.imgflag = true
this.tdtxt = '开启'
}
this.loadings = true
}
})
uni.showToast({
title: res.msg,
icon: 'success',
duration: 1500
})
}else{
uni.showToast({
title: res.msg,
icon: 'none',
duration: 1500
})
}
})
},
// 点击跳转固件更新页面
btnfirmware(){
uni.navigateTo({
url:'/pages/daili/gujian'
})
},
// 点击显示选择单位
btnxzdw(){
this.showflag = true
console.log(1);
},
// 选择时长单位
btnconfirm(e) {
console.log(e)
this.danwei = e[0].label
this.damweiid = e[0].value
},
drawCanvas() {
const ctx = uni.createCanvasContext('qrcode', this)
ctx.setFillStyle('#fff')
ctx.fillRect(10, 10, 250, 250)
ctx.draw()
},
// 长按保存二维码
saveCanvas() {
uni.canvasToTempFilePath({
canvasId: 'qrcode',
success: (res) => {
console.log(res.tempFilePath)// 打印图片路径
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.showToast({
title: '保存成功',
icon: 'success'
})
}
})
},
fail: (err) => {
console.error(err)
}
});
},
//**生成二维码**//
qrFun: function() {
uni.navigateTo({
url:'/page_fenbao/fenxiang?id=' + this.deviceNo
})
},
ewmyc() {
this.wemflag = false
},
// 点击连接取消
btnlyqx() {
this.shibaiflag = false
this.bluetoothflag = false
},
// 开启和关闭
btnkq() {
if(this.deviceInfo.allowSwitch == true){
if (this.deviceInfo.onlineStatus == 1) {
if (this.tdtxt == '开启') {
this.$u.put(`/app/device/${this.id}/changePower?status=0`).then((res) => {
if (res.code == 200) {
this.tdtxt = '关闭'
this.imgflag = false
this.deviceInfo.status = 1
uni.showToast({
title: res.msg,
icon: 'success',
duration: 2000
})
} else {
this.imgflag = true
this.tdtxt = '开启'
uni.showModal({
title: '温馨提示',
content: res.msg,
showCancel: false,
success: function(res) {
}
})
this.getshuax()
}
})
} else {
this.$u.put(`/app/device/${this.id}/changePower?status=1`).then((res) => {
if (res.code == 200) {
this.imgflag = true
this.tdtxt = '开启'
this.deviceInfo.status = 3
uni.showToast({
title: res.msg,
icon: 'success',
duration: 2000
})
} else {
this.imgflag = false
this.tdtxt = '关闭'
uni.showModal({
title: '温馨提示',
content: res.msg,
showCancel: false,
success: function(res) {
}
})
this.getshuax()
}
})
}
} else {
if (this.ver_dataflag != 3) {
uni.showModal({
title: '温馨提示',
content: '蓝牙连接中,请尽量靠近设备!',
showCancel: false,
success: function(res) {
}
})
} else {
this.shibaiflag = false
if (this.tdtxt == '开启') {
let that = this
that.tdtxt = '关闭'
that.imgflag = false
that.deviceInfo.status = 1
xBlufi.notifySendCustomData({
customData: 'close'
})
xBlufi.notifySendCustomData({
customData: '11close'
})
let data = {
mac:that.qrResult,
reason:'商户操作临时开关关闭',
command:'11close',
result:'成功'
}
that.$u.post(`/app/commandLog/bluetooth`,data).then(res => {})
} else {
let that = this
that.tdtxt = '开启'
that.imgflag = true
that.deviceInfo.status = 3
xBlufi.notifySendCustomData({
customData: 'open'
})
xBlufi.notifySendCustomData({
customData: '11open'
})
let data = {
mac:that.qrResult,
reason:'商户操作临时开关开启',
command:'11open',
result:'成功'
}
that.$u.post(`/app/commandLog/bluetooth`,data).then(res => {})
}
}
}
}else{
uni.showToast({
title: '您没有权限操作',
icon: 'none',
duration: 2000
})
}
},
// 获取七牛云token
getQiniuToken() {
this.$u.get("/common/qiniu/uploadInfo").then((res) => {
if (res.code == 200) {
this.token = res.token
}
})
},
// 选择图像
btnpic() {
uni.chooseImage({
count: 1,
success: (rst) => {
this.url = rst.tempFilePaths[0]
}
})
},
onok(ev) {
this.url = ""
this.path = ev.path
let _this = this
let math = 'static/' + _this.$u.guid(20)
wx.uploadFile({
url: 'https://up-z2.qiniup.com',
name: 'file',
filePath: _this.path,
formData: {
token: _this.token,
key: 'smartmeter/img/' + math
},
success: function(res) {
// console.log(res);
let str = JSON.parse(res.data)
_this.userImgs = 'https://api.ccttiot.com/' + str.key
_this.imglist = _this.userImgs
let data = {
deviceId: _this.id,
customPicture: _this.imglist
}
_this.putdevice(data)
}
})
},
oncancel() {
// url设置为空隐藏控件
this.url = ""
},
putdevice(data) {
this.$u.put('/app/device', data).then((res) => {
if (res.code == 200) {
uni.showToast({
title: '修改成功',
icon: 'success',
duration: 2000
})
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
},
// 连接蓝牙函数
getlanya() {
if(this.ver_dataflag != 3){
console.log("进入111蓝牙连接")
this.czflag = true
this.ver_dataflag = 2
let that = this
if (that.deviceId != '') {
let systemInfo = uni.getSystemInfoSync()
if (systemInfo.platform == 'android') {
// that.modelId.some(item => {
if(that.modelChip == 'LX'){
console.log('配网')
let zuih = ''
if(that.deviceId.slice(-1) == 8){
zuih = 'A'
}else if(that.deviceId.slice(-1) == 9){
zuih = 'B'
}else if(that.deviceId.slice(-1) == 'A'){
zuih = 'C'
}else if(that.deviceId.slice(-1) == 'B'){
zuih = 'D'
}else if(that.deviceId.slice(-1) == 'C'){
zuih = 'E'
}else if(that.deviceId.slice(-1) == 'D'){
zuih = 'F'
}else{
zuih = Number(that.deviceId.slice(-1)) + 2
}
that.deviceId = that.deviceId.slice(0, -1) + zuih
console.log(that.modelId,zuih,that.deviceId.slice(0, -1),'...........')
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
console.log("进入蓝牙连接", that.deviceId)
console.log("进入that.name", that.name)
xBlufi.notifyConnectBle({
isStart: true,
deviceId: that.deviceId,
name: that.name
})
}else{
console.log('无配网')
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
console.log("进入蓝牙连接", that.deviceId)
console.log("进入that.name", that.name)
xBlufi.notifyConnectBle({
isStart: true,
deviceId: that.deviceId,
name: that.name
})
}
// })
} else if (systemInfo.platform == 'ios') {
// 当前设备是 iOS
that.findDevice()
}
}
}
},
findDevice() {
// 使用 find 方法查找匹配的设备
const matchedDevice = this.devicesarr.find(device => {
console.log(device.name, this.qrResult, '111')
console.log("IOSMAC", device)
return device.name.slice(-12) == this.qrResult.slice(-12)
})
if (matchedDevice) {
// 找到匹配的设备
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
xBlufi.notifyConnectBle({
isStart: true,
deviceId: matchedDevice.deviceId,
name: matchedDevice.name
})
this.deviceId = matchedDevice.deviceId
this.name = matchedDevice.name
console.log(this.deviceId, '11221')
} else {
console.log("未找到匹配的设备,继续查找...")
setTimeout(this.findDevice.bind(this), 1000) // 使用 bind 保持 this 上下文
}
},
// 获取设备详情
getDevice(id) {
this.$u.get("/app/device/" + id).then((res) => {
if (res.code == 200) {
if(res.data.wxs != null){
this.wxs = (res.data.wxs * 100).toFixed(2) + '%'
}else{
this.wxs = 100 + '%'
}
this.deviceInfo = res.data
this.qrResult = res.data.mac
this.modelId = res.data.modelTags
this.modelChip = res.data.modelChip
this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
console.log(this.deviceId,'02022')
if (this.ver_dataflag != 3) { //判断离线默认连蓝牙
this.getlanya()
}
this.storeId = res.data.storeId
this.deviceNo = res.data.deviceNo
this.getshoukuan()
if (res.data.customPicture != null) {
this.imglist = res.data.customPicture
} else {
this.imglist = res.data.picture
}
if (this.deviceInfo.expireTime == null) {
this.timeday = 0
} else {
let expireTimeStr = this.deviceInfo.expireTime
let expireTimeParts = expireTimeStr.split(" ")
let expireDateParts = expireTimeParts[0].split("-")
let expireTimePartsTime = expireTimeParts[1].split(":")
let expireDate = new Date(expireDateParts[0], expireDateParts[1] - 1, expireDateParts[2], expireTimePartsTime[0], expireTimePartsTime[1], expireTimePartsTime[2])
let now = new Date()
let differenceInMs = expireDate - now
if (differenceInMs <= 0) {
this.timeday = 0
} else {
clearInterval(this.timer)
this.timer = null
this.timeday = this.formatMilliseconds(differenceInMs)
this.startTimer()
}
}
if (res.data.powerStatus == 0) {
this.imgflag = false
this.tdtxt = '关闭'
} else {
this.imgflag = true
this.tdtxt = '开启'
}
this.loadings = true
}
})
},
startTimer() {
this.timer = setInterval(() => {
if (this.timeday.seconds > 0) {
this.timeday.seconds--
} else if (this.timeday.minutes > 0) {
this.timeday.seconds = 59 // 重置秒数为59
this.timeday.minutes--
} else if (this.timeday.hours > 0) {
this.timeday.minutes = 59 // 重置分钟数为59
this.timeday.hours--
this.timeday.seconds = 0 // 同时重置秒数为0
} else if (this.timeday.days > 0) {
this.timeday.hours = 23 // 重置小时数为23
this.timeday.minutes = 59 // 重置分钟数为59
this.timeday.seconds = 0 // 重置秒数为0
this.timeday.days--
} else {
// 所有时间单位都已减为0停止定时器
clearInterval(this.timer)
this.timer = null
// console.log('时间已到期')
}
}, 1000) // 每秒执行一次
},
// 计算天时分秒
formatMilliseconds(milliseconds) {
// 计算天数
let days = Math.floor(milliseconds / (1000 * 60 * 60 * 24))
// 计算剩余的小时数
let hours = Math.floor((milliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
// 计算剩余的分钟数
let minutes = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60))
// 计算剩余的秒数
let seconds = Math.floor((milliseconds % (1000 * 60)) / 1000)
// 返回一个对象,包含天、小时、分钟和秒
return {
days: days,
hours: hours,
minutes: minutes,
seconds: seconds
}
},
// 固件升级进度
startProgress() {
this.intervalId = setInterval(() => {
if (this.progress < 100) {
} else {
clearInterval(this.intervalId) // 进度达到 100% 时清除定时器
console.log("加载完成")
}
}, 30) // 每 30 毫秒更新一次进度
},
// 其他部分 点击进行跳转
topage(num) {
this.btnmsk = true
if (num == 0) {
this.btnmsk = false
uni.navigateTo({ //抄表
url: '/page_user/cbRecord?id=' + this.id
})
} else if (num == 1) {
if (this.deviceInfo.onlineStatus == 1) {
let that = this
uni.showModal({
title: '提示',
content: '您确定要将设备时间归零吗?',
success: function(res) {
if (res.confirm) {
that.btnmsk = false
//归零
that.$u.put(`/app/device/${that.id}/reset`).then((res) => {
if (res.code == 200) {
uni.showToast({
title: res.msg,
icon: 'success',
duration: 2000
})
that.getDevice(that.id)
setTimeout(()=>{
that.deviceInfo.status = 1
that.imgflag = false
that.tdtxt = '关闭'
},1000)
} else if (res.code == 500) {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
} else if (res.cancel) {
that.btnmsk = false
console.log('用户点击了取消')
}
}
})
}else{
this.btnmsk = false
if (this.ver_dataflag != 3) {
uni.showModal({
title: '温馨提示',
content: '蓝牙连接中,请尽量靠近设备!',
showCancel: false,
success: function(res) {
}
})
} else {
let that = this
uni.showModal({
title: '提示',
content: '您确定要将设备时间归零吗?',
success: function(res) {
if (res.confirm) {
that.btnmsk = false
setTimeout(() => {
that.deviceInfo.status = 1
that.imgflag = false
that.tdtxt = '关闭'
that.timeday = 0
xBlufi.notifySendCustomData({
customData: 'time0@'
})
xBlufi.notifySendCustomData({
customData: 'mmney0@'
})
xBlufi.notifySendCustomData({
customData: '11time0@'
})
xBlufi.notifySendCustomData({
customData: '11mmney0@'
})
let data = {
mac:that.qrResult,
reason:'归零',
command:'@time0@mmney0close',
result:'成功'
}
that.$u.post(`/app/commandLog/bluetooth`,data).then(res => {})
uni.showToast({
title: '归零成功',
icon: 'success',
duration: 2000
})
}, 1000)
}
}
})
}
}
} else if (num == 2) { //异常
this.btnmsk = false
uni.navigateTo({
url: '/page_fenbao/statulist/fault/yichang/index'
})
} else if (num == 3) {
this.btnmsk = false
uni.navigateTo({
url: "/page_fenbao/statulist/taocanlist/index?id=" + this.id + '&modevalue=' + 1
})
} else if (num == 4) { //固件升级
this.btnmsk = false
if(this.ver_dataflag != 3){
uni.showToast({
title: '请在蓝牙连接的情况下进行',
icon: 'none',
duration: 2000
})
}else{
}
// uni.navigateTo({
// url: '/page_user/setting?id=' + this.id
// })
} else if (num == 5) {
this.btnmsk = false
let that = this
uni.openBluetoothAdapter({
success: function (res) {
uni.getLocation({
type: 'wgs84',
success: (res) => {
if(that.deviceInfo.wifi == null){
let systemInfo = uni.getSystemInfoSync()
if (systemInfo.platform == 'android') {
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
xBlufi.notifyConnectBle({
isStart: false,
deviceId: that.deviceId,
name: that.name
})
// 当前设备是 Android
setTimeout(()=>{
uni.navigateTo({
url: '/page_components/wifilist/index?deviceId=' + that.qrResult + '&name=' + that.name + '&wifi=' + '暂无配网' + '&id=' + that.id
})
},500)
} else if (systemInfo.platform == 'ios') {
xBlufi.notifyStartDiscoverBle({
'isStart': false
})
xBlufi.notifyConnectBle({
isStart: false,
deviceId: that.deviceId,
name: that.name
})
// 当前设备是 iOS
setTimeout(()=>{
uni.navigateTo({
url: '/page_fenbao/device/wifivideo?deviceId=' + that.qrResult + '&name=' + that.name + '&wifi=' + '暂无配网' + '&id=' + that.id
})
},500)
}else{
uni.showToast({
title: '目前仅支持安卓和iOS系统',
icon: 'none',
duration: 2000
})
}
}else{
let systemInfo = uni.getSystemInfoSync()
if (systemInfo.platform == 'android') {
// 当前设备是 Android
uni.navigateTo({
url: '/page_components/wifilist/index?deviceId=' + that.qrResult + '&name=' + that.name + '&wifi=' + that.deviceInfo.wifi + '&id=' + that.id
})
} else if (systemInfo.platform == 'ios') {
// 当前设备是 iOS
uni.navigateTo({
url: '/page_fenbao/device/wifivideo?deviceId=' + that.qrResult + '&name=' + that.name + '&wifi=' + that.deviceInfo.wifi + '&id=' + that.id
})
}else{
uni.showToast({
title: '目前仅支持安卓和iOS系统',
icon: 'none',
duration: 2000
})
}
}
},
fail: (err) => {
console.error('获取位置失败:', err)
uni.showToast({
title: '位置信息未打开,无法配网,请授权后重试',
icon: 'none',
duration:2000
})
}
})
},
fail: function (err) {
console.error('蓝牙适配器初始化失败', err)
// 蓝牙未打开或初始化失败
uni.showToast({
title: '手机蓝牙未打开',
icon: 'none'
})
}
})
} else if (num == 6) {
uni.pageScrollTo({
scrollTop: 0,//滚动到距离顶部为0
duration: 0//滚动时长
})
this.btnmsk = false
this.vipflag = true
this.focus = true
}
},
getaddtime() {
this.$u.put('/app/device/addTime/' + this.id + '?amount=' + this.cztime + '&timeUnit=' + this.damweiid +'&withIot=false').then(res => {})
},
trueje() {
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
let id = this.deviceInfo.deviceId
this.vipflag = false
if (this.deviceInfo.onlineStatus == 1) {
this.$u.put('/app/device/addTime/' + id + '?amount=' + this.cztime + '&timeUnit=' + this.damweiid)
.then(res => {
if (res.code == 200) {
uni.showToast({
title: '充值成功',
icon: 'success',
duration: 2000
})
setTimeout(() => {
this.getshuax()
this.cztime = ''
this.danwei = ''
this.deviceInfo.status = 3
this.tdtxt = '开启'
this.imgflag = true
}, 2000)
} else if (res.code == 500) {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000
})
}
})
} else {
if (this.ver_dataflag != 3) {
uni.showModal({
title: '温馨提示',
content: '蓝牙连接中,请尽量靠近设备!',
showCancel: false,
success: function(res) {
}
})
} else {
let that = this
uni.getNetworkType({
success(res) {
if (res.networkType !== 'none') {
uni.getConnectedBluetoothDevices({
success(res) {
setTimeout(() => {
that.deviceInfo.status = 2
that.imgflag = true
that.tdtxt = '开启'
if (that.damweiid == 0) {
xBlufi.notifySendCustomData({
customData: 'mmney' + that.cztime + '@'
})
xBlufi.notifySendCustomData({
customData: '11mmney' + that.cztime + '@'
})
that.getaddtime()
} else if (that.damweiid == 4) {
xBlufi.notifySendCustomData({
customData: 'time' + that.cztime + '@'
})
xBlufi.notifySendCustomData({
customData: '11time' + that.cztime + '@'
})
that.getaddtime()
} else if (that.damweiid == 3) {
xBlufi.notifySendCustomData({
customData: 'time' + that.cztime * 60 + '@'
})
xBlufi.notifySendCustomData({
customData: '11time' + that.cztime * 60 + '@'
})
that.getaddtime()
} else if (that.damweiid == 2) {
xBlufi.notifySendCustomData({
customData: 'time' + that.cztime * 60 * 60 + '@'
})
xBlufi.notifySendCustomData({
customData: '11time' + that.cztime * 60 * 60 + '@'
})
that.getaddtime()
}
let data = {
mac:that.qrResult,
reason:'增加时长',
command:'11time@',
result:'成功'
}
console.log(data,'111');
that.$u.post(`/app/commandLog/bluetooth`,data).then(res => {})
}, 1000)
},
fail(err) {
console.error('获取已连接蓝牙设备信息失败:', err)
}
})
}
}
})
}
}
},
btnqx() {
this.vipflag = false
this.cztime = ''
},
funListenDeviceMsgEvent: function(options) {
let that = this;
switch (options.type) {
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
if (!options.result) {
that.ver_dataflag = 1
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) {
this.devicesarr = options.data
}
break
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
console.log("连接回调:" + JSON.stringify(options))
if (options.result == true) {
setTimeout(()=>{
this.ver_dataflag = 3
},2000)
xBlufi.notifyInitBleEsp32({
deviceId: options.data.deviceId
})
}else{
}
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_MY_DATA:
console.log("文件读取中", options.data)
break
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
this.ver_dataflag = 3
if (typeof options.data === 'string') {
if (options.data.indexOf("prom:") !== -1) {
console.log("选择固件升级收信息:", options.data, options.data.length);
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(()=>{
uni.reLaunch({
url:'/pages/index/index'
})
this.shengjiflag = false
},2000)
}
if (this.progress === 9000) {
console.log('固件升级失败')
this.progress = 99
uni.showToast({
title: '固件升级失败',
icon: 'none',
duration: 2000
})
setTimeout(()=>{
uni.reLaunch({
url:'/pages/index/index'
})
this.shengjiflag = false
},1000)
}
}else{
let arrobj = this.parseStringToObject(options.data)
this.lanyaobj = arrobj
let data ={
v:arrobj.bat,
S:arrobj.sw,
mac:this.qrResult,
time:arrobj.time,
version:arrobj.ver
}
this.$u.put(`/app/device/bltSyncIot`,data).then(res => {
if(res.code == 200){
// console.log(data);
}
})
console.log("1收到设备发来的自定义数据结果", options.data,arrobj)
}
} else {
console.log("不是字符串:", options.data,this.ver_data);
}
break
case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
if (options.result) {
console.log('初始化成功')
} else {
console.log('初始化失败')
break
}
break
}
},
parseStringToObject(str) {
// 去掉末尾的空字符串(如果有)
const parts = str.split('@').filter(part => part.trim() !== '');
const result = {};
parts.forEach(part => {
// 如果包含冒号,按 key:value 解析
if (part.includes(':')) {
const [key, value] = part.split(':');
result[key.trim()] = value.trim();
} else {
// 如果不包含冒号,按 keyvalue 解析
const key = part.match(/[a-zA-Z]+/)?.[0]; // 提取字母部分
const value = part.match(/\d+/)?.[0]; // 提取数字部分
if (key && value !== undefined) {
result[key.trim()] = value.trim();
}
}
});
return result;
}
}
}
</script>
<style lang="scss">
.pagesac{
top: 0 !important;
}
/deep/ .panel {
position: fixed;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
left: 0;
z-index: 99 !important;
overflow: hidden;
}
.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;
}
.imgewmflag {
width: 750rpx;
height: 100vh;
background: #fff;
border-radius: 0rpx 0rpx 0rpx 0rpx;
z-index: 1;
position: fixed;
top: 0;
left: 0;
}
.imgewm {
width: 250px;
height:250px;
position: fixed;
top:400rpx;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
.lanyalx {
display: inline-block;
text-align: center;
font-size: 26rpx;
width: 196rpx;
height: 40rpx;
line-height: 40rpx;
background-color: #8883F0;
color: #fff;
position: absolute;
bottom: 0;
border-radius: 0 0 10rpx 10rpx;
}
.conts {
display: flex;
justify-content: space-between;
margin-top: 50rpx;
align-items: center;
width: 100%;
height: 100%;
padding: 20rpx;
border-radius: 30rpx;
box-sizing: border-box;
background-color: #fff;
.bot {
// width: 100%;
// height: 80rpx;
// line-height: 80rpx;
// text-align: center;
// border-radius: 30rpx;
// background-color: #fff;
// margin-top: 30rpx;
font-size: 30rpx;
}
}
.picjt {
position: fixed;
top: 190rpx;
right: 60rpx;
width: 16rpx;
height: 30rpx;
}
.bluetoothbox {
width: 100%;
height: 100vh;
background-color: #f4f1f6;
position: fixed;
top: 0;
left: 0;
z-index: 99;
text-align: center;
.img {
margin-top: 400rpx;
width: 320rpx;
height: 320rpx;
}
.one {
font-size: 36rpx;
color: #000;
}
.two {
margin-top: 30rpx;
font-size: 24rpx;
color: #ccc;
}
.thr {
margin-top: 30rpx;
font-size: 28rpx;
color: #ccc;
}
.anfour {
display: flex;
margin-top: 30rpx;
justify-content: space-between;
padding: 0 220rpx;
box-sizing: border-box;
.qx {
width: 100rpx;
height: 70rpx;
line-height: 70rpx;
text-align: center;
border: 1px solid #3D3D3D;
border-radius: 10rpx;
}
.cx {
width: 200rpx;
height: 70rpx;
line-height: 70rpx;
text-align: center;
background-color: #8883F0;
color: #fff;
border-radius: 10rpx;
}
}
.stop {
font-size: 36rpx;
color: #000;
margin-top: 380rpx;
}
.xtop {
margin-top: 30rpx;
font-size: 24rpx;
color: #ccc;
}
.xqx {
width: 530rpx;
height: 90rpx;
line-height: 90rpx;
border-radius: 20rpx;
text-align: center;
background-color: #fff;
margin: auto;
margin-top: 200rpx;
}
image {
width: 500rpx;
height: 500rpx;
margin-top: 100rpx;
}
}
.popcard {
display: flex;
justify-content: center;
flex-wrap: wrap;
width: 550rpx;
height: 400rpx;
border-radius: 20rpx;
.tit {
display: flex;
justify-content: center;
width: 100%;
align-items: center;
font-size: 28rpx;
font-weight: 700;
}
.ipt {
margin-top: 60rpx;
width: 80%;
.u-input::placeholder {
font-size: 20px;
color: red;
}
}
.btnbox {
width: 100%;
display: flex;
flex-wrap: nowrap;
border-radius: 0 0 20rpx 20rpx;
.btn2 {
display: flex;
align-items: center;
justify-content: center;
width: 50%;
font-size: 32rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #000;
background-color: #fff;
}
.btn1 {
display: flex;
align-items: center;
justify-content: center;
width: 50%;
font-size: 32rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #fff;
background-color: #8883f0;
border: 1rpx solid #ccc;
}
}
}
/deep/ .u-title {
padding-bottom: 22rpx;
}
/deep/ .uicon-nav-back {
padding-bottom: 22rpx;
}
page {
background-color: #F9F8FF;
}
.dianliang{
position: fixed;
top: 30%;
left: 50%;
transform: translateX(-50%);
z-index: 3;
width: 680rpx;
height: 733rpx;
.anniu{
width: 636rpx;
height: 114rpx;
line-height: 114rpx;
text-align: center;
font-weight: 600;
font-size: 40rpx;
color: #FFFFFF;
background: #8883F0;
border-radius: 18rpx 18rpx 18rpx 18rpx;
position: absolute;
top: 570rpx;
left: 50%;
transform:translateX(-50%);
z-index: 2;
}
.shuru{
position: absolute;
top: 400rpx;
left: 50%;
transform:translateX(-50%);
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
input{
width: 386rpx;
height: 88rpx;
border-radius: 15rpx 15rpx 15rpx 15rpx;
border: 1rpx solid #808080;
text-align: center;
line-height: 88rpx;
margin: 0 27rpx;
}
image{
width: 88rpx;
height: 88rpx;
}
}
.bj{
position: absolute;
top: 0;
left: 0;
z-index: 2;
}
}
// .mask {
// width: 750rpx;
// height: 100vh;
// background: #000000;
// border-radius: 0rpx 0rpx 0rpx 0rpx;
// opacity: 0.2;
// // z-index: 1;
// position: fixed;
// top: 0;
// left: 0;
// }
.maskss {
width: 750rpx;
height: 100vh;
background: #000000;
border-radius: 0rpx 0rpx 0rpx 0rpx;
opacity: 0.2;
z-index: 1;
position: fixed;
top: 0;
left: 0;
}
.tanc {
width: 610rpx;
max-height: 430rpx;
background: #FFFFFF;
border-radius: 30rpx 30rpx 30rpx 30rpx;
position: fixed;
top: 528rpx;
left: 50%;
transform: translateX(-50%);
z-index: 2;
text-align: center;
.tit {
width: 100%;
text-align: center;
margin-top: 28rpx;
font-weight: 500;
font-size: 32rpx;
color: #3D3D3D;
}
input {
width: 504rpx;
height: 90rpx;
background: #EEEEEE;
border-radius: 6rpx 6rpx 6rpx 6rpx;
margin: auto;
margin-top: 22rpx;
padding-left: 20rpx;
text-align: left;
}
.inpss{
width: 510rpx;
height: 90rpx;
line-height: 90rpx;
font-size: 32rpx;
color: #ccc;
background: #EEEEEE;
border-radius: 6rpx 6rpx 6rpx 6rpx;
margin: auto;
margin-top: 22rpx;
padding-left: 20rpx;
text-align: left;
}
.xian {
width: 610rpx;
height: 2rpx;
background: #eee;
border-radius: 0rpx 0rpx 0rpx 0rpx;
margin-top: 26rpx;
}
.anniu {
display: flex;
justify-content: space-between;
height: 98rpx;
text {
padding: 24rpx;
text-align: center;
box-sizing: border-box;
font-weight: 500;
font-size: 36rpx;
color: #3D3D3D;
display: inline-block;
width: 100%;
height: 100rpx;
}
}
}
.txt {
text-align: left;
font-size: 28rpx;
color: #808080;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
display: flex;
justify-content: space-between;
}
.page {
// width: 100%;
// height: 100vh;
// overflow: scroll;
// padding-bottom: 80rpx;
// box-sizing: border-box;
.zhuhu {
margin-top: 46rpx;
padding: 0 40rpx;
padding-bottom: 80rpx;
.card1 {
// padding: 34rpx 0 0 40rpx;
width: 670rpx;
// height: 320rpx;
.top {
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
.left {
font-size: 35rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #8883F0;
}
.right {
margin-right: 56rpx;
.img1 {
width: 76rpx;
height: 76rpx;
}
}
}
.mid {
margin-top: 20rpx;
display: flex;
flex-wrap: nowrap;
align-content: flex-start;
justify-content: space-between;
.mid_left {
border-radius: 20rpx;
border: 1px solid #ff;
image {
width: 160rpx;
height: 160rpx;
border-radius: 20rpx;
}
}
.mid_right {
margin-left: 20rpx;
display: flex;
flex-wrap: wrap;
.mid_top {
width: 100%;
font-size: 36rpx;
font-weight: 600;
color: #333;
display: flex;
align-items: center;
padding-right: 4rpx;
box-sizing: border-box;
text{
margin-left: 10rpx;
font-weight: 400;
font-size: 24rpx;
padding: 6rpx;
box-sizing: border-box;
}
}
.mid_bot {
width: 100%;
display: flex;
// padding-right: 102rpx;
box-sizing: border-box;
margin-top: 10rpx;
.tip {
box-sizing: border-box;
background: rgba(204, 204, 204, 0);
opacity: 1;
font-size: 28rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #5B5B5B;
margin-right: 16rpx;
}
}
}
}
.bot {
margin-top: 20rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
.bot_left {
width: 210rpx;
height: 180rpx;
margin-right: 34rpx;
.echarts {
height: 200rpx;
.uni-ec-canvas {
width: 100%;
height: 100rpx !important;
display: block;
}
}
}
.bot_right {
display: flex;
width: 100%;
justify-content: space-between;
padding-left: 80rpx;
padding-right: 80rpx;
box-sizing: border-box;
.cont {
.tit {
font-size: 28rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 600;
color: #262B37;
line-height: 49rpx;
}
.txt {
font-size: 26rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #262B37;
}
}
}
}
}
.bot_right {
display: flex;
width: 100%;
justify-content: space-between;
padding-left: 60rpx;
padding-right: 60rpx;
box-sizing: border-box;
margin-top: 30rpx;
.cont {
.tit {
font-size: 32rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 600;
color: #262B37;
line-height: 49rpx;
margin-left: 0;
}
.txt {
font-size: 32rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #262B37;
}
}
}
.card2 {
padding-top: 40rpx;
margin-top: 20rpx;
width: 670rpx;
max-height: 614rpx;
padding-bottom: 30rpx;
background: #FFFFFF;
box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(53, 140, 255, 0.1);
border-radius: 28rpx;
.aa{
padding-left: 40rpx;
padding-right: 40rpx;
box-sizing: border-box;
display: flex;
justify-content: space-between;
margin-top: 10rpx;
font-size: 28rpx;
color: #808080;
}
.tit {
margin-left: 40rpx;
font-size: 36rpx;
color: #3D3D3D;
font-weight: 600;
}
}
.card3 {
padding-top: 40rpx;
margin-top: 24rpx;
width: 670rpx;
// height: 490rpx;
// overflow: scroll;
background: #FFFFFF;
box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(53, 140, 255, 0.1);
border-radius: 28rpx;
.tit {
margin-left: 40rpx;
font-size: 35rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #3D3D3D;
}
.cont_box {
padding: 0 40rpx;
display: flex;
padding-bottom: 40rpx;
box-sizing: border-box;
flex-wrap: wrap;
align-items: center;
.cont:last-child {
margin-right: 0rpx;
}
.cont {
width: 25%;
text-align: center;
margin-top: 58rpx;
.top {
width: 100%;
image {
width: 58rpx !important;
height: 58rpx !important;
}
.bot {
font-weight: 400;
font-size: 32rpx;
color: #3D3D3D;
margin-top: 24rpx;
}
}
}
}
}
.button {
margin-left: 76rpx;
margin-top: 178rpx;
display: flex;
justify-content: center;
align-items: center;
width: 520rpx;
height: 104rpx;
background: #8883F0;
box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42, 130, 228, 0.1);
border-radius: 52rpx 52rpx 52rpx 52rpx;
font-size: 32rpx;
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
color: #FFFFFF;
}
}
}
</style>