第一版

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
+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;
}