流程改版

This commit is contained in:
17792275749
2025-05-29 08:45:04 +08:00
parent ba54f14735
commit f9c22f1da4
83 changed files with 1831 additions and 2603 deletions
+68 -4
View File
@@ -6,14 +6,14 @@ App({
globalData: { globalData: {
// wx.request 请求的服务地址 // wx.request 请求的服务地址
wxRequestUrl: "https://device.shuziweidao.com/gateway/", wxRequestUrl: "https://device.shuziweidao.com/gateway/",
// wxRequestUrl: "http://192.168.10.173:8889/", // wxRequestUrl: "http://192.168.1.12:8889/",
// 秤的所有信息 // 秤的所有信息
ppScale: { ppScale: {
plugin: null, plugin: null,
activeProtocol: null, activeProtocol: null,
domain: "http://device.shuziweidao.com:80/gateway", domain: "http://device.shuziweidao.com:80/gateway",
// domain: "http://192.168.10.173:8889", // domain: "http://192.168.1.12:8889",
wifi: { wifi: {
ssid: "", ssid: "",
password: "" password: ""
@@ -130,18 +130,23 @@ App({
"updateBy": null "updateBy": null
}], // 即将要搜索周边秤的配置 }], // 即将要搜索周边秤的配置
list: [], // 根据配置搜索到秤的列表 list: [], // 根据配置搜索到秤的列表
name: "",
mac: null, // 选中的设备mac地址/SN码 mac: null, // 选中的设备mac地址/SN码
name: "", // 设备名称
connection: null, // 默认选中连接的设备 connection: null, // 默认选中连接的设备
connectState: null, // 当前连接设备的状态
} }
} },
_callbacks: {} // 用于存储所有 globalData 属性的监听回调
}, },
initPpScale() { initPpScale() {
this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin'); this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin');
// 蓝牙连接状态监听
this.globalData.ppScale.plugin.bus.subscribe("connectState", (res) => { this.globalData.ppScale.plugin.bus.subscribe("connectState", (res) => {
console.log("app.js ===> connectState", res); console.log("app.js ===> connectState", res);
this.setGlobalData('ppScale.device.connectState', res);
// 连接失败则重新连接 // 连接失败则重新连接
if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) { if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) {
@@ -150,6 +155,7 @@ App({
wx.hideLoading(); wx.hideLoading();
}); });
// 设备自动断开监听
this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => { this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => {
console.log("app.js ===> deviceWillDisconnect", res); console.log("app.js ===> deviceWillDisconnect", res);
@@ -165,5 +171,63 @@ App({
this.reconnectDevice(); this.reconnectDevice();
} }
}) })
},
/**
* 注册 globalData 某个属性的监听
* @param {string} keyPath 要监听的 globalData 属性路径,例如 'ppScale.device.connectState'
* @param {function} callback 属性变化时执行的回调函数 (newValue, oldValue) => {}
*/
watch(keyPath, callback) {
if (!this.globalData._callbacks[keyPath]) {
this.globalData._callbacks[keyPath] = [];
} }
this.globalData._callbacks[keyPath].push(callback);
},
/**
* 取消 globalData 某个属性的监听
* @param {string} keyPath 要取消监听的 globalData 属性路径
* @param {function} callback 之前注册的回调函数
*/
unwatch(keyPath, callback) {
if (this.globalData._callbacks[keyPath]) {
this.globalData._callbacks[keyPath] = this.globalData._callbacks[keyPath].filter(cb => cb !== callback);
}
},
/**
* 设置 globalData 的值并触发所有相关监听器
* 支持点表示法设置嵌套属性,例如 'ppScale.device.connectState'
* @param {string} keyPath 要设置的 globalData 属性路径
* @param {*} value 要设置的新值
*/
setGlobalData(keyPath, value) {
const keys = keyPath.split('.');
let current = this.globalData;
let oldValue = undefined;
// 遍历到目标属性的父级
for (let i = 0; i < keys.length - 1; i++) {
if (!current[keys[i]]) {
current[keys[i]] = {}; // 如果路径不存在,创建空对象
}
current = current[keys[i]];
}
// 获取旧值
oldValue = current[keys[keys.length - 1]];
// 只有当值发生变化时才更新并通知
if (oldValue !== value) {
current[keys[keys.length - 1]] = value; // 设置新值
// 触发监听器
if (this.globalData._callbacks[keyPath]) {
this.globalData._callbacks[keyPath].forEach(callback => {
callback(value, oldValue);
});
}
}
},
}) })
+2 -15
View File
@@ -2,17 +2,9 @@
"pages": [ "pages": [
"pages/home/home", "pages/home/home",
"pages/searchDevice/searchDevice", "pages/searchDevice/searchDevice",
"pages/connectedDevice/connectedDevice", "pages/configureDevice/configureDevice",
"pages/connectionSuccessful/connectionSuccessful",
"pages/getWifiList/getWifiList",
"pages/setWifiPassword/setWifiPassword",
"pages/setNetwork/setNetwork",
"pages/setNetworkSuccessful/setNetworkSuccessful",
"pages/my/my", "pages/my/my",
"pages/userInfo/userInfo", "pages/deviceInfo/deviceInfo"
"pages/deviceInfo/deviceInfo",
"pages/familyMembers/familyMembers",
"pages/index/index"
], ],
"window": { "window": {
"navigationBarTitleText": "", "navigationBarTitleText": "",
@@ -42,11 +34,6 @@
"provider": "wx0ffb48417ce6345c" "provider": "wx0ffb48417ce6345c"
} }
}, },
"permission": {
"scope.bluetooth": {
"desc": "用于连接体重秤设备"
}
},
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents" "lazyCodeLoading": "requiredComponents"
} }
@@ -0,0 +1,32 @@
const app = getApp();
Component({
data: {
devices: []
},
// 生命周期方法
lifetimes: {
attached() {
this.setData({
devices: app.globalData.ppScale.device.list
})
},
detached() {
this.setData({
devices: []
})
}
},
// 组件的方法
methods: {
selectDevice(e) {
let device = this.data.devices[e.currentTarget.dataset.i];
this.triggerEvent('deviceEvent', {
device: device,
status: true
});
}
}
});
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
@@ -0,0 +1,17 @@
<view class="configureDevice1">
<view class="title">蓝牙</view>
<view class="describe">可用设备</view>
<view class="deviceName">
<block wx:for="{{devices}}" wx:key="index">
<view data-i="{{index}}" bind:tap="selectDevice">
<view>
<image src="/images/configureDevice/bluetooth.png"/>
</view>
<view>
<view>{{item.name}}</view>
<!-- <view>正在配对</view> -->
</view>
</view>
</block>
</view>
</view>
@@ -0,0 +1,70 @@
.configureDevice1 {
width: 100%;
height: 100%;
padding: 60rpx 60rpx 0;
box-sizing: border-box;
}
.title {
color: #252535;
width: 100%;
height: 48rpx;
font-size: 48rpx;
font-weight: bold;
line-height: 48rpx;
margin-bottom: 48rpx;
}
.describe {
color: #B6B6B6;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
margin-bottom: 40rpx;
}
.deviceName {
width: 100%;
height: calc(100% - 166rpx);
}
.deviceName>view {
width: 100%;
height: 80rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
margin-bottom: 32rpx;
}
.deviceName>view>view:nth-of-type(1) {
width: 80rpx;
height: 80rpx;
overflow: hidden;
border-radius: 50%;
margin-right: 22rpx;
}
.deviceName>view>view:nth-of-type(2) {
flex: 1;
width: 0;
}
.deviceName>view>view:nth-of-type(2)>view:nth-of-type(1) {
color: #252535;
width: 100%;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
}
.deviceName>view>view:nth-of-type(2)>view:nth-of-type(2) {
color: #808080;
width: 100%;
height: 28rpx;
font-size: 28rpx;
line-height: 28rpx;
margin-top: 10rpx;
}
@@ -0,0 +1,294 @@
const app = getApp();
import $ from "../../utils/request";
Component({
data: {
BLUE_STATE: {},
device: null,
connectState: "",
userId: "",
realname: "",
sex: {
index: "",
data: [{
id: 1,
name: '男'
}, {
id: 2,
name: '女'
}]
},
birthday: {
label: "1980年01月01日",
value: "1980-01-01"
},
height: {
index: 50,
data: Array.from({ length: 200 - 120 + 1 }, (_, i) => i + 120)
},
weight: {
index: [60, 0],
data: [Array.from({ length: 120 + 1 }, (_, i) => i + 10), Array.from({ length: 10 }, (_, i) => i)]
},
},
// 存储回调函数的引用,以便在 detached 时取消监听
_connectStateWatcher: null,
lifetimes: {
attached() {
console.log(`[Component] connectState 获取: ${app.globalData.ppScale.device.connectState}`);
this.setData({
BLUE_STATE: app.globalData.ppScale.plugin.BLUE_STATE,
connectState: app.globalData.ppScale.device.connectState,
device: app.globalData.ppScale.device.connection
})
this._connectStateWatcher = (newValue, oldValue) => {
console.log(`[Component] connectState 变化: ${oldValue} -> ${newValue}`);
this.setData({
connectState: newValue || ''
});
};
app.watch('ppScale.device.connectState', this._connectStateWatcher);
let userInfo = wx.getStorageSync("userInfo") || null;
if(userInfo) {
let [year, month, day] = userInfo.birthday.split("-");
this.setData({
userId: userInfo.userId,
realname: userInfo.realname,
["sex.index"]: this.data.sex.data.findIndex(item => {return item.id === userInfo.sex}),
birthday: {
label: year + "年" + month + "月" + day + "日",
value: userInfo.birthday
},
["height.index"]: this.data.height.data.findIndex(item => {return item === userInfo.height}),
})
if(userInfo.weight) {
const integerPart = Math.floor(userInfo.weight);
const decimalPart = Math.round((userInfo.weight - integerPart) * 10);
const integerIndex = this.data.weight.data[0].indexOf(integerPart);
const decimalIndex = this.data.weight.data[1].indexOf(decimalPart);
this.setData({
["weight.index"]: [integerIndex !== -1 ? integerIndex : null, decimalIndex !== -1 ? decimalIndex : null],
})
}
}
},
detached() {
// 4. 在组件销毁时取消监听,防止内存泄漏
if (this._connectStateWatcher) {
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
}
}
},
// 组件的方法
methods: {
// 二次连接设备
connectedDevice() {
this.triggerEvent('connectedDeviceEvent', {
device: this.data.device
});
},
// 姓名输入
realnameInput(e) {
let realname = e.detail.value.replace(/\s+/g, '');
this.setData({
realname: realname
})
},
// 性别选择
sexChange(e) {
let sex = e.detail.value;
console.log(sex);
this.setData({
['sex.index']: e.detail.value
})
if(this.data.height.index === null) {
this.setData({
['height.index']: sex == 0 ? 50 : 40
})
}
if(this.data.weight.index === null) {
this.setData({
['weight.index']: sex == 0 ? 20 : 10
})
}
},
// 生日选择
birthdayChange(e) {
let v = e.detail.value;
let [year, month, day] = v.split("-");
this.setData({
birthday: {
label: year + "年" + month + "月" + day + "日",
value: v
}
})
},
// 身高选择
heightChange(e) {
this.setData({
['height.index']: e.detail.value
})
},
// 体重选择
weightChange(e) {
console.log(e.detail.value)
this.setData({
['weight.index']: e.detail.value
})
},
setUserInfo() {
if(this.data.connectState == this.data.BLUE_STATE.CONNECTSUCCESS) {
if(this.data.userId) {
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: this.data.userId,
userName: this.data.realname,
memberID: "",
age: this.getAge(this.data.birthday.value),
gender: this.data.sex.data[this.data.sex.index].id,
height: this.data.height.data[this.data.height.index],
isAthleteMode: 0,
currentWeight: this.data.weight.data[0][this.data.weight.index[0]] + '.' + this.data.weight.data[1][this.data.weight.index[1]],
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
if(res == 0) {
this.triggerEvent('deviceEvent', {
status: true
});
} else {
console.log("dataSyncUserInfo", res)
wx.showToast({
title: "用户信息下发失败,请重试。",
icon: "none"
})
}
})
} else {
let realname = this.data.realname;
let sex = this.data.sex;
let birthday = this.data.birthday;
let height = this.data.height;
let weight = this.data.weight;
if(!realname) {
wx.showToast({
icon: "none",
title: "姓名不能为空"
})
return false;
}
if(sex.index === "") {
wx.showToast({
icon: "none",
title: "性别不能为空"
})
return false;
}
if(!birthday.value) {
wx.showToast({
icon: "none",
title: "生日不能为空"
})
return false;
}
if(height.index === "") {
wx.showToast({
icon: "none",
title: "身高不能为空"
})
return false;
}
if(weight.index[0] === null && weight.index[1] === null) {
console.log(weight)
wx.showToast({
icon: "none",
title: "体重不能为空"
})
return false;
}
let sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
$.ajax("weighingScale/edit/user", {
sn: sn,
realname: realname,
sex: sex.data[sex.index].id,
birthday: birthday.value,
height: height.data[height.index],
weight: weight.data[0][weight.index[0]] + '.' + weight.data[1][weight.index[1]]
}, "POST", true, "保存中...").then(res => {
$.ajax("weighingScale/select/user", {
sn: sn
}, "GET", true, "更新用户信息中...").then(res_ => {
wx.setStorageSync("userInfo", res_.result);
wx.showToast({
icon: "none",
title: res.message
})
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: res_.result.id,
userName: res_.result.realname,
memberID: "",
age: this.getAge(res_.result.birthday), //
gender: res_.result.sex, //
height: res_.result.height, //
isAthleteMode: 0,
currentWeight: res_.result.weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
if(res == 0) {
this.triggerEvent('deviceEvent', {
status: true
});
} else {
console.log("dataSyncUserInfo", res)
wx.showToast({
title: "用户信息下发失败,请重试。",
icon: "none"
})
}
})
})
})
}
} else {
wx.showToast({
title: "设备连接失败,请重试。",
icon: "none"
})
}
},
// 根据生日获取年龄
getAge(birthDateString) {
const birthDate = new Date(birthDateString);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
const dayDiff = today.getDate() - birthDate.getDate();
// 如果当前月份小于出生月份,或者同月但当前日期小于出生日期,年龄需要减 1
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
age--;
}
return age;
},
}
});
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
@@ -0,0 +1,127 @@
<view class="configureDevice2">
<view class="header">
<view>
<view>智能蓝牙秤</view>
<view>型号:{{device.name}}</view>
</view>
<view>
<block wx:if="{{connectState == BLUE_STATE.CONNECTSUCCESS}}">
<view style="background-color: #2AC79F;"></view>
<view style="color: #2AC79F;">连接成功</view>
</block>
<block wx:else>
<view style="background-color: #F24439;"></view>
<view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view>
</block>
</view>
</view>
<view class="section">
<view class="from">
<view>
<view>姓名</view>
<block wx:if="{{userId}}">
<view class="valueClass">{{realname}}</view>
</block>
<block wx:else>
<view>
<view>
<input
type="text"
value="{{realname}}"
bindinput="realnameInput"
placeholder="请输入您的姓名"
class="valueClass"
placeholder-class="placeholderClass" />
</view>
</view>
</block>
</view>
<view>
<view>性别</view>
<block wx:if="{{userId}}">
<view class="valueClass">{{sex.data[sex.index].name}}</view>
</block>
<block wx:else>
<view class="~arrowAfter">
<view>
<picker mode="selector" bindchange="sexChange" value="{{sex.index}}" range="{{sex.data}}" range-key="name">
<block wx:if="{{sex.index === ''}}">
<view class="placeholderClass">请选择您的性别</view>
</block>
<block wx:else>
<view class="valueClass">{{sex.data[sex.index].name}}</view>
</block>
</picker>
</view>
</view>
</block>
</view>
<view>
<view>生日</view>
<block wx:if="{{userId}}">
<view class="valueClass">{{birthday.label}}</view>
</block>
<block wx:else>
<view class="~arrowAfter">
<view>
<picker mode="date" bindchange="birthdayChange" value="{{birthday.value}}">
<block wx:if="{{birthday.value === ''}}">
<view class="placeholderClass">请选择您的生日</view>
</block>
<block wx:else>
<view class="valueClass">{{birthday.label}}</view>
</block>
</picker>
</view>
</view>
</block>
</view>
<view>
<view>身高</view>
<block wx:if="{{userId}}">
<view class="valueClass">{{height.data[height.index]}}cm</view>
</block>
<block wx:else>
<view class="~arrowAfter">
<view>
<picker mode="selector" bindchange="heightChange" value="{{height.index}}" range="{{height.data}}">
<block wx:if="{{height.index === ''}}">
<view class="placeholderClass">请选择您的身高</view>
</block>
<block wx:else>
<view class="valueClass">{{height.data[height.index]}}</view>
</block>
</picker>
</view>
<view>cm</view>
</view>
</block>
</view>
<view>
<view>体重</view>
<block wx:if="{{userId}}">
<view class="valueClass">{{weight.data[0][weight.index[0]]}}.{{weight.data[1][weight.index[1]]}}kg</view>
</block>
<block wx:else>
<view class="~arrowAfter">
<view>
<picker mode="multiSelector" bindchange="weightChange" value="{{weight.index}}" range="{{weight.data}}">
<block wx:if="{{weight.index && weight.index.length && weight.index[0] !== null && weight.index[1] !== null}}">
<view class="valueClass">{{weight.data[0][weight.index[0]]}}.{{weight.data[1][weight.index[1]]}}</view>
</block>
<block wx:else>
<view class="placeholderClass">请选择您的体重</view>
</block>
</picker>
</view>
<view>kg</view>
</view>
</block>
</view>
</view>
<view class="btn">
<view bind:tap="setUserInfo">下一步</view>
</view>
<view class="describe">请填写和完善您家人的健康信息(填写数据同时,踩亮蓝牙秤并与其保持连接),将用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。</view>
</view>
</view>
@@ -0,0 +1,154 @@
input {
width: 100%;
height: 58rpx;
font-size: 28rpx;
line-height: 58rpx;
}
.placeholderClass {
color: #B6B6B6;
height: 58rpx;
font-size: 28rpx;
line-height: 58rpx;
}
.valueClass {
color: #77849E;
height: 58rpx;
font-size: 28rpx;
font-weight: bold;
line-height: 58rpx;
}
.configureDevice2 {
width: 100%;
height: 100%;
}
.header {
width: 100%;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 30rpx 40rpx;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
}
.header>view:nth-of-type(1) {
flex: 1;
}
.header>view:nth-of-type(1)>view:nth-of-type(1) {
color: #252535;
height: 32rpx;
font-weight: bold;
font-size: 32rpx;
line-height: 32rpx;
margin-bottom: 16rpx;
}
.header>view:nth-of-type(1)>view:nth-of-type(2) {
color: #808080;
height: 26rpx;
font-size: 26rpx;
line-height: 26rpx;
}
.header>view:nth-of-type(2) {
height: 28rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.header>view:nth-of-type(2)>view:nth-of-type(1) {
width: 12rpx;
height: 12rpx;
border-radius: 50%;
margin-right: 14rpx;
}
.header>view:nth-of-type(2)>view:nth-of-type(2) {
height: 28rpx;
font-weight: bold;
font-size: 28rpx;
line-height: 28rpx;
}
.section {
width: 100%;
padding: 0 30rpx;
box-sizing: border-box;
}
.from {
width: 100%;
margin-bottom: 66rpx;
}
.from>view {
width: 100%;
padding: 48rpx 10rpx 0;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
}
.from>view>view:nth-of-type(1) {
color: #252535;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
margin-bottom: 18rpx;
}
.from>view>view:nth-of-type(2) {
width: 100%;
height: 58rpx;
display: flex;
flex-wrap: nowrap;
padding-right: 26rpx;
box-sizing: border-box;
}
.from>view>view:nth-of-type(2)>view:nth-of-type(1) {
flex: 1;
width: 0;
}
.from>view>view:nth-of-type(2)>view:nth-of-type(2) {
color: #77849E;
height: 58rpx;
font-size: 28rpx;
font-weight: bold;
line-height: 58rpx;
}
.btn {
width: 100%;
padding: 0 26rpx;
box-sizing: border-box;
}
.btn>view {
color: #FFFFFF;
width: 100%;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
text-align: center;
line-height: 88rpx;
border-radius: 44rpx;
margin-bottom: 40rpx;
background-color: #1385FA;
}
.describe {
color: #77849E;
width: 100%;
font-size: 24rpx;
line-height: 40rpx;
}
@@ -0,0 +1,157 @@
const app = getApp();
import $ from "../../utils/request";
Component({
data: {
progress: 0,
wifiList: [],
selectWifi: null,
type: true,
selectWifiPWD: ""
},
lifetimes: {
attached() {
this.initWifi();
},
detached() {
// 在组件实例被从页面节点树移除时执行
console.log('MyComponent detached!');
}
},
// 组件的方法
methods: {
initWifi() {
wx.showLoading({
title: "正在获取Wi-Fi列表...",
mask: true
});
app.globalData.ppScale.activeProtocol.dataFindSurroundDevice((res) => {
wx.hideLoading();
this.setData({
wifiList: res
})
})
},
selectDevice(e) {
this.setData({
progress: 1,
selectWifi: e.currentTarget.dataset.item,
})
},
inputTypeChange() {
this.setData({
type: !this.data.type
})
},
passwordInput(e) {
this.setData({
selectWifiPWD: e.detail.value
})
},
setWifiPWD() {
this.setData({
progress: 2
})
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
domain: app.globalData.ppScale.domain,
ssid: this.data.selectWifi.ssid,
password: this.data.selectWifiPWD
}, (res) => {
console.log("setNetwork.js dataConfigNetWork", res);
if(res === 23) {
app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid;
app.globalData.ppScale.wifi.password = this.data.selectWifiPWD;
let mac = app.globalData.ppScale.device.mac;
let deviceId = app.globalData.ppScale.device.connection.deviceId;
if(mac && deviceId) {
let scaleDeviceId = mac.replace(/:/g, '');
let params = {
equipmentName: app.globalData.ppScale.device.name,
scaleDeviceId: scaleDeviceId,
deviceId: deviceId
};
$.ajax("weighingScale/binding/device", params, "POST").then(res => {
if (res.success) {
app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
console.log("setNetwork.js codeSetBindingState", res);
if(res == 0) {
this.triggerEvent('deviceEvent', {
status: true
});
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
wx.showToast({
title: "绑定失败,请重试。",
icon: "none"
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
})
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
wx.showToast({
icon: "none",
title: res.message
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
}).catch(err => {
app.globalData.ppScale.plugin.Blue.disconnect();
wx.showToast({
icon: "none",
title: err.message
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
})
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
wx.showToast({
icon: "none",
title: "Mac 地址与 deviceId 获取失败,请重新绑定"
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
})
}
}
});
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
@@ -0,0 +1,62 @@
<view class="configureDevice3">
<block wx:if="{{progress === 0}}">
<view class="progress0">
<view class="progress0_title">
<view>可用Wi-Fi</view>
<view>网络列表(设备暂不支持5GWi-Fi网络)</view>
</view>
<view class="progress0_content">
<scroll-view class="scrollView" scroll-y>
<view class="scrollViewContent">
<block wx:for="{{wifiList}}" wx:key="index">
<view data-item="{{item}}" bind:tap="selectDevice" class="~arrowAfter">
<view>
<image src="/images/configureDevice/wifi.png" />
</view>
<view>{{item.ssid}}</view>
</view>
</block>
</view>
</scroll-view>
</view>
</view>
</block>
<block wx:if="{{progress === 1}}">
<view class="progress1">
<view class="progress1_title">输入Wi-Fi密码</view>
<view class="progress1_form">
<view>
<view>
<image src="/images/configureDevice/wifiPwd.png" />
</view>
<view>{{selectWifi.ssid}}</view>
</view>
<view>
<view>密码</view>
<view>
<input
password="{{type}}"
value="{{selectWifiPWD}}"
bindinput="passwordInput"
placeholder="输入您的wi-fi密码"
placeholder-class="placeholderClass" />
</view>
<view bind:tap="inputTypeChange">
<image src="/images/configureDevice/open.png" />
</view>
</view>
</view>
<view class="progress1_btn" bind:tap="setWifiPWD">连接</view>
</view>
</block>
<block wx:if="{{progress === 2}}">
<view class="progress2">
<view>
<image src="/images/configureDevice/configureDevice_3_icon.png" />
</view>
<view>设备正在配对网络中,请稍等...</view>
<view>请持续站在秤上,耐心等待</view>
</view>
</block>
</view>
@@ -0,0 +1,207 @@
.configureDevice3 {
width: 100%;
height: 100%;
}
.progress0 {
width: 100%;
height: 100%;
padding-top: 60rpx;
box-sizing: border-box;
}
.progress0_title {
width: 100%;
padding: 0 60rpx;
box-sizing: border-box;
margin-bottom: 40rpx;
}
.progress0_title>view:nth-of-type(1) {
color: #252535;
width: 100%;
height: 48rpx;
font-size: 48rpx;
font-weight: bold;
line-height: 48rpx;
margin-bottom: 48rpx;
}
.progress0_title>view:nth-of-type(2) {
color: #B6B6B6;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
}
.progress0_content {
width: 100%;
height: calc(100% - 166rpx);
}
.scrollView {
width: 100%;
height: 100%;
}
.scrollViewContent {
width: 100%;
padding: 0 60rpx;
box-sizing: border-box;
}
.scrollViewContent>view {
width: 100%;
height: 80rpx;
display: flex;
flex-wrap: nowrap;
margin-bottom: 32rpx;
}
.scrollViewContent>view>view:nth-of-type(1) {
width: 80rpx;
height: 80rpx;
margin-right: 24rpx;
}
.scrollViewContent>view>view:nth-of-type(2) {
color: #252535;
flex: 1;
width: 0;
height: 80rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 80rpx;
}
.progress1 {
width: 100%;
height: 100%;
padding: 60rpx 30rpx 0;
box-sizing: border-box;
}
.progress1_title {
color: #252535;
width: 100%;
height: 48rpx;
font-size: 48rpx;
font-weight: bold;
line-height: 48rpx;
margin-bottom: 48rpx;
}
.progress1_form {
width: 100%;
margin-bottom: 64rpx;
}
.progress1_form>view {
width: 100%;
height: 96rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 0 24rpx;
box-sizing: border-box;
border-radius: 16rpx;
background-color: #F6F6F6;
}
.progress1_form>view:first-of-type {
margin-bottom: 32rpx;
}
.progress1_form>view>view:nth-of-type(1) {
color: #252535;
width: 100rpx;
height: 96rpx;
line-height: 96rpx;
font-size: 32rpx;
font-weight: bold;
}
.progress1_form>view:first-of-type>view:nth-of-type(1) {
padding: 24rpx 45rpx 24rpx 7rpx;
box-sizing: border-box;
display: flex;
align-items: center;
}
.progress1_form>view>view:nth-of-type(2) {
color: #252535;
flex: 1;
width: 0;
height: 96rpx;
font-size: 32rpx;
line-height: 96rpx;
}
.progress1_form>view>view:nth-of-type(2) input {
color: #252535;
width: 100%;
height: 96rpx;
font-size: 32rpx;
line-height: 96rpx;
}
.placeholderClass {
color: #B6B6B6;
height: 96rpx;
font-size: 32rpx;
line-height: 96rpx;
}
.progress1_form>view>view:nth-of-type(3) {
width: 56rpx;
height: 56rpx;
}
.progress1_btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
margin: 0 auto;
text-align: center;
border-radius: 44rpx;
background-color: #1385FA;
}
.progress2 {
width: 100%;
height: 100%;
padding: 90rpx 62rpx 0;
box-sizing: border-box;
}
.progress2>view:nth-of-type(1) {
width: 565rpx;
height: 500rpx;
margin: 0 auto;
}
.progress2>view:nth-of-type(2) {
color: #1385FA;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 36rpx;
text-align: center;
margin-bottom: 28rpx;
}
.progress2>view:nth-of-type(3) {
color: #808080;
width: 100%;
height: 30rpx;
font-size: 30rpx;
text-align: center;
line-height: 30rpx;
}
@@ -0,0 +1,27 @@
const app = getApp();
import $ from "../../utils/request";
Component({
data: {
},
lifetimes: {
attached() {
},
detached() {
// 在组件实例被从页面节点树移除时执行
console.log('MyComponent detached!');
}
},
// 组件的方法
methods: {
bindOk() {
this.triggerEvent('deviceEvent', {
status: true
});
}
}
});
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
@@ -0,0 +1,12 @@
<view class="configureDevice4">
<view class="icon">
<view>
<image src="/images/configureDevice/configureDevice_4_icon.png" />
</view>
<view>绑定成功</view>
</view>
<view class="describe">随时随地同步测量数据</view>
<view class="btn" bind:tap="bindOk">完成</view>
</view>
@@ -1,13 +1,13 @@
page { .configureDevice4 {
width: 100%; width: 100%;
padding: 200rpx 85rpx 0; height: 100%;
padding: 105rpx 55rpx 0;
box-sizing: border-box; box-sizing: border-box;
background-color: #ffffff;
} }
.icon { .icon {
width: 100%; width: 100%;
margin-bottom: 540rpx; margin-bottom: 475rpx;
} }
.icon>view:first-of-type { .icon>view:first-of-type {
-107
View File
@@ -1,107 +0,0 @@
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
/**
* 组件的属性列表
*/
properties: {
extClass: {
type: String,
value: ''
},
title: {
type: String,
value: ''
},
background: {
type: String,
value: ''
},
color: {
type: String,
value: ''
},
back: {
type: Boolean,
value: true
},
loading: {
type: Boolean,
value: false
},
homeButton: {
type: Boolean,
value: false,
},
animated: {
// 显示隐藏的时候opacity动画效果
type: Boolean,
value: true
},
show: {
// 显示隐藏导航,隐藏的时候navigation-bar的高度占位还在
type: Boolean,
value: true,
observer: '_showChange'
},
// back为true的时候,返回的页面深度
delta: {
type: Number,
value: 1
},
},
/**
* 组件的初始数据
*/
data: {
displayStyle: ''
},
lifetimes: {
attached() {
const rect = wx.getMenuButtonBoundingClientRect()
wx.getSystemInfo({
success: (res) => {
const isAndroid = res.platform === 'android'
const isDevtools = res.platform === 'devtools'
this.setData({
ios: !isAndroid,
innerPaddingRight: `padding-right: ${res.windowWidth - rect.left}px`,
leftWidth: `width: ${res.windowWidth - rect.left }px`,
safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${res.safeArea.top}px); padding-top: ${res.safeArea.top}px` : ``
})
}
})
},
},
/**
* 组件的方法列表
*/
methods: {
_showChange(show) {
const animated = this.data.animated
let displayStyle = ''
if (animated) {
displayStyle = `opacity: ${
show ? '1' : '0'
};transition:opacity 0.5s;`
} else {
displayStyle = `display: ${show ? '' : 'none'}`
}
this.setData({
displayStyle
})
},
back() {
const data = this.data
if (data.delta) {
wx.navigateBack({
delta: data.delta
})
}
this.triggerEvent('back', {
delta: data.delta
}, {})
}
},
})
@@ -1,5 +0,0 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {}
}
@@ -1,47 +0,0 @@
<view class="weui-navigation-bar {{extClass}}">
<view class="weui-navigation-bar__inner {{ios ? 'ios' : 'android'}}" style="color: {{color}}; background: {{background}}; {{displayStyle}}; {{innerPaddingRight}}; {{safeAreaTop}};">
<!-- 左侧按钮 -->
<view class='weui-navigation-bar__left' style="{{leftWidth}};">
<block wx:if="{{back || homeButton}}">
<!-- 返回上一页 -->
<block wx:if="{{back}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_goback">
<view bindtap="back" class="weui-navigation-bar__btn_goback_wrapper" hover-class="weui-active" hover-stay-time="100" aria-role="button" aria-label="返回">
<view class="weui-navigation-bar__button weui-navigation-bar__btn_goback"></view>
</view>
</view>
</block>
<!-- 返回首页 -->
<block wx:if="{{homeButton}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_home">
<view bindtap="home" class="weui-navigation-bar__btn_home_wrapper" hover-class="weui-active" aria-role="button" aria-label="首页">
<view class="weui-navigation-bar__button weui-navigation-bar__btn_home"></view>
</view>
</view>
</block>
</block>
<block wx:else>
<slot name="left"></slot>
</block>
</view>
<!-- 标题 -->
<view class='weui-navigation-bar__center'>
<view wx:if="{{loading}}" class="weui-navigation-bar__loading" aria-role="alert">
<view class="weui-loading" aria-role="img" aria-label="加载中"></view>
</view>
<block wx:if="{{title}}">
<text>{{title}}</text>
</block>
<block wx:else>
<slot name="center"></slot>
</block>
</view>
<!-- 右侧留空 -->
<view class='weui-navigation-bar__right'>
<slot name="right"></slot>
</view>
</view>
</view>
@@ -1,98 +0,0 @@
.weui-navigation-bar {
--weui-FG-0: rgba(0, 0, 0, .9);
--height: 44px;
--left: 16px;
}
.weui-navigation-bar .android {
--height: 48px;
}
.weui-navigation-bar {
overflow: hidden;
color: var(--weui-FG-0);
flex: none;
}
.weui-navigation-bar__inner {
position: relative;
top: 0;
left: 0;
height: calc(var(--height) + env(safe-area-inset-top));
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding-top: env(safe-area-inset-top);
width: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__left {
position: relative;
padding-left: var(--left);
display: flex;
flex-direction: row;
align-items: flex-start;
height: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__btn_goback_wrapper {
padding: 11px 18px 11px 16px;
margin: -11px -18px -11px -16px;
}
.weui-navigation-bar__btn_goback_wrapper.weui-active {
opacity: 0.5;
}
.weui-navigation-bar__btn_goback {
font-size: 12px;
width: 12px;
height: 24px;
-webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
-webkit-mask-size: cover;
mask-size: cover;
background-color: var(--weui-FG-0);
}
.weui-navigation-bar__center {
font-size: 17px;
text-align: center;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
font-weight: bold;
flex: 1;
height: 100%;
}
.weui-navigation-bar__loading {
margin-right: 4px;
align-items: center;
}
.weui-loading {
font-size: 16px;
width: 16px;
height: 16px;
display: block;
background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
background-size: 100%;
margin-left: 0;
animation: loading linear infinite 1s;
}
@keyframes loading {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Before

Width:  |  Height:  |  Size: 976 B

After

Width:  |  Height:  |  Size: 976 B

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 117 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 745 B

+187
View File
@@ -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;
}
-146
View File
@@ -1,146 +0,0 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
name: "",
deviceSelect: null
},
onLoad(options) {
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('connectedDevice ===》deviceConnect', res);
app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("connectedDevice ===》codeUpdateMTU", res);
app.globalData.ppScale.activeProtocol.codeFetchBindingState((res) => {
console.log("connectedDevice ===》codeFetchBindingState", res);
wx.hideLoading();
if (res === 1) {
wx.showModal({
title: '提示',
content: '当前设备已被绑定,你确定要覆盖绑定吗?',
success: (res) => {
if (res.confirm) {
app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
console.log("deviceInfo === codeClearDeviceData", res);
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, '');
let params = {
equipmentCode: scaleDeviceId,
};
$.ajax("weighingScale/del/device", params, "POST", true, "正在初始化设备...").then(res => {
wx.showToast({
icon: "none",
title: res.message,
})
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.setData({
getDeviceSetting: true
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500);
});
})
} else if (res.cancel) {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
})
} else {
app.globalData.ppScale.device.name = this.data.name;
wx.redirectTo({
url: "/pages/connectionSuccessful/connectionSuccessful"
})
}
})
});
});
},
onShow() {
let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null;
let deviceSelect = app.globalData.ppScale.device.connection;
this.setData({
token: token,
userInfo: userInfo,
name: deviceSelect.name,
deviceSelect: deviceSelect
})
},
nameInput(e) {
this.setData({
name: e.detail.value
})
},
// 配对
openConnectionSuccessful() {
let token = this.data.token;
let userInfo = this.data.userInfo;
if (token && userInfo) {
this.starConnection();
} else {
wx.login({
success: (res) => {
if (res.code) {
this.checkOpenIdLogin(res.code);
} else {
wx.showToast({
icon: "none",
title: "登录失败,请稍后再试!",
})
}
}
})
}
},
starConnection() {
let deviceSelect = this.data.deviceSelect;
if (deviceSelect) {
let name = this.data.name;
if (name) {
wx.showLoading({
title: "蓝牙配对中...",
mask: true
});
app.globalData.ppScale.device.name = name;
app.globalData.ppScale.plugin.Blue.createBLEConnection(deviceSelect);
} else {
wx.showToast({
icon: "none",
title: "设备名称不能为空"
})
}
} else {
wx.showToast({
icon: "none",
title: "配对设备不能为空"
})
}
},
// 微信一键登录
checkOpenIdLogin(code) {
let params = {
code: code
};
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token);
this.starConnection();
})
},
})
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "设备命名",
"disableScroll": true
}
@@ -1,16 +0,0 @@
<view class="equipmentModel">型号:{{deviceSelect.name}}</view>
<view class="equipmentIcon">
<block wx:if="{{deviceSelect && deviceSelect.name}}">
<image src="/images/devices/{{deviceSelect.name}}.png" />
</block>
</view>
<view class="equipmentName arrowAfter">
<view>设备名称</view>
<view>
<input type="text" value="{{name}}" bindinput="nameInput" placeholder="请输入设备名称" />
</view>
</view>
<view class="btn" bind:tap="openConnectionSuccessful">配对</view>
@@ -1,68 +0,0 @@
page {
padding: 50rpx 60rpx 0;
background-color: #ffffff;
}
.equipmentModel {
color: #252535;
width: 100%;
height: 48rpx;
font-size: 48rpx;
font-weight: bold;
line-height: 48rpx;
margin-bottom: 60rpx;
}
.equipmentIcon {
width: 320rpx;
height: 320rpx;
margin: 0 auto 40rpx;
}
.equipmentName {
width: 100%;
height: 126rpx;
display: flex;
flex-wrap: nowrap;
padding-right: 35rpx;
box-sizing: border-box;
margin-bottom: 550rpx;
justify-content: space-between;
border-bottom: 1rpx solid #EAECF1;
}
.equipmentName>view:first-of-type {
color: #252535;
height: 126rpx;
line-height: 126rpx;
font-size: 36rpx;
font-weight: bold;
}
.equipmentName>view:last-of-type {
flex: 1;
width: 0;
height: 126rpx;
}
.equipmentName>view:last-of-type input {
color: #808080;
width: 100%;
height: 126rpx;
text-align: right;
font-size: 36rpx;
line-height: 126rpx;
}
.btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
line-height: 88rpx;
margin: 0 auto;
font-size: 32rpx;
font-weight: bold;
border-radius: 44rpx;
text-align: center;
background-color: #1385FA;
}
@@ -1,10 +0,0 @@
const app = getApp();
Page({
// 获取wifi列表
openGetWifiList() {
wx.redirectTo({
url: "/pages/getWifiList/getWifiList"
})
}
})
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "绑定成功",
"disableScroll": true
}
@@ -1,10 +0,0 @@
<view class="icon">
<view>
<image src="/images/connectionSuccessful/icon.png" />
</view>
<view>绑定成功</view>
</view>
<view class="describe">随时随地同步测量数据</view>
<view class="btn" bind:tap="openGetWifiList">配置网络</view>
+1 -73
View File
@@ -3,67 +3,13 @@ import $ from "../../utils/request";
Page({ Page({
data: { data: {
// deviceConnect: false,
deviceInfo: null, deviceInfo: null,
}, },
onLoad(options) { onLoad(options) {
this.getDevice(); this.getDevice();
// app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
// console.log('deviceInfo ===》deviceConnect', res);
// app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
// app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
// app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
// console.log("deviceInfo ===》codeUpdateMTU", res);
// this.setData({
// deviceConnect: true
// })
// });
// });
}, },
// 初始化蓝牙
// initBluetooth() {
// wx.openBluetoothAdapter({
// success: () => {
// this.getDeviceSettingList();
// },
// fail: (err) => {
// if (err.errCode === 10001) {
// wx.showModal({
// title: "提示",
// content: "请打开手机蓝牙",
// });
// }
// },
// });
// },
// getDeviceSettingList() {
// let seviceList = [];
// app.globalData.ppScale.device.setting.map(item => {
// if(this.data.deviceInfo.type === item.deviceName) {
// seviceList.push(item);
// }
// })
// if(seviceList && seviceList.length) {
// app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
// app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
// app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
// let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
// if (fIndex > -1) {
// app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
// app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
// }
// });
// }
// },
// 获取已经绑定的设备列表 // 获取已经绑定的设备列表
getDevice() { getDevice() {
let params = {}; let params = {};
@@ -71,15 +17,10 @@ Page({
this.setData({ this.setData({
deviceInfo: res.result[0] deviceInfo: res.result[0]
}) })
// this.initBluetooth();
}) })
}, },
delDevice() { delDevice() {
// if(this.data.deviceConnect) {
// app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
// console.log("deviceInfo === codeClearDeviceData", res);
let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, ''); let scaleDeviceId = this.data.deviceInfo.macAddress.replace(/:/g, '');
let params = { let params = {
equipmentCode: scaleDeviceId, equipmentCode: scaleDeviceId,
@@ -95,18 +36,5 @@ Page({
}) })
}, 1500); }, 1500);
}); });
// }) }
// } else {
// wx.showToast({
// icon: "none",
// title: "删除失败,请靠近设备并点亮后再试"
// })
// app.globalData.ppScale.plugin.Blue.stop();
// this.getDeviceSettingList();
// }
},
// onUnload() {
// app.globalData.ppScale.plugin.Blue.stop();
// }
}) })
-4
View File
@@ -27,10 +27,6 @@
<view>成员</view> <view>成员</view>
<view>{{deviceInfo.subUserNum}}人</view> <view>{{deviceInfo.subUserNum}}人</view>
</view> </view>
<view>
<view>MAC地址</view>
<view>{{deviceInfo.macAddress}}</view>
</view>
</view> </view>
<view class="btn" bind:tap="delDevice">删除设备</view> <view class="btn" bind:tap="delDevice">删除设备</view>
-45
View File
@@ -1,45 +0,0 @@
import $ from "../../utils/request";
Page({
data: {
userInfo: null,
subUserList: [],
},
onShow() {
this.setData({
userInfo: wx.getStorageSync("userInfo") || null
})
this.getSubUser();
},
// 获取家庭成员列表
getSubUser() {
let params = {};
$.ajax("weighingScale/list/subUser", params, "GET", true, "正在获取...").then(res => {
this.setData({
subUserList: res.result
})
})
},
openUserInfo() {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=0"
})
},
editMyInfo() {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=1"
})
},
editUserInfo(e) {
let id = e.currentTarget.dataset.id;
wx.navigateTo({
url: "/pages/userInfo/userInfo?id="+ id +"&initBluetooth=1&customerType=0"
})
}
})
-5
View File
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "家庭成员",
"disableScroll": true
}
-31
View File
@@ -1,31 +0,0 @@
<view class="myInfo" bind:tap="editMyInfo">
<view>
<image src="/images/my/user.png" />
</view>
<view>{{userInfo ? userInfo.realname : '-'}}</view>
<view class="arrowAfter">修改我的档案</view>
</view>
<view class="familyMembers">
<view>家庭成员</view>
<view>
<block wx:if="{{subUserList && subUserList.length}}">
<block wx:for="{{subUserList}}" wx:key="index">
<view data-id="{{item.id}}" bind:tap="editUserInfo">
<view>
<image src="/images/my/user.png" />
</view>
<view>{{item.realname}}</view>
<view class="arrowAfter">修改档案</view>
</view>
</block>
</block>
</view>
</view>
<view class="btn" bind:tap="openUserInfo">
<view>
<image src="/images/familyMembers/add.png" />
</view>
<view>添加新成员</view>
</view>
-128
View File
@@ -1,128 +0,0 @@
page {
padding: 30rpx 30rpx 0;
}
.myInfo {
width: 100%;
height: 150rpx;
padding: 0 30rpx 0 38rpx;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
align-items: center;
border-radius: 16rpx;
margin-bottom: 40rpx;
background-color: #FFFFFF;
}
.myInfo>view:nth-of-type(1) {
width: 84rpx;
height: 84rpx;
border-radius: 50%;
margin-right: 24rpx;
}
.myInfo>view:nth-of-type(2) {
color: #252535;
flex: 1;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
}
.myInfo>view:nth-of-type(3) {
color: #B6B6B6;
height: 28rpx;
font-size: 28rpx;
line-height: 28rpx;
padding-right: 30rpx;
}
.familyMembers {
width: 100%;
margin-bottom: 24rpx;
}
.familyMembers>view:first-of-type {
color: #252535;
width: 100%;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
margin-bottom: 30rpx;
}
.familyMembers>view:last-of-type {
width: 100%;
border-radius: 16rpx;
}
.familyMembers>view:last-of-type>view {
width: 100%;
height: 150rpx;
padding: 0 30rpx 0 38rpx;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
align-items: center;
background-color: #FFFFFF;
border-bottom: 1rpx solid #EAECF1;
}
.familyMembers>view:last-of-type>view:last-of-type {
border-bottom: 0;
}
.familyMembers>view:last-of-type>view>view:nth-of-type(1) {
width: 84rpx;
height: 84rpx;
border-radius: 50%;
margin-right: 24rpx;
}
.familyMembers>view:last-of-type>view>view:nth-of-type(2) {
color: #252535;
flex: 1;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
}
.familyMembers>view:last-of-type>view>view:nth-of-type(3) {
color: #B6B6B6;
height: 28rpx;
font-size: 28rpx;
line-height: 28rpx;
padding-right: 30rpx;
}
.btn {
width: 100%;
height: 150rpx;
padding: 0 38rpx;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
align-items: center;
border-radius: 16rpx;
background-color: #FFFFFF;
}
.btn>view:first-of-type {
width: 84rpx;
height: 84rpx;
border-radius: 50%;
margin-right: 24rpx;
}
.btn>view:last-of-type {
color: #252535;
flex: 1;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
}
-32
View File
@@ -1,32 +0,0 @@
const app = getApp();
Page({
data: {
wifiList: []
},
onLoad() {
this.initWifi();
},
initWifi() {
wx.showLoading({
title: "正在获取Wi-Fi列表...",
mask: true
});
app.globalData.ppScale.activeProtocol.dataFindSurroundDevice((res) => {
wx.hideLoading();
console.log("wifiList", res);
this.setData({
wifiList: res
})
})
},
openSetWifiPassword(e) {
let item = JSON.stringify(e.currentTarget.dataset.item);
wx.navigateTo({
url: "/pages/setWifiPassword/setWifiPassword?item=" + item
})
}
})
-4
View File
@@ -1,4 +0,0 @@
{
"usingComponents": {},
"disableScroll": true
}
-19
View File
@@ -1,19 +0,0 @@
<view class="title">
<view>可用Wi-Fi</view>
<view>网络列表(设备暂不支持5GWi-Fi网络)</view>
</view>
<view class="wifi">
<scroll-view class="scrollView" scroll-y>
<view class="content">
<block wx:for="{{wifiList}}" wx:key="index">
<view class="arrowAfter" data-item="{{item}}" bind:tap="openSetWifiPassword">
<view>
<image src="/images/getWifiList/icon.png" />
</view>
<view>{{item.ssid}}</view>
</view>
</block>
</view>
</scroll-view>
</view>
-64
View File
@@ -1,64 +0,0 @@
page {
display: flex;
flex-direction: column;
background-color: #ffffff;
}
.title {
width: 100%;
padding: 50rpx 55rpx 24rpx;
box-sizing: border-box;
}
.title>view:first-of-type {
color: #252535;
width: 100%;
height: 48rpx;
font-size: 48rpx;
font-weight: bold;
line-height: 48rpx;
margin-bottom: 60rpx;
}
.title>view:last-of-type {
color: #B6B6B6;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
}
.wifi {
flex: 1;
overflow: hidden;
}
.content {
width: 100%;
padding: 0 55rpx;
box-sizing: border-box;
}
.content>view {
width: 100%;
height: 80rpx;
margin: 30rpx 0;
display: flex;
flex-wrap: nowrap;
}
.content>view>view:nth-of-type(1) {
width: 80rpx;
height: 80rpx;
margin-right: 24rpx;
}
.content>view>view:nth-of-type(2) {
color: #252535;
flex: 1;
width: 0;
height: 80rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 80rpx;
}
+13 -28
View File
@@ -9,23 +9,25 @@ Page({
}, },
onShow() { onShow() {
let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null; let userInfo = wx.getStorageSync("userInfo") || null;
let token = wx.getStorageSync("token") || null;
this.setData({ this.setData({
token: token, token: token,
userInfo: userInfo userInfo: userInfo,
deviceList: []
}) })
if(token && userInfo) { if(token) {
this.getDevice(); this.getDevice();
} }
}, },
// 点击登录或注册 // 点击登录或注册
openLoginOrReg() { openLoginOrReg(e) {
let bol = e.currentTarget.dataset.bol;
wx.login({ wx.login({
success: (res) => { success: (res) => {
if (res.code) { if (res.code) {
this.checkOpenIdLogin(res.code); this.checkOpenIdLogin(res.code, bol);
} else { } else {
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
@@ -37,29 +39,20 @@ Page({
}, },
// 微信一键登录 // 微信一键登录
checkOpenIdLogin(code) { checkOpenIdLogin(code, bol) {
let params = { let params = {
code: code code: code
}; };
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => { $.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "加载中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user); wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token); wx.setStorageSync("token", res.result.token);
if(res.result.token && res.result.user) {
this.setData({ this.setData({
token: res.result.token, token: res.result.token,
userInfo: res.result.user userInfo: res.result.user
}) })
this.getDevice();
} else { if(bol) {
wx.showToast({ this.openSearchDevice();
icon: "none",
title: "请先补全个人信息"
})
setTimeout(() => {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=0&customerType=1"
})
}, 1500)
} }
}) })
}, },
@@ -76,20 +69,12 @@ Page({
// 添加设备 // 添加设备
openSearchDevice() { openSearchDevice() {
// let token = this.data.token;
// let userInfo = this.data.userInfo;
// if (token && userInfo) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/searchDevice/searchDevice" url: "/pages/searchDevice/searchDevice"
}) })
// } else {
// wx.showToast({
// icon: "none",
// title: "请先登录"
// })
// }
}, },
// 打开设备详情
openDeviceInfo() { openDeviceInfo() {
wx.navigateTo({ wx.navigateTo({
url: "/pages/deviceInfo/deviceInfo" url: "/pages/deviceInfo/deviceInfo"
+8 -8
View File
@@ -8,14 +8,14 @@
<view> <view>
<image src="/images/home/user.png" /> <image src="/images/home/user.png" />
</view> </view>
<block wx:if="{{userInfo && token}}"> <block wx:if="{{userInfo || token}}">
<view>{{userInfo.realname}}</view> <view>{{userInfo ? userInfo.realname : '已登录'}}</view>
</block> </block>
<block wx:else> <block wx:else>
<view class="arrowAfter" bind:tap="openLoginOrReg">登录/注册</view> <view class="arrowAfter" data-bol="{{false}}" bind:tap="openLoginOrReg">登录/注册</view>
</block> </block>
</view> </view>
<view>智能体脂秤</view> <view>智能蓝牙秤</view>
<view>注重更好的健康生活品质</view> <view>注重更好的健康生活品质</view>
<view></view> <view></view>
</view> </view>
@@ -31,12 +31,12 @@
<view class="addDevice"> <view class="addDevice">
<view>请添加设备</view> <view>请添加设备</view>
<view>添加设备后,解锁更多体验</view> <view>添加设备后,解锁更多体验</view>
<!-- <block wx:if="{{userInfo && token}}"> --> <block wx:if="{{userInfo && token}}">
<view bind:tap="openSearchDevice">添加设备</view> <view bind:tap="openSearchDevice">添加设备</view>
<!-- </block> </block>
<block wx:else> <block wx:else>
<view bind:tap="openLoginOrReg">登录/注册</view> <view data-bol="{{true}}" bind:tap="openLoginOrReg">添加设备</view>
</block> --> </block>
</view> </view>
</block> </block>
</view> </view>
+1 -1
View File
@@ -86,7 +86,7 @@
.device>view:nth-of-type(1) { .device>view:nth-of-type(1) {
width: 500rpx; width: 500rpx;
height: 500rpx; height: 500rpx;
margin: 0 auto; margin: 0 auto 16rpx;
} }
.device>view:nth-of-type(2) { .device>view:nth-of-type(2) {
-2
View File
@@ -1,2 +0,0 @@
// index.js
Page({})
-5
View File
@@ -1,5 +0,0 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
-7
View File
@@ -1,7 +0,0 @@
<!--index.wxml-->
<navigation-bar title="Weixin" back="{{false}}" color="black" background="#FFF"></navigation-bar>
<scroll-view class="scrollarea" scroll-y type="list">
<view class="container">
Weixin
</view>
</scroll-view>
-10
View File
@@ -1,10 +0,0 @@
/**index.wxss**/
page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scrollarea {
flex: 1;
overflow-y: hidden;
}
+17 -52
View File
@@ -3,6 +3,7 @@ import $ from "../../utils/request";
Page({ Page({
data: { data: {
userInfo: null, userInfo: null,
token: null,
deviceInfo: null deviceInfo: null
}, },
@@ -11,24 +12,30 @@ Page({
let token = wx.getStorageSync("token") || null; let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null; let userInfo = wx.getStorageSync("userInfo") || null;
this.setData({ this.setData({
userInfo: userInfo userInfo: userInfo,
token: token
}) })
if(token && userInfo) { if(token && userInfo) {
this.getDevice(); this.getDevice();
} }
}, },
// 打开用户信息 openLoginOrReg() {
openUserInfo() { if(this.data.userInfo === null && this.data.token === null) {
if(this.data.userInfo) {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=1"
})
} else {
wx.login({ wx.login({
success: (res) => { success: (res) => {
if (res.code) { if (res.code) {
this.checkOpenIdLogin(res.code); let params = {
code: res.code
};
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token);
this.setData({
token: res.result.token,
userInfo: res.result.user
})
})
} else { } else {
wx.showToast({ wx.showToast({
icon: "none", icon: "none",
@@ -40,37 +47,9 @@ Page({
} }
}, },
// 微信一键登录
checkOpenIdLogin(code) {
let params = {
code: code
};
$.ajax("weighingScale/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token);
if(res.result.token && res.result.user) {
this.setData({
token: res.result.token,
userInfo: res.result.user
})
this.getDevice();
} else {
wx.showToast({
icon: "none",
title: "请先补全个人信息"
})
setTimeout(() => {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=0&customerType=1"
})
}, 1500)
}
})
},
// 打开设备详情 // 打开设备详情
openDeviceInfo() { openDeviceInfo() {
if(this.data.userInfo) { if(this.data.userInfo && this.data.token) {
let deviceInfo = this.data.deviceInfo; let deviceInfo = this.data.deviceInfo;
if(deviceInfo) { if(deviceInfo) {
wx.navigateTo({ wx.navigateTo({
@@ -98,20 +77,6 @@ Page({
} }
}, },
// 打开成员管理
openFamilyMembers() {
if(this.data.userInfo) {
wx.navigateTo({
url: "/pages/familyMembers/familyMembers"
})
} else {
wx.showToast({
icon: "none",
title: "请先登录"
})
}
},
// 获取已经绑定的设备列表 // 获取已经绑定的设备列表
getDevice() { getDevice() {
let params = {}; let params = {};
+7 -11
View File
@@ -1,9 +1,14 @@
<view class="userInfo"> <view class="userInfo">
<view class="user arrowAfter" bind:tap="openUserInfo"> <view class="user" bind:tap="openLoginOrReg">
<view> <view>
<image src="/images/my/user.png" /> <image src="/images/my/user.png" />
</view> </view>
<view>{{userInfo && userInfo.realname ? userInfo.realname : '未登录'}}</view> <view>
<block wx:if="{{userInfo || token}}">
{{userInfo ? userInfo.realname : '已登录'}}
</block>
<block wx:else>未登录</block>
</view>
</view> </view>
<view class="info"> <view class="info">
<view> <view>
@@ -33,15 +38,6 @@
<view>设备绑定</view> <view>设备绑定</view>
<view>{{deviceInfo ? '已绑定('+ deviceInfo.equipmentName +')' : '未绑定'}}</view> <view>{{deviceInfo ? '已绑定('+ deviceInfo.equipmentName +')' : '未绑定'}}</view>
</view> </view>
<view class="list arrowAfter" bind:tap="openFamilyMembers">
<view>
<image src="/images/my/2.png" />
</view>
<view>成员管理</view>
<view></view>
</view>
</view>
<view class="agreement">
<view class="list arrowAfter"> <view class="list arrowAfter">
<view> <view>
<image src="/images/my/3.png" /> <image src="/images/my/3.png" />
+1 -1
View File
@@ -75,7 +75,7 @@
width: 100%; width: 100%;
padding: 0 30rpx; padding: 0 30rpx;
box-sizing: border-box; box-sizing: border-box;
margin-bottom: 360rpx; margin-bottom: 480rpx;
} }
.content .arrowAfter::after { .content .arrowAfter::after {
+100 -99
View File
@@ -10,110 +10,136 @@ Page({
}, },
onLoad(options) { onLoad(options) {
this.initBluetooth(); this.checkBluetoothPermissionAndInit();
}, },
onShow() { onShow() {
if (this.data.getDeviceSetting) { if (this.data.getDeviceSetting) {
this.getDeviceSettingList(); this.getDeviceSettingList();
} else {
this.checkBluetoothPermissionAndInit();
} }
}, },
// 初始化蓝牙 checkBluetoothPermissionAndInit() {
initBluetooth() { this.setData({
initText: "正在检查蓝牙权限..."
});
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.bluetooth']) {
this.openBluetoothAdapter();
} else {
wx.authorize({
scope: 'scope.bluetooth',
success: () => {
this.openBluetoothAdapter();
},
fail: (err) => {
this.setData({
initText: "蓝牙权限被拒绝。"
});
wx.showModal({
title: '提示',
content: '您拒绝了蓝牙权限,将无法连接蓝牙秤。是否前往设置开启?',
confirmText: '去开启',
cancelText: '不开启',
success: (modalRes) => {
if (modalRes.confirm) {
wx.openSetting({
success: (settingRes) => {
console.log('openSetting success', settingRes);
},
fail: (settingErr) => {
wx.navigateBack({
delta: 1
});
}
});
} else {
wx.navigateBack({
delta: 1
});
}
}
});
}
});
}
},
fail: (err) => {
this.setData({
initText: "获取权限设置失败。"
});
wx.showToast({
title: '获取权限设置失败',
icon: 'none'
});
wx.navigateBack({
delta: 1
});
}
});
},
openBluetoothAdapter() {
this.setData({ this.setData({
initText: "正在初始化蓝牙..." initText: "正在初始化蓝牙..."
}) });
wx.openBluetoothAdapter({ wx.openBluetoothAdapter({
success: () => { success: () => {
this.setData({ this.setData({
initText: "蓝牙初始化成功" initText: "蓝牙初始化成功"
}) });
this.getDeviceSettingList(); this.getDeviceSettingList();
}, },
fail: (err) => { fail: (err) => {
this.setData({ this.setData({
initText: "蓝牙初始化失败" initText: "蓝牙初始化失败"
}) });
if (err.errCode === 10001) { if (err.errCode === 10001) {
wx.showModal({ wx.showModal({
title: "提示", title: "提示",
content: "请打开手机蓝牙", content: "请确保手机蓝牙已开启。",
showCancel: false,
success: () => {
wx.navigateBack({
delta: 1
});
}
});
} else if (err.errMsg && err.errMsg.includes('permission denied')) {
wx.showModal({
title: '提示',
content: '蓝牙权限仍被拒绝,无法使用蓝牙功能。',
showCancel: false,
success: () => {
wx.navigateBack({
delta: 1
});
}
});
} else {
wx.showToast({
title: `蓝牙适配器打开失败: ${err.errMsg || err.errCode}`,
icon: 'none',
success: () => {
wx.navigateBack({
delta: 1
});
}
}); });
} }
}, },
}); });
}, },
// async refreshToken(fn, flag) {
// let bodyToken = wx.getStorageSync('bodyToken');
// let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
// if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
// let res = await app.globalData.ppScale.plugin.refreshToken({
// url: "https://uniquehealth.lefuenergy.com",
// data: {
// "appKey": app.globalData.ppScale.options.key,
// "appSecret": app.globalData.ppScale.options.secret
// }
// });
// if (res.data.code == 200) {
// wx.setStorageSync('bodyToken', res.data.data.token);
// wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
// fn();
// }
// } else {
// fn();
// }
// },
// getDeviceSettingList() {
// this.setData({
// initText: "获取设备配置中..."
// })
// let bodyToken = wx.getStorageSync("bodyToken");
// app.globalData.ppScale.plugin.getDeviceSettingList({
// url: "https://uniquehealth.lefuenergy.com",
// data: {
// appKey: app.globalData.ppScale.options.key
// },
// header: {
// "token": bodyToken,
// "Accept-Language": wx.getStorageSync("lang") || 'zh'
// }
// }).then((res) => {
// if (res.data.code == 200) {
// this.setData({
// initText: "设备搜索中..."
// });
// app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data);
// app.globalData.ppScale.device.setting = res.data.data;
// let deviceNames = res.data.data.map(item => item.deviceName);
// app.globalData.ppScale.plugin.Blue.start(deviceNames, false);
// app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
// console.log("searchDevice ===> devicesList", res_);
// this.setData({
// getDeviceSetting: false,
// initText: "设备搜索完成"
// });
// app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
// app.globalData.ppScale.device.list = res_;
// app.globalData.ppScale.device.connection = res_[0];
// wx.navigateTo({
// url: "/pages/connectedDevice/connectedDevice"
// })
// });
// } else if (res.data.code == 401 || res.data.code == 4008) {
// this.refreshToken(() => {
// this.getDeviceSettingList();
// }, true);
// }
// });
// },
getDeviceSettingList() { getDeviceSettingList() {
// app.globalData.ppScale.plugin.Blue.visibleLog(true); // app.globalData.ppScale.plugin.Blue.visibleLog(true);
this.setData({ this.setData({
initText: "设备搜索中..." initText: "设备搜索中..."
}); });
app.globalData.ppScale.device.list = [];
let seviceList = app.globalData.ppScale.device.setting; let seviceList = app.globalData.ppScale.device.setting;
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList); app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
let deviceNames = seviceList.map(item => item.deviceName); let deviceNames = seviceList.map(item => item.deviceName);
@@ -126,11 +152,6 @@ Page({
}); });
this.selectDevice(); this.selectDevice();
}); });
app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("searchDevice ===》devicesModel", res);
app.globalData.ppScale.device.mac = res.deviceMac;
});
}, },
selectDevice() { selectDevice() {
@@ -141,30 +162,10 @@ Page({
setTimeout(() => { setTimeout(() => {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery(); app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.device.list = this.data.devicesList; app.globalData.ppScale.device.list = this.data.devicesList;
if(this.data.devicesList.length === 1) {
app.globalData.ppScale.device.connection = this.data.devicesList[0];
wx.redirectTo({ wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice" url: "/pages/configureDevice/configureDevice"
}) })
} else { }, 1000);
let itemLists = this.data.devicesList.map(item => item.name);
wx.showActionSheet({
itemList: itemLists,
alertText: "请选择你要使用的设备",
success: (res) => {
app.globalData.ppScale.device.connection = this.data.devicesList[res.tapIndex];
wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice"
})
},
fail: () => {
wx.navigateBack({
delta: 1
})
}
})
}
}, 3000);
} }
} }
}) })
-83
View File
@@ -1,83 +0,0 @@
const app = getApp();
import $ from "../../utils/request";
Page({
onLoad(options) {
let ssid = options.ssid;
let password = options.password;
app.globalData.ppScale.activeProtocol.dataConfigNetWork({
domain: app.globalData.ppScale.domain,
ssid: options.ssid,
password: options.password
}, (res) => {
console.log("setNetwork.js dataConfigNetWork", res);
if(res === 23) {
app.globalData.ppScale.wifi.ssid = ssid;
app.globalData.ppScale.wifi.password = password;
let mac = app.globalData.ppScale.device.mac;
let deviceId = app.globalData.ppScale.device.connection.deviceId;
if(mac && deviceId) {
let scaleDeviceId = mac.replace(/:/g, '');
let params = {
equipmentName: app.globalData.ppScale.device.name,
scaleDeviceId: scaleDeviceId,
deviceId: deviceId
};
$.ajax("weighingScale/binding/device", params, "POST").then(res => {
if (res.success) {
app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
console.log("setNetwork.js codeSetBindingState", res);
wx.navigateTo({
url: "/pages/setNetworkSuccessful/setNetworkSuccessful"
})
})
} else {
wx.showToast({
icon: "none",
title: res.message
})
setTimeout(() => {
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
}
}).catch(err => {
wx.showToast({
icon: "none",
title: err.message
})
setTimeout(() => {
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
})
} else {
wx.showToast({
icon: "none",
title: "Mac 地址与 deviceId 获取失败,请重新绑定"
})
setTimeout(() => {
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
}
} else {
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
}
})
}
})
-5
View File
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "正在配网",
"disableScroll": true
}
-13
View File
@@ -1,13 +0,0 @@
<view class="icon">
<view>
<image src="/images/setNetwork/icon.png" />
</view>
<view>已链接,配网中...</view>
<view>请持续站在秤上,耐心等待</view>
</view>
<view class="describe">
<view>手机尽量靠近设备(2米以内)</view>
<view>Wi-Fi指示灯闪烁,处于配网状态</view>
<view>Wi-Fi指示灯长亮为已连接状态</view>
</view>
-54
View File
@@ -1,54 +0,0 @@
page {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 90rpx 60rpx 120rpx;
background-color: #ffffff;
}
.icon {
width: 100%;
}
.icon>view:nth-of-type(1) {
width: 565rpx;
height: 500rpx;
margin: 0 auto;
}
.icon>view:nth-of-type(2) {
color: #1385FA;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 36rpx;
text-align: center;
margin-bottom: 28rpx;
}
.icon>view:nth-of-type(3) {
color: #808080;
width: 100%;
height: 30rpx;
font-size: 30rpx;
text-align: center;
line-height: 30rpx;
}
.describe {
width: 100%;
}
.describe>view {
color: #808080;
width: 100%;
font-size: 26rpx;
font-weight: bold;
line-height: 26rpx;
margin-bottom: 26rpx;
}
.describe>view:last-of-type {
margin-bottom: 0;
}
@@ -1,128 +0,0 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
userInfo: null,
subUser: {
i: 0,
data: []
},
ssid: ""
},
onLoad(options) {
this.setData({
userInfo: wx.getStorageSync("userInfo"),
ssid: app.globalData.ppScale.wifi.ssid
});
this.getSubUser();
},
completeClick() {
let userInfo = this.data.userInfo;
// 设置主用户时userID为小程序的用户IDmemberID为空
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: userInfo.id,
userName: userInfo.realname,
memberID: "",
age: this.getAge(userInfo.birthday), //
gender: userInfo.sex, //
height: userInfo.height, //
isAthleteMode: 0,
currentWeight: userInfo.weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
console.log("dataSyncUserInfo", res);
if(this.data.subUser.data && this.data.subUser.data.length) {
wx.showLoading({
title: "正在同步用户信息,请稍等...",
mask: true
});
this.setSubUser();
} else {
this.resetDevice();
app.globalData.ppScale.plugin.Blue.stop();
wx.switchTab({
url: "/pages/home/home"
})
}
})
},
setSubUser() {
let userInfo = this.data.userInfo;
let i = this.data.subUser.i;
let subUser = this.data.subUser.data;
if(i < subUser.length) {
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: userInfo.id,
userName: subUser[i].realname,
memberID: subUser[i].id,
age: this.getAge(subUser[i].birthday), //
gender: subUser[i].sex, //
height: subUser[i].height, //
isAthleteMode: 0,
currentWeight: subUser[i].weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
console.log("dataSyncSubUserInfo", res);
this.setData({
['subUser.i']: i + 1
})
this.setSubUser();
})
} else {
this.resetDevice();
app.globalData.ppScale.plugin.Blue.stop();
wx.hideLoading();
wx.switchTab({
url: "/pages/home/home"
})
}
},
resetDevice() {
app.globalData.ppScale.device = {
list: [],
mac: null,
name: "",
connection: null
}
},
// 获取家庭成员列表
getSubUser() {
let params = {};
$.ajax("weighingScale/list/subUser", params, "GET", true, "正在获取成员列表...").then(res => {
this.setData({
['subUser.data']: res.result
})
})
},
// 根据生日获取年龄
getAge(birthDateString) {
const birthDate = new Date(birthDateString);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
const dayDiff = today.getDate() - birthDate.getDate();
// 如果当前月份小于出生月份,或者同月但当前日期小于出生日期,年龄需要减 1
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
age--;
}
return age;
}
})
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "绑定成功",
"disableScroll": true
}
@@ -1,21 +0,0 @@
<view class="icon">
<view>
<image src="/images/setNetworkSuccessful/icon.png" />
</view>
<view>配网成功</view>
</view>
<view class="info">
<view>当前设备配置Wi-Fi</view>
<view>
<view>
<image src="/images/setNetworkSuccessful/wifi.png" />
</view>
<view>{{ssid}}</view>
<view>
<image src="/images/setNetworkSuccessful/success.png" />
</view>
</view>
</view>
<view class="btn" bind:tap="completeClick">完成</view>
@@ -1,93 +0,0 @@
page {
width: 100%;
padding: 200rpx 85rpx 0;
box-sizing: border-box;
background-color: #ffffff;
}
.icon {
width: 100%;
margin-bottom: 120rpx;
}
.icon>view:first-of-type {
width: 360rpx;
height: 295rpx;
margin: 0 auto 50rpx;
}
.icon>view:last-of-type {
color: #252535;
width: 100%;
height: 40rpx;
font-size: 40rpx;
font-weight: bold;
line-height: 40rpx;
text-align: center;
}
.info {
width: 100%;
margin-bottom: 380rpx;
}
.info>view:first-of-type {
color: #B6B6B6;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
margin-bottom: 40rpx;
}
.info>view:last-of-type {
width: 100%;
height: 80rpx;
margin: 30rpx 0;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.info>view:last-of-type>view:nth-of-type(1) {
width: 80rpx;
height: 80rpx;
margin-right: 24rpx;
}
.info>view:last-of-type>view:nth-of-type(2) {
color: #252535;
flex: 1;
width: 0;
height: 80rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 80rpx;
}
.info>view:last-of-type>view:nth-of-type(3) {
width: 32rpx;
height: 32rpx;
}
.describe {
color: #B6B6B6;
width: 100%;
height: 26rpx;
font-size: 28rpx;
line-height: 28rpx;
text-align: center;
margin-bottom: 46rpx;
}
.btn {
color: #FFFFFF;
width: 100%;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
text-align: center;
border-radius: 44rpx;
background-color: #1385FA;
}
-35
View File
@@ -1,35 +0,0 @@
const app = getApp();
Page({
data: {
type: true,
wifiInfo: null,
password: ""
},
onLoad(options) {
this.setData({
wifiInfo: JSON.parse(options.item)
})
},
passwordInput(e) {
this.setData({
password: e.detail.value
})
},
inputTypeChange() {
this.setData({
type: !this.data.type
})
},
// 打开配网
openSetNetwork() {
wx.navigateTo({
url: "/pages/setNetwork/setNetwork?ssid=" + this.data.wifiInfo.ssid + "&password=" + this.data.password
})
}
})
@@ -1,5 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "输入Wi-Fi密码",
"disableScroll": true
}
@@ -1,24 +0,0 @@
<view class="form">
<view>
<view>
<image src="/images/setWifiPassword/icon.png" />
</view>
<view>{{wifiInfo.ssid}}</view>
</view>
<view>
<view>密码</view>
<view>
<input
password="{{type}}"
value="{{password}}"
bindinput="passwordInput"
placeholder="8~16位密码"
placeholder-class="placeholderClass" />
</view>
<view bind:tap="inputTypeChange">
<image src="/images/setWifiPassword/open.png" />
</view>
</view>
</view>
<view class="btn" bind:tap="openSetNetwork">连接</view>
@@ -1,81 +0,0 @@
page {
padding: 55rpx 55rpx 0;
background-color: #ffffff;
}
.form {
width: 100%;
margin-bottom: 64rpx;
}
.form>view {
width: 100%;
height: 96rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 0 24rpx;
box-sizing: border-box;
border-radius: 16rpx;
background-color: #F6F6F6;
}
.form>view:first-of-type {
margin-bottom: 32rpx;
}
.form>view>view:nth-of-type(1) {
color: #252535;
width: 100rpx;
height: 96rpx;
line-height: 96rpx;
font-size: 32rpx;
font-weight: bold;
}
.form>view:first-of-type>view:nth-of-type(1) {
padding: 24rpx 45rpx 24rpx 7rpx;
box-sizing: border-box;
display: flex;
align-items: center;
}
.form>view>view:nth-of-type(2) {
color: #252535;
flex: 1;
width: 0;
height: 96rpx;
font-size: 32rpx;
line-height: 96rpx;
}
.form>view>view:nth-of-type(2) input {
color: #252535;
width: 100%;
height: 96rpx;
font-size: 32rpx;
line-height: 96rpx;
}
.placeholderClass {
color: #B6B6B6;
font-size: 32rpx;
}
.form>view>view:nth-of-type(3) {
width: 56rpx;
height: 56rpx;
}
.btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
margin: 0 auto;
text-align: center;
border-radius: 44rpx;
background-color: #1385FA;
}
-553
View File
@@ -1,553 +0,0 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
deviceConnect: false,
initBluetooth: "0",
customerType: "1",
deviceInfo: null,
seviceList: [],
userInfo: null,
id: "",
realname: "",
sex: {
index: null,
data: [{
id: 1,
name: '男'
}, {
id: 2,
name: '女'
}]
},
birthday: {
label: "1980年01月01日",
value: "1980-01-01"
},
phone: "",
height: {
index: 50,
data: Array.from({ length: 200 - 120 + 1 }, (_, i) => i + 120)
},
weight: {
index: 20,
data: Array.from({ length: 100 - 50 + 1 }, (_, i) => i + 50)
},
connectedDevice: {
code: "",
color: "",
message: ""
}
},
onLoad(options) {
// initBluetooth 是否初始化蓝牙和设备 1 是 / 0 否
// customerType 用户类型 1 自己 / 0 他人
// id 用户ID 当customerType为0时,家庭成员的用户ID / 为1时始终为空字符串
this.setData({
id: options.id ? options.id : null,
initBluetooth: options.initBluetooth,
customerType: options.customerType,
})
if(options.customerType === "0") {
wx.setNavigationBarTitle({
title: options.id ? '编辑成员档案' : '新增成员档案'
})
if(options.id) {
this.subUserInfo()
}
} else {
let userInfo = wx.getStorageSync("userInfo") || null;
if (userInfo && options.initBluetooth === "1") {
let [year, month, day] = userInfo.birthday.split("-");
this.setData({
userInfo: userInfo,
realname: userInfo.realname,
["sex.index"]: this.data.sex.data.findIndex(item => {return item.id === userInfo.sex}),
birthday: {
label: year + "年" + month + "月" + day + "日",
value: userInfo.birthday
},
phone: userInfo.phone,
["height.index"]: this.data.height.data.findIndex(item => {return item === userInfo.height}),
["weight.index"]: this.data.weight.data.findIndex(item => {return item === userInfo.weight}),
})
}
}
if(options.initBluetooth === "1") {
this.initBluetooth();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('userInfo ===》deviceConnect', res);
this.setData({
connectedDevice: {
code: "",
color: "#2AC79F",
message: "等待设备回应"
}
})
app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("userInfo ===》codeUpdateMTU", res);
this.setData({
deviceConnect: true,
connectedDevice: {
code: "",
color: "#2AC79F",
message: "已连接"
}
})
});
});
}
},
// 获取已经绑定的设备列表
getDevice() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "获取设备列表"
}
})
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
if(res.result && res.result.length) {
this.setData({
deviceInfo: res.result[0]
})
this.getDeviceSettingList();
} else {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "未绑定设备"
}
})
wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
} else if (res.cancel) {
wx.navigateBack({
delta: 1
})
}
}
})
}
})
},
// 初始化蓝牙
initBluetooth() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "初始化蓝牙"
}
})
wx.openBluetoothAdapter({
success: () => {
this.getDevice();
},
fail: (err) => {
if (err.errCode === 10001) {
this.setData({
connectedDevice: {
code: "",
color: "#F24439",
message: "初始化蓝牙失败"
}
})
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
getDeviceSettingList() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "获取配置信息"
}
})
let seviceList = [];
app.globalData.ppScale.device.setting.map(item => {
if(this.data.deviceInfo && this.data.deviceInfo.type === item.deviceName) {
seviceList.push(item);
}
})
this.setData({
seviceList: seviceList,
connectedDevice: {
code: "",
color: "#2AC79F",
message: "配置获取成功"
}
})
if(seviceList && seviceList.length) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "开始搜索设备"
}
})
app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
console.log("deviceInfo ===> devicesList", res);
let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "设备搜索中"
}
})
if (fIndex >= 0) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
this.setData({
connectedDevice: {
code: "",
color: "#2AC79F",
message: "连接中"
}
})
app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
return;
}
});
}
},
// 姓名输入
realnameInput(e) {
let realname = e.detail.value.replace(/\s+/g, '');
this.setData({
realname: realname
})
},
// 性别选择
sexChange(e) {
let sex = e.detail.value;
console.log(sex);
this.setData({
['sex.index']: e.detail.value
})
if(this.data.height.index === null) {
this.setData({
['height.index']: sex == 0 ? 50 : 40
})
}
if(this.data.weight.index === null) {
this.setData({
['weight.index']: sex == 0 ? 20 : 10
})
}
},
// 生日选择
birthdayChange(e) {
let v = e.detail.value;
let [year, month, day] = v.split("-");
this.setData({
birthday: {
label: year + "年" + month + "月" + day + "日",
value: v
}
})
},
// 获取手机号
getPhoneNumber(e) {
let params = {
code: e.detail.code,
thirdId: wx.getStorageSync("userInfo").thirdId
};
$.ajax("weighingScale/getPhone", params, "POST").then(res => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token);
this.setData({
phone: res.result.user.phone
})
})
},
// 身高选择
heightChange(e) {
this.setData({
['height.index']: e.detail.value
})
},
// 体重选择
weightChange(e) {
this.setData({
['weight.index']: e.detail.value
})
},
// 提交判断
submit() {
let realname = this.data.realname;
let sex = this.data.sex;
let birthday = this.data.birthday;
let phone = this.data.phone;
let height = this.data.height;
let weight = this.data.weight;
if(this.data.initBluetooth === "1" && !this.data.deviceConnect) {
wx.showToast({
icon: "none",
title: "请靠近设备并点亮后再试"
})
app.globalData.ppScale.plugin.Blue.start(this.data.seviceList[0].deviceName, false);
return false;
}
if(!realname) {
wx.showToast({
icon: "none",
title: "姓名不能为空"
})
return false;
}
if(sex.index === null) {
wx.showToast({
icon: "none",
title: "性别不能为空"
})
return false;
}
if(!birthday.value) {
wx.showToast({
icon: "none",
title: "生日不能为空"
})
return false;
}
if(this.data.customerType === "1" && !phone) {
wx.showToast({
icon: "none",
title: "手机号不能为空"
})
return false;
}
if(height.index === null) {
wx.showToast({
icon: "none",
title: "身高不能为空"
})
return false;
}
if(weight.index === null) {
wx.showToast({
icon: "none",
title: "体重不能为空"
})
return false;
}
if(this.data.customerType === "1") {
this.submitMe({
realname: realname,
sex: sex.data[sex.index].id,
birthday: birthday.value,
phone: phone,
height: height.data[height.index],
weight: weight.data[weight.index]
});
} else {
this.submitUser({
id: this.data.id,
realname: realname,
sex: sex.data[sex.index].id,
birthday: birthday.value,
height: height.data[height.index],
weight: weight.data[weight.index]
});
}
},
// 提交自己的信息
submitMe(params) {
$.ajax("weighingScale/edit/user", params, "POST", true, "保存中...").then(res => {
$.ajax("weighingScale/select/user", {}, "GET", true, "更新用户信息中...").then(res_ => {
wx.setStorageSync("userInfo", res_.result);
wx.showToast({
icon: "none",
title: res.message
})
if(this.data.initBluetooth === "1") {
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: res_.result.id,
userName: res_.result.realname,
memberID: "",
age: this.getAge(res_.result.birthday), //
gender: res_.result.sex, //
height: res_.result.height, //
isAthleteMode: 0,
currentWeight: res_.result.weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
console.log("dataSyncUserInfo", res)
app.globalData.ppScale.plugin.Blue.stop();
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
})
} else {
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
}
})
})
},
// 提交家庭成员的信息
submitUser(params) {
$.ajax("weighingScale/edit/subUser", params, "POST", true, "保存中...").then(res => {
wx.showToast({
icon: "none",
title: res.message
})
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: wx.getStorageSync("userInfo").id,
userName: params.realname,
memberID: res.result,
age: this.getAge(params.birthday), //
gender: params.sex, //
height: params.height, //
isAthleteMode: 0,
currentWeight: params.weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
recentData: [],
}, (res) => {
console.log("dataSyncUserInfo", res)
app.globalData.ppScale.plugin.Blue.stop();
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
})
})
},
// 删除家庭成员
delUser() {
if(this.data.deviceConnect) {
wx.showModal({
title: "提示",
content: "你要定要删除此成员吗?",
success: (res) => {
if (res.confirm) {
let params = {
id: this.data.id
};
console.log(params);
$.ajax("weighingScale/del/subUser", params, "POST", true, "删除中...").then(res => {
wx.showToast({
icon: "none",
title: res.message
})
app.globalData.ppScale.activeProtocol.dataDeleteUser({
userID: wx.getStorageSync("userInfo").id,
memberID: this.data.id,
}, (res) => {
console.log("dataDeleteUser", res);
app.globalData.ppScale.plugin.Blue.stop();
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500);
})
})
}
}
})
} else {
wx.showToast({
icon: "none",
title: "删除失败,请靠近设备并点亮后再试"
})
app.globalData.ppScale.plugin.Blue.start(this.data.seviceList[0].deviceName, false);
}
},
// 获取家庭成员信息详情
subUserInfo() {
let params = {
userId: this.data.id
};
$.ajax("weighingScale/select/subUser", params, "GET", false).then(res => {
let [year, month, day] = res.result.birthday.split("-");
this.setData({
realname: res.result.realname,
["sex.index"]: this.data.sex.data.findIndex(item => {return item.id === res.result.sex}),
birthday: {
label: year + "年" + month + "月" + day + "日",
value: res.result.birthday
},
["height.index"]: this.data.height.data.findIndex(item => {return item === res.result.height}),
["weight.index"]: this.data.weight.data.findIndex(item => {return item === res.result.weight}),
})
})
},
// 根据生日获取年龄
getAge(birthDateString) {
const birthDate = new Date(birthDateString);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
const dayDiff = today.getDate() - birthDate.getDate();
// 如果当前月份小于出生月份,或者同月但当前日期小于出生日期,年龄需要减 1
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
age--;
}
return age;
},
onUnload() {
if(this.data.initBluetooth === "1") {
app.globalData.ppScale.plugin.Blue.stop();
}
}
})
-6
View File
@@ -1,6 +0,0 @@
{
"usingComponents": {},
"navigationBarTitleText": "用户档案",
"navigationBarBackgroundColor": "#F5F7FB",
"disableScroll": true
}
-81
View File
@@ -1,81 +0,0 @@
<block wx:if="{{initBluetooth === '1'}}">
<view class="device">
<view>
<view>{{deviceInfo && deviceInfo.equipmentName ? deviceInfo.equipmentName : '获取中...'}}</view>
<view>型号:{{deviceInfo && deviceInfo.type ? deviceInfo.type : '获取中...'}}</view>
</view>
<view>
<view style="background-color: {{connectedDevice.color}};"></view>
<view style="color: {{connectedDevice.color}};">{{connectedDevice.message}}</view>
</view>
</view>
</block>
<view class="form">
<view>
<view>姓名</view>
<view>
<input
type="text"
value="{{realname}}"
bindinput="realnameInput"
placeholder="请输入姓名"
placeholder-class="placeholderClass" />
</view>
</view>
<view>
<view>性别</view>
<view class="arrowAfter">
<picker bindchange="sexChange" value="{{sex.index}}" range="{{sex.data}}" range-key="name">
{{sex.index === null ? '请选择性别' : sex.data[sex.index].name}}
</picker>
</view>
</view>
<view>
<view>生日</view>
<view class="arrowAfter">
<picker bindchange="birthdayChange" mode="date" value="{{birthday.value}}">
{{birthday.value ? birthday.label : '请选择生日'}}
</picker>
</view>
</view>
<block wx:if="{{customerType === '1'}}">
<view>
<view>手机号</view>
<view>
<block wx:if="{{phone}}">
{{phone}}
</block>
<block wx:else>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">点击获取手机号</button>
</block>
</view>
</view>
</block>
<view>
<view>身高</view>
<view class="arrowAfter">
<picker bindchange="heightChange" value="{{height.index}}" range="{{height.data}}">
{{height.index === null ? '请选择身高' : height.data[height.index] + ' cm'}}
</picker>
</view>
</view>
<view>
<view>体重</view>
<view class="arrowAfter">
<picker bindchange="weightChange" value="{{weight.index}}" range="{{weight.data}}">
{{weight.index === null ? '请选择体重' : weight.data[weight.index] + ' kg'}}
</picker>
</view>
</view>
</view>
<view class="btn" bind:tap="submit">确定</view>
<block wx:if="{{!userInfo && !id}}">
<view class="tips">请填写和完善您家人的健康信息,将用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。我们会严格保护您的家庭信息安全。</view>
</block>
<block wx:if="{{customerType === '0' && id}}">
<view class="delBtn" bind:tap="delUser">删除该档案</view>
</block>
-145
View File
@@ -1,145 +0,0 @@
page {
padding: 30rpx 30rpx 0;
}
.device {
width: 100%;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 35rpx 40rpx;
border-radius: 24rpx;
box-sizing: border-box;
margin-bottom: 24rpx;
background-color: #FFFFFF;
justify-content: space-between;
}
.device>view:nth-of-type(1)>view:nth-of-type(1) {
color: #252535;
height: 32rpx;
font-weight: bold;
font-size: 32rpx;
line-height: 32rpx;
margin-bottom: 22rpx;
}
.device>view:nth-of-type(1)>view:nth-of-type(2) {
color: #808080;
height: 26rpx;
font-size: 26rpx;
line-height: 26rpx;
}
.device>view:nth-of-type(2) {
height: 28rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.device>view:nth-of-type(2)>view:nth-of-type(1) {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
}
.device>view:nth-of-type(2)>view:nth-of-type(2) {
height: 28rpx;
font-weight: bold;
font-size: 28rpx;
line-height: 28rpx;
padding-left: 8rpx;
}
.form {
width: 100%;
padding: 0 30rpx;
border-radius: 16rpx;
box-sizing: border-box;
background-color: #FFFFFF;
margin-bottom: 80rpx;
}
.form>view {
width: 100%;
height: 120rpx;
padding: 0 10rpx;
display: flex;
flex-wrap: nowrap;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
}
.form>view>view:first-of-type {
color: #252535;
height: 120rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 120rpx;
}
.form>view>view:last-of-type {
flex: 1;
width: 0;
color: #B6B6B6;
font-size: 28rpx;
height: 120rpx;
line-height: 120rpx;
text-align: right;
}
.form>view>view:last-of-type.arrowAfter {
padding-right: 30rpx;
}
.form>view>view:last-of-type input {
color: #252535;
width: 100%;
height: 120rpx;
line-height: 120rpx;
text-align: right;
}
.placeholderClass {
color: #B6B6B6;
font-size: 28rpx;
}
.form>view {
border-bottom: 0;
}
.btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
text-align: center;
border-radius: 44rpx;
margin: 0 auto 50rpx;
background-color: #1385FA;
}
.tips {
color: #77849E;
width: 100%;
font-size: 26rpx;
line-height: 40rpx;
padding: 0 30rpx;
box-sizing: border-box;
}
.delBtn {
color: #1385FA;
width: 580rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
text-align: center;
border-radius: 44rpx;
margin: 0 auto;
}
+14 -2
View File
@@ -1,7 +1,7 @@
{ {
"appid": "wx6c71f3ebcdcddffd", "appid": "wx6c71f3ebcdcddffd",
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "3.7.11", "libVersion": "3.8.5",
"packOptions": { "packOptions": {
"ignore": [], "ignore": [],
"include": [] "include": []
@@ -18,7 +18,19 @@
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
} },
"compileWorklet": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"packNpmManually": false,
"minifyWXSS": true,
"minifyWXML": true,
"localPlugins": false,
"disableUseStrict": false,
"useCompilerPlugins": false,
"condition": false,
"swc": false,
"disableSWC": true
}, },
"condition": {}, "condition": {},
"editorSetting": { "editorSetting": {
+16 -2
View File
@@ -4,7 +4,21 @@
"setting": { "setting": {
"compileHotReLoad": true, "compileHotReLoad": true,
"urlCheck": false, "urlCheck": false,
"bigPackageSizeSupport": true "bigPackageSizeSupport": true,
"coverView": true,
"lazyloadPlaceholderEnable": false,
"skylineRenderEnable": false,
"preloadBackgroundData": false,
"autoAudits": false,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"useStaticServer": false,
"useLanDebug": false,
"showES6CompileOption": false,
"checkInvalidKey": true,
"ignoreDevUnusedFiles": true
}, },
"libVersion": "3.7.11" "libVersion": "3.8.5",
"condition": {}
} }