流程改版
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
const ppScale = getApp().globalData.ppScale;
|
||||
import $ from "../../utils/request";
|
||||
|
||||
Page({
|
||||
data: {
|
||||
progress: {
|
||||
index: 0,
|
||||
data: ['配置蓝牙', '初始化用户信息', '配备网络', '完成']
|
||||
},
|
||||
|
||||
progressNext: false,
|
||||
device: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
ppScale.plugin.bus.subscribe("devicesModel", (res) => {
|
||||
console.log("searchDevice ===》devicesModel", res);
|
||||
ppScale.device.mac = res.deviceMac;
|
||||
|
||||
ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
|
||||
console.log('connectedDevice ===》deviceConnect', res);
|
||||
|
||||
ppScale.plugin.ScaleAction.startDataProgress(true);
|
||||
ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol();
|
||||
|
||||
ppScale.activeProtocol.codeUpdateMTU((res) => {
|
||||
console.log("connectedDevice ===》codeUpdateMTU", res);
|
||||
|
||||
ppScale.activeProtocol.codeFetchBindingState((res) => {
|
||||
console.log("connectedDevice ===》codeFetchBindingState", res);
|
||||
|
||||
wx.hideLoading();
|
||||
if (res === 1) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '当前设备已被绑定,你确定要覆盖绑定吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.showLoading({
|
||||
title: "正在初始化设备...",
|
||||
mask: true
|
||||
});
|
||||
ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
|
||||
console.log("deviceInfo === codeClearDeviceData", res);
|
||||
wx.hideLoading();
|
||||
|
||||
if(res === 0) {
|
||||
let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
|
||||
let params = {
|
||||
equipmentCode: scaleDeviceId,
|
||||
};
|
||||
$.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "设备初始化成功,请重新绑定。",
|
||||
})
|
||||
// device.list = [];
|
||||
// device.mac = null;
|
||||
let pages = getCurrentPages();
|
||||
let prevPage = pages[pages.length - 2];
|
||||
prevPage.setData({
|
||||
getDeviceSetting: true
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}, 1500);
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "设备初始化失败。",
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
// device.mac = null;
|
||||
ppScale.plugin.Blue.disconnect();
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ppScale.device.name = this.data.device.name;
|
||||
ppScale.device.connection = this.data.device;
|
||||
if(this.data.progressNext) {
|
||||
let scaleDeviceId = ppScale.device.mac.replace(/:/g, '');
|
||||
let params = {
|
||||
sn: scaleDeviceId,
|
||||
};
|
||||
$.ajax("weighingScale/getUserInfoBySn", params, "GET", true, "正在同步用户信息...").then(res => {
|
||||
if(res.result) {
|
||||
wx.setStorageSync("userInfo", res.result);
|
||||
this.setProgress();
|
||||
} else {
|
||||
wx.removeStorageSync("userInfo");
|
||||
wx.showToast({
|
||||
title: "暂无用户信息,请手动补充",
|
||||
icon: "none"
|
||||
})
|
||||
setTimeout(() => {
|
||||
this.setProgress();
|
||||
}, 1500)
|
||||
}
|
||||
}).catch(() => {
|
||||
wx.showToast({
|
||||
title: "用户信息同步失败,请手动补充",
|
||||
icon: "none"
|
||||
})
|
||||
setTimeout(() => {
|
||||
this.setProgress();
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 选择了某个设备
|
||||
deviceChange(e) {
|
||||
let status = e.detail.status;
|
||||
if(status) {
|
||||
wx.showLoading({
|
||||
title: "蓝牙配对中...",
|
||||
mask: true
|
||||
});
|
||||
this.setData({
|
||||
progressNext: true
|
||||
})
|
||||
let device = e.detail.device;
|
||||
this.connectedDevice_(device);
|
||||
}
|
||||
},
|
||||
|
||||
connectedDevice(e) {
|
||||
wx.showLoading({
|
||||
title: "正在尝试连接...",
|
||||
mask: true
|
||||
});
|
||||
this.setData({
|
||||
progressNext: false
|
||||
})
|
||||
let device = e.detail.device;
|
||||
this.connectedDevice_(device);
|
||||
},
|
||||
|
||||
connectedDevice_(device) {
|
||||
if(device) {
|
||||
this.setData({
|
||||
device: device
|
||||
})
|
||||
ppScale.plugin.Blue.createBLEConnection(device);
|
||||
}
|
||||
},
|
||||
|
||||
setDeviceUserInfo(e) {
|
||||
this.setData({
|
||||
progressNext: true
|
||||
})
|
||||
let status = e.detail.status;
|
||||
if(status) {
|
||||
this.setProgress();
|
||||
}
|
||||
},
|
||||
|
||||
setDeviceConfig(e) {
|
||||
let status = e.detail.status;
|
||||
if(status) {
|
||||
this.setProgress();
|
||||
}
|
||||
},
|
||||
|
||||
setConfigSuccessful() {
|
||||
wx.switchTab({
|
||||
url: "/pages/home/home"
|
||||
})
|
||||
},
|
||||
|
||||
setProgress() {
|
||||
this.setData({
|
||||
["progress.index"]: this.data.progress.index + 1
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"configureDevice1": "/components/configureDevice_1/configureDevice_1",
|
||||
"configureDevice2": "/components/configureDevice_2/configureDevice_2",
|
||||
"configureDevice3": "/components/configureDevice_3/configureDevice_3",
|
||||
"configureDevice4": "/components/configureDevice_4/configureDevice_4"
|
||||
},
|
||||
"navigationBarTitleText": "配置蓝牙",
|
||||
"disableScroll": true
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<view class="configureDevice">
|
||||
<view class="progress">
|
||||
<block wx:for="{{progress.data}}" wx:key="index">
|
||||
<view class="progressList">
|
||||
<view style="background-color: {{progress.index >= index ? '#BFDEFD' : '#C1DFFE'}};">
|
||||
<view style="height: {{progress.index >= index ? '24rpx' : '40rpx'}};width: {{progress.index >= index ? '24rpx' : '40rpx'}};background-color: {{progress.index >= index ? '#3194FB' : '#77849E'}};">{{progress.index >= index ? '' : index + 1}}</view>
|
||||
</view>
|
||||
<view class="{{progress.index >= index ? 'active' : ''}}">{{item}}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view class="content">
|
||||
<block wx:if="{{progress.index === 0}}">
|
||||
<configureDevice1 bind:deviceEvent="deviceChange"></configureDevice1>
|
||||
</block>
|
||||
<block wx:if="{{progress.index === 1}}">
|
||||
<configureDevice2 bind:deviceEvent="setDeviceUserInfo" bind:connectedDeviceEvent="connectedDevice"></configureDevice2>
|
||||
</block>
|
||||
<block wx:if="{{progress.index === 2}}">
|
||||
<configureDevice3 bind:deviceEvent="setDeviceConfig"></configureDevice3>
|
||||
</block>
|
||||
<block wx:if="{{progress.index === 3}}">
|
||||
<configureDevice4 bind:deviceEvent="setConfigSuccessful"></configureDevice4>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,82 @@
|
||||
.configureDevice {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
padding: 0 30rpx 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.configureDevice::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 550rpx;
|
||||
background: linear-gradient(0deg, #F5F7FB 0%, #D8EAFD 100%);
|
||||
}
|
||||
|
||||
.progress {
|
||||
width: 100%;
|
||||
height: 160rpx;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.progressList {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.progressList>view:nth-of-type(1) {
|
||||
width: 52rpx;
|
||||
height: 52rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
position: relative;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 20rpx;
|
||||
}
|
||||
|
||||
.progressList>view:nth-of-type(1)::before {
|
||||
content: "";
|
||||
}
|
||||
|
||||
.progressList>view:nth-of-type(1)::after {
|
||||
content: "";
|
||||
}
|
||||
|
||||
.progressList>view:nth-of-type(1)>view {
|
||||
color: #FFFFFF;
|
||||
font-size: 24rpx;
|
||||
font-weight: bold;
|
||||
line-height: 40rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 50%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.progressList>view:nth-of-type(2) {
|
||||
color: #77849E;
|
||||
height: 24rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 24rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.active {
|
||||
color: #3194FB !important;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100%;
|
||||
border-radius: 16rpx;
|
||||
height: calc(100% - 160rpx);
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
Reference in New Issue
Block a user