第一版

This commit is contained in:
17792275749
2025-03-25 20:52:15 +08:00
commit 04d373b84e
88 changed files with 4539 additions and 0 deletions
+107
View File
@@ -0,0 +1,107 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
name: "",
deviceSelect: null
},
onLoad(options) {
let name = app.globalData.ppScale.device.name;
let deviceSelect = app.globalData.ppScale.device.connection;
this.setData({
name: name ? name : deviceSelect.name,
deviceSelect: deviceSelect
})
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: 1
})
}, 1500);
});
})
} else if (res.cancel) {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
})
} else {
app.globalData.ppScale.device.name = this.data.name;
wx.navigateTo({
url: "/pages/connectionSuccessful/connectionSuccessful"
})
}
})
});
});
},
nameInput(e) {
this.setData({
name: e.detail.value
})
},
// 配对
openConnectionSuccessful() {
let deviceSelect = this.data.deviceSelect;
if (deviceSelect) {
let name = this.data.name;
if (name) {
wx.showLoading({
title: "蓝牙配对中...",
mask: true
});
app.globalData.ppScale.plugin.Blue.createBLEConnection(deviceSelect);
} else {
wx.showToast({
icon: "none",
title: "设备名称不能为空"
})
}
} else {
wx.showToast({
icon: "none",
title: "配对设备不能为空"
})
}
},
})
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "设备命名",
"disableScroll": true
}
@@ -0,0 +1,14 @@
<view class="equipmentModel">型号:{{deviceSelect.name}}</view>
<view class="equipmentIcon">
<image src="/images/connectedDevice/device.png" />
</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>
@@ -0,0 +1,68 @@
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;
}
@@ -0,0 +1,10 @@
const app = getApp();
Page({
// 获取wifi列表
openGetWifiList() {
wx.navigateTo({
url: "/pages/getWifiList/getWifiList"
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "绑定成功",
"disableScroll": true
}
@@ -0,0 +1,10 @@
<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>
@@ -0,0 +1,49 @@
page {
width: 100%;
padding: 200rpx 85rpx 0;
box-sizing: border-box;
background-color: #ffffff;
}
.icon {
width: 100%;
margin-bottom: 540rpx;
}
.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;
}
.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;
}
+151
View File
@@ -0,0 +1,151 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
deviceConnect: false,
deviceInfo: null
},
onLoad(options) {
this.getDevice();
this.initBluetooth();
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);
$.ajax("weighingScale/list/device", {}, "GET", false).then((res) => {
if(res.result && res.result.length) {
let deviceConnect = res.result.some(item => item.macAddress === app.globalData.ppScale.device.mac);
if(deviceConnect) {
this.setData({
deviceConnect: true
})
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
})
});
});
},
// 初始化蓝牙
initBluetooth() {
wx.openBluetoothAdapter({
success: () => {
this.getDeviceSettingList();
},
fail: (err) => {
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
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() {
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) {
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_) => {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]);
});
} else if (res.data.code == 401 || res.data.code == 4008) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
}
});
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
this.setData({
deviceInfo: res.result[0]
})
})
},
delDevice() {
if(this.data.deviceConnect) {
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,
})
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500);
});
})
} else {
wx.showToast({
icon: "none",
title: "删除失败,请靠近设备并点亮后再试"
})
this.initBluetooth();
}
},
onUnload() {
app.globalData.ppScale.plugin.Blue.stop();
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "设备详情",
"disableScroll": true
}
+34
View File
@@ -0,0 +1,34 @@
<view class="device">
<view>
<image src="/images/deviceInfo/device.png" />
</view>
<view>
<view>{{deviceInfo.equipmentName}}</view>
<view>型号:{{deviceInfo.type}}</view>
</view>
</view>
<view class="info">
<view>
<view>设备名称</view>
<view>{{deviceInfo.equipmentName}}</view>
</view>
<view>
<view>设备SN</view>
<view>{{deviceInfo.equipmentCode}}</view>
</view>
<view>
<view>配置Wi-Fi</view>
<view class="arrowAfter" style="padding-right: 30rpx;">{{deviceInfo.wifiName}}</view>
</view>
<view>
<view>成员</view>
<view>{{deviceInfo.subUserNum}}人</view>
</view>
<view>
<view>MAC地址</view>
<view>{{deviceInfo.macAddress}}</view>
</view>
</view>
<view class="btn" bind:tap="delDevice">删除设备</view>
+94
View File
@@ -0,0 +1,94 @@
page {
padding: 30rpx 30rpx 0;
}
.device {
width: 100%;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 30rpx;
box-sizing: border-box;
border-radius: 24rpx;
margin-bottom: 24rpx;
background-color: #FFFFFF;
}
.device>view:first-of-type {
width: 180rpx;
height: 180rpx;
margin-right: 20rpx;
}
.device>view:last-of-type {
flex: 1;
width: 0;
}
.device>view:last-of-type>view:first-of-type {
color: #252535;
width: 100%;
height: 40rpx;
font-weight: bold;
font-size: 40rpx;
line-height: 40rpx;
margin-bottom: 22rpx;
}
.device>view:last-of-type>view:last-of-type {
color: #808080;
width: 100%;
height: 26rpx;
font-size: 26rpx;
line-height: 26rpx;
}
.info {
width: 100%;
border-radius: 24rpx;
margin-bottom: 88rpx;
background-color: #FFFFFF;
}
.info>view {
width: 100%;
height: 120rpx;
padding: 0 30rpx;
box-sizing: border-box;
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
border-bottom: 1rpx solid #EAECF1;
}
.info>view:last-of-type {
border-bottom: 0;
}
.info>view>view {
height: 120rpx;
font-size: 30rpx;
line-height: 120rpx;
}
.info>view>view:first-of-type {
color: #252535;
font-weight: bold;
}
.info>view>view:last-of-type {
color: #808080;
}
.btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
margin: 0 auto;
font-size: 32rpx;
font-weight: bold;
line-height: 88rpx;
text-align: center;
border-radius: 44rpx;
background-color: #1385FA;
}
+45
View File
@@ -0,0 +1,45 @@
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
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "家庭成员",
"disableScroll": true
}
+31
View File
@@ -0,0 +1,31 @@
<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">
<view>
<image src="/images/familyMembers/add.png" />
</view>
<view bind:tap="openUserInfo">添加新成员</view>
</view>
+128
View File
@@ -0,0 +1,128 @@
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
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,4 @@
{
"usingComponents": {},
"disableScroll": true
}
+19
View File
@@ -0,0 +1,19 @@
<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
@@ -0,0 +1,64 @@
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;
}
+92
View File
@@ -0,0 +1,92 @@
import $ from "../../utils/request";
Page({
data: {
token: null,
userInfo: null,
deviceList: []
},
onShow() {
let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null;
this.setData({
token: token,
userInfo: userInfo
})
if(token && userInfo) {
this.getDevice();
}
},
// 点击登录或注册
openLoginOrReg() {
wx.login({
success: (res) => {
if (res.code) {
this.checkOpenIdLogin(res.code);
} 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);
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)
}
})
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => {
this.setData({
deviceList: res.result
})
})
},
// 添加设备
openSearchDevice() {
let token = this.data.token;
let userInfo = this.data.userInfo;
if (token && userInfo) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
} else {
wx.showToast({
icon: "none",
title: "请先登录"
})
}
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationStyle": "custom",
"disableScroll": true
}
+37
View File
@@ -0,0 +1,37 @@
<view class="bg">
<image src="/images/home/bg.jpg"/>
</view>
<view class="home">
<view class="title">
<view>
<view>
<block wx:if="{{userInfo && userInfo.avatar}}">
<image src="{{userInfo.avatar}}" />
</block>
<block wx:else>
<image src="/images/home/user.png" />
</block>
</view>
<block wx:if="{{userInfo && token}}">
<view>{{userInfo.realname}}</view>
</block>
<block wx:else>
<view class="arrowAfter" bind:tap="openLoginOrReg">登录/注册</view>
</block>
</view>
<view>智能体脂秤</view>
<view>注重更好的健康生活品质</view>
<view></view>
</view>
<view class="device">
<view>请添加设备</view>
<view>添加设备后,解锁更多体验</view>
<block wx:if="{{userInfo && token}}">
<view bind:tap="openSearchDevice">添加设备</view>
</block>
<block wx:else>
<view bind:tap="openLoginOrReg">登录/注册</view>
</block>
</view>
</view>
+118
View File
@@ -0,0 +1,118 @@
.bg {
position: absolute;
z-index: 1;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
.home {
position: relative;
z-index: 2;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 215rpx 60rpx 120rpx;
box-sizing: border-box;
}
.title {
width: 100%;
}
.title>view:nth-of-type(1) {
width: 100%;
height: 80rpx;
display: flex;
flex-wrap: nowrap;
margin-bottom: 56rpx;
}
.title>view:nth-of-type(1)>view:first-of-type {
width: 80rpx;
height: 80rpx;
overflow: hidden;
border-radius: 50%;
margin-right: 20rpx;
}
.title>view:nth-of-type(1)>view:last-of-type {
color: #FFFFFF;
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
font-weight: bold;
padding-right: 26rpx;
}
.title>view:nth-of-type(1)>view:last-of-type::after {
border-left: 5rpx solid #ffffff;
border-top: 5rpx solid #ffffff;
}
.title>view:nth-of-type(2) {
color: #FFFFFF;
height: 58rpx;
font-size: 58rpx;
font-weight: bold;
line-height: 58rpx;
margin-bottom: 34rpx;
}
.title>view:nth-of-type(3) {
color: #FFFFFF;
height: 32rpx;
font-size: 32rpx;
line-height: 32rpx;
margin-bottom: 48rpx;
}
.title>view:nth-of-type(4) {
width: 120rpx;
height: 6rpx;
border-radius: 3rpx;
background-color: #FFFFFF;
}
.device {
width: 580rpx;
margin: 0 auto;
}
.device>view:nth-of-type(1) {
color: #FFFFFF;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
text-align: center;
line-height: 36rpx;
margin-bottom: 30rpx;
}
.device>view:nth-of-type(2) {
color: #FFFFFF;
width: 100%;
height: 30rpx;
font-size: 30rpx;
text-align: center;
line-height: 30rpx;
margin-bottom: 80rpx;
}
.device>view:nth-of-type(3) {
color: #FFFFFF;
width: 100%;
height: 106rpx;
font-size: 32rpx;
font-weight: bold;
text-align: center;
line-height: 106rpx;
border-radius: 16rpx;
border: 1rpx solid #FFFFFF;
}
+2
View File
@@ -0,0 +1,2 @@
// index.js
Page({})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+7
View File
@@ -0,0 +1,7 @@
<!--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
@@ -0,0 +1,10 @@
/**index.wxss**/
page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scrollarea {
flex: 1;
overflow-y: hidden;
}
+112
View File
@@ -0,0 +1,112 @@
import $ from "../../utils/request";
Page({
data: {
userInfo: null,
deviceInfo: null
},
onShow() {
let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null;
this.setData({
userInfo: userInfo
})
if(token && userInfo) {
this.getDevice();
}
},
// 打开用户信息
openUserInfo() {
if(this.data.userInfo) {
wx.navigateTo({
url: "/pages/userInfo/userInfo?initBluetooth=1&customerType=1"
})
} else {
wx.showToast({
icon: "none",
title: "请先登录"
})
}
},
// 打开设备详情
openDeviceInfo() {
if(this.data.userInfo) {
let deviceInfo = this.data.deviceInfo;
if(deviceInfo) {
wx.navigateTo({
url: "/pages/deviceInfo/deviceInfo"
})
} else {
wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
}
}
})
}
} else {
wx.showToast({
icon: "none",
title: "请先登录"
})
}
},
// 打开成员管理
openFamilyMembers() {
if(this.data.userInfo) {
wx.navigateTo({
url: "/pages/familyMembers/familyMembers"
})
} else {
wx.showToast({
icon: "none",
title: "请先登录"
})
}
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
this.setData({
deviceInfo: res.result && res.result.length ? res.result[0] : null
})
})
},
// 退出登录
exitLogin() {
wx.showModal({
title: "提示",
content: "你确定要退出登录吗?",
success: (res) => {
if (res.confirm) {
$.ajax("weighingScale/logout", {}, "POST", true, "正在退出登录...").then(res => {
wx.showToast({
icon: "none",
title: res.message
})
setTimeout(() => {
wx.clearStorageSync();
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
})
}
}
})
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationStyle": "custom",
"disableScroll": true
}
+59
View File
@@ -0,0 +1,59 @@
<view class="userInfo">
<view class="user arrowAfter" bind:tap="openUserInfo">
<view>
<image src="/images/my/user.png" />
</view>
<view>{{userInfo && userInfo.realname ? userInfo.realname : '未登录'}}</view>
</view>
<view class="info">
<view>
<view>身高(cm)</view>
<view>{{userInfo && userInfo.height ? userInfo.height : '--'}}</view>
</view>
<view></view>
<view>
<view>体重(kg)</view>
<view>{{userInfo && userInfo.weight ? userInfo.weight : '--'}}</view>
</view>
<view></view>
<view>
<view>BMI</view>
<view>{{userInfo && userInfo.bmi ? userInfo.bmi : '--'}}</view>
</view>
</view>
</view>
<view class="content">
<view class="service">
<view class="title">我的服务</view>
<view class="list arrowAfter" bind:tap="openDeviceInfo">
<view>
<image src="/images/my/1.png" />
</view>
<view>设备绑定</view>
<view>{{deviceInfo ? '已绑定('+ deviceInfo.equipmentName +')' : '未绑定'}}</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>
<image src="/images/my/3.png" />
</view>
<view>隐私协议</view>
<view></view>
</view>
</view>
</view>
<block wx:if="{{userInfo}}">
<view class="btn">
<view bind:tap="exitLogin">退出登录</view>
</view>
</block>
+165
View File
@@ -0,0 +1,165 @@
.userInfo {
width: 100%;
height: 488rpx;
margin-bottom: 24rpx;
box-sizing: border-box;
padding: 185rpx 40rpx 0;
background: linear-gradient(#F3F9FD 0%, #FFFFFF 100%);
}
.user {
width: 100%;
height: 136rpx;
display: flex;
flex-wrap: nowrap;
margin-bottom: 46rpx;
}
.user>view:first-of-type {
width: 126rpx;
height: 126rpx;
margin-right: 24rpx;
border-radius: 50%;
border: 5rpx solid #FFFFFF;
}
.user>view:last-of-type {
color: #252536;
flex: 1;
height: 136rpx;
font-size: 40rpx;
font-weight: bold;
line-height: 136rpx;
}
.info {
width: 100%;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.info>view:nth-of-type(1),
.info>view:nth-of-type(3),
.info>view:nth-of-type(5) {
flex: 1;
}
.info>view:nth-of-type(2n) {
width: 2rpx;
height: 52rpx;
background-color: #EAECF1;
}
.info>view>view:first-of-type {
color: #394356;
width: 100%;
height: 28rpx;
font-size: 28rpx;
line-height: 28rpx;
text-align: center;
margin-bottom: 18rpx;
}
.info>view>view:last-of-type {
color: #394356;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 36rpx;
text-align: center;
}
.content {
width: 100%;
padding: 0 30rpx;
box-sizing: border-box;
margin-bottom: 360rpx;
}
.content .arrowAfter::after {
right: 36rpx;
}
.service {
width: 100%;
margin-bottom: 24rpx;
border-radius: 16rpx;
background-color: #FFFFFF;
}
.title {
color: #394356;
width: 100%;
height: 96rpx;
line-height: 96rpx;
padding: 0 30rpx;
font-size: 30rpx;
font-weight: bold;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
}
.list {
width: 100%;
height: 96rpx;
padding: 0 30rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
}
.list:last-of-type {
border-bottom: none;
}
.list>view:nth-of-type(1) {
width: 56rpx;
height: 56rpx;
margin-right: 30rpx;
}
.list>view:nth-of-type(2) {
flex: 1;
color: #394356;
height: 96rpx;
line-height: 96rpx;
font-size: 32rpx;
font-weight: bold;
}
.list>view:nth-of-type(3) {
color: #77849E;
height: 96rpx;
font-size: 28rpx;
line-height: 96rpx;
padding-right: 34rpx;
}
.agreement {
width: 100%;
border-radius: 16rpx;
background-color: #FFFFFF;
}
.btn {
width: 100%;
padding: 0 85rpx;
box-sizing: border-box;
}
.btn>view {
color: #1385FA;
width: 580rpx;
height: 88rpx;
line-height: 88rpx;
font-size: 32rpx;
border-radius: 44rpx;
text-align: center;
background-color: #F5F7FB;
border: 1rpx solid #1385FA;
}
+112
View File
@@ -0,0 +1,112 @@
const app = getApp();
Page({
data: {
getDeviceSetting: false,
initText: "",
devicesList: []
},
onLoad(options) {
this.initBluetooth();
},
onShow() {
if (this.data.getDeviceSetting) {
this.getDeviceSettingList();
}
},
// 初始化蓝牙
initBluetooth() {
this.setData({
initText: "正在初始化蓝牙..."
})
wx.openBluetoothAdapter({
success: () => {
this.setData({
initText: "蓝牙初始化成功"
})
this.getDeviceSettingList();
},
fail: (err) => {
this.setData({
initText: "蓝牙初始化失败"
})
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
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) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
}
});
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "搜索设备",
"disableScroll": true
}
+12
View File
@@ -0,0 +1,12 @@
<view class="icon">
<view>
<image src="/images/searchDevice/icon.png" />
</view>
<view></view>
<view style="animation-delay: 1s;"></view>
</view>
<view class="description">
<view>{{initText}}</view>
<view>请轻轻踩秤,保证屏幕亮起</view>
</view>
+78
View File
@@ -0,0 +1,78 @@
page {
width: 100%;
height: 100%;
padding-top: 120rpx;
box-sizing: border-box;
background-color: #FFFFFF;
}
.icon {
width: 556rpx;
height: 556rpx;
position: relative;
margin: 0 auto 120rpx;
}
.icon>view:nth-of-type(1) {
position: absolute;
z-index: 3;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 200rpx;
height: 200rpx;
border-radius: 50%;
}
.icon>view:nth-of-type(2),
.icon>view:nth-of-type(3) {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 200rpx;
height: 200rpx;
border-radius: 50%;
animation: expand 2s infinite;
}
@keyframes expand {
0% {
width: 200rpx;
height: 200rpx;
background-color: #3194FB;
}
100% {
width: 556rpx;
height: 556rpx;
background-color: rgba(0, 0, 0, 0);
}
}
.description {
width: 100%;
}
.description>view:nth-of-type(1) {
color: #252535;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 36rpx;
text-align: center;
margin-bottom: 30rpx;
}
.description>view:nth-of-type(2) {
color: #808080;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
text-align: center;
}
+42
View File
@@ -0,0 +1,42 @@
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) => {
app.globalData.ppScale.wifi.ssid = ssid;
app.globalData.ppScale.wifi.password = password;
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, '');
let params = {
equipmentName: app.globalData.ppScale.device.name,
scaleDeviceId: scaleDeviceId,
};
$.ajax("weighingScale/binding/device", params, "POST").then(res => {
app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
console.log("setNetwork.js codeSetBindingState", res);
wx.navigateTo({
url: "/pages/setNetworkSuccessful/setNetworkSuccessful"
})
})
}).catch(err => {
wx.showToast({
icon: "none",
title: err.message
})
setTimeout(() => {
wx.switchTab({
url: "/pages/home/home"
})
}, 1500)
})
})
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "正在配网",
"disableScroll": true
}
+13
View File
@@ -0,0 +1,13 @@
<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
@@ -0,0 +1,54 @@
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;
}
@@ -0,0 +1,115 @@
const app = getApp();
Page({
data: {
userInfo: null,
subUser: {
i: 0,
data: []
},
ssid: ""
},
onLoad(options) {
this.setData({
userInfo: wx.getStorageSync("userInfo"),
ssid: app.globalData.ppScale.wifi.ssid
});
},
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
});
setSubUser();
} else {
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;
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);
if(i < subUser.length) {
this.setData({
['subUser.i']: i + 1
})
setSubUser();
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.hideLoading();
wx.switchTab({
url: "/pages/home/home"
})
}
})
},
// 获取家庭成员列表
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;
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "绑定成功",
"disableScroll": true
}
@@ -0,0 +1,21 @@
<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>
@@ -0,0 +1,93 @@
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;
}
+27
View File
@@ -0,0 +1,27 @@
const app = getApp();
Page({
data: {
wifiInfo: null,
password: "mimahaojige8"
},
onLoad(options) {
this.setData({
wifiInfo: JSON.parse(options.item)
})
},
passwordInput(e) {
this.setData({
password: e.detail.value
})
},
// 打开配网
openSetNetwork() {
wx.navigateTo({
url: "/pages/setNetwork/setNetwork?ssid=" + this.data.wifiInfo.ssid + "&password=" + this.data.password
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "输入Wi-Fi密码",
"disableScroll": true
}
@@ -0,0 +1,24 @@
<view class="form">
<view>
<view>
<image src="/images/setWifiPassword/icon.png" />
</view>
<view>{{wifiInfo.ssid}}</view>
</view>
<view>
<view>密码</view>
<view>
<input
type="password"
value="{{password}}"
bindinput="passwordInput"
placeholder="8~16位密码"
placeholder-class="placeholderClass" />
</view>
<view>
<image src="/images/setWifiPassword/open.png" />
</view>
</view>
</view>
<view class="btn" bind:tap="openSetNetwork">连接</view>
@@ -0,0 +1,81 @@
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;
}
+475
View File
@@ -0,0 +1,475 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
deviceConnect: false,
initBluetooth: "0",
customerType: "1",
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)
},
},
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({
realname: userInfo.realname,
["sex.index"]: this.data.sex.data.findIndex(item => {return item.name === userInfo.sex_dictText}),
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('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);
$.ajax("weighingScale/list/device", {}, "GET", false).then((res) => {
if(res.result && res.result.length) {
let deviceConnect = res.result.some(item => item.macAddress === app.globalData.ppScale.device.mac);
if(deviceConnect) {
this.setData({
deviceConnect: true
})
} else {
app.globalData.ppScale.plugin.Blue.disconnect();
}
}
})
});
});
}
},
// 初始化蓝牙
initBluetooth() {
wx.openBluetoothAdapter({
success: () => {
this.getDeviceSettingList();
},
fail: (err) => {
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
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() {
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) {
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_) => {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]);
});
} else if (res.data.code == 401 || res.data.code == 4008) {
// 401 token过期 / 4008 token为空
// 重新请求token解析数据
this.refreshToken(() => {
this.getDeviceSettingList();
}, true);
}
});
},
// 姓名输入
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: "请靠近设备并点亮后再试"
})
this.initBluetooth();
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: "删除失败,请靠近设备并点亮后再试"
})
this.initBluetooth();
}
},
// 获取家庭成员信息详情
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.name === res.result.sex_dictText}),
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
@@ -0,0 +1,6 @@
{
"usingComponents": {},
"navigationBarTitleText": "用户档案",
"navigationBarBackgroundColor": "#F5F7FB",
"disableScroll": true
}
+66
View File
@@ -0,0 +1,66 @@
<view class="tips">请填写和完善您家人的健康信息,将用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。我们会严格保护您的家庭信息安全。</view>
<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="{{customerType === '0' && id}}">
<view class="delBtn" bind:tap="delUser">删除该档案</view>
</block>
+96
View File
@@ -0,0 +1,96 @@
page {
padding: 30rpx 30rpx 0;
}
.tips {
color: #77849E;
width: 100%;
font-size: 26rpx;
line-height: 40rpx;
margin-bottom: 40rpx;
padding: 0 30rpx;
box-sizing: border-box;
}
.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;
}
.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;
}