3 Commits
Author SHA1 Message Date
17792275749 2ecd70765e v2 2025-06-06 18:58:18 +08:00
17792275749 4b0e0eabb2 处理了仁康的 appiD 和图片 2025-06-06 18:31:22 +08:00
17792275749 46266223f1 修改了颜色和图片的颜色 2025-06-05 17:56:50 +08:00
65 changed files with 1998 additions and 2213 deletions
-1
View File
@@ -1 +0,0 @@
.idea/
+54 -152
View File
@@ -6,18 +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.1.207:8889/", // wxRequestUrl: "http://192.168.1.12:8889/",
// 秤的所有信息 // 秤的所有信息
ppScale: { ppScale: {
version: "",
plugin: null, plugin: null,
activeProtocol: null, activeProtocol: null,
domain1: "http://device.shuziweidao.com:80/gateway", // 老版本 没有鉴权 domain: "http://device.shuziweidao.com:80/gateway",
domain2: "http://device.shuziweidao.com:80/weight", // 新版本 有鉴权 // domain: "http://192.168.1.12:8889",
// domain1: "http://192.168.1.207:8889", // 老版本 没有鉴权
// domain2: "http://192.168.1.207:8889/weight", // 新版本 有鉴权
wifi: { wifi: {
ssid: "", ssid: "",
password: "" password: ""
@@ -138,143 +134,49 @@ App({
mac: null, // 选中的设备mac地址/SN码 mac: null, // 选中的设备mac地址/SN码
connection: null, // 默认选中连接的设备 connection: null, // 默认选中连接的设备
connectState: null, // 当前连接设备的状态 connectState: null, // 当前连接设备的状态
version: null, // 当前连接设备的固件版本
},
reconnect: {
count: 0, // 当前已重连次数
max: 3, // 最大重连次数
timer: null // 重连定时器
} }
}, },
_callbacks: {} // 用于存储所有 globalData 属性的监听回调 _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) => {
console.log("app.js ===> connectState", res);
this.setGlobalData('ppScale.device.connectState', res);
// 保活定时器引用 // 连接失败则重新连接
_keepAliveTimer: null, if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) {
this.reconnectDevice()
/**
* 启动保活定时器,每 15 秒发送一次保活指令
* 内部已做去重处理,重复调用安全
*/
startKeepAlive() {
this.stopKeepAlive();
this._keepAliveTimer = setInterval(() => {
if (this.globalData.ppScale.activeProtocol) {
this.globalData.ppScale.activeProtocol.sendKeepAliveCode();
}
}, 15000);
},
/**
* 清除保活定时器
*/
stopKeepAlive() {
if (this._keepAliveTimer) {
clearInterval(this._keepAliveTimer);
this._keepAliveTimer = null;
}
},
/**
* 页面离开时的统一清理:停止保活 + 重置重连计数 + connectState 置空 + 停止蓝牙
*/
cleanupConnection() {
this.stopKeepAlive();
this.resetReconnectCount();
this.setGlobalData('ppScale.device.connectState', null);
this.globalData.ppScale.plugin.Blue.stop();
},
/**
* 注册全局 bus 事件监听(connectState / syncDeviceTimeSuccess / deviceWillDisconnect
* 依赖 Blue.stop() 清空订阅,onShow 时直接调用,无需标志位
*/
registerBusListeners() {
const plugin = this.globalData.ppScale.plugin;
// 蓝牙连接状态监听
plugin.bus.subscribe('connectState', (res) => {
console.log("app.js ===> connectState", res);
this.setGlobalData('ppScale.device.connectState', res);
if (res == plugin.BLUE_STATE.CONNECTSUCCESS) {
this.globalData.ppScale.reconnect.count = 0;
this.startKeepAlive();
}
if (res == plugin.BLUE_STATE.CONNECTFAILED) {
this.stopKeepAlive();
this.reconnectDevice();
} }
wx.hideLoading(); wx.hideLoading();
}); });
// 同步时间
this.globalData.ppScale.plugin.bus.subscribe("syncDeviceTimeSuccess", (res) => {
console.log("app.js ===> syncDeviceTimeSuccess", res);
})
// 同步时间 // 设备自动断开监听
plugin.bus.subscribe('syncDeviceTimeSuccess', (res) => { this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => {
console.log("app.js ===> syncDeviceTimeSuccess", res);
});
// 设备自动断开监听
plugin.bus.subscribe('deviceWillDisconnect', (res) => {
console.log("app.js ===> deviceWillDisconnect", res); console.log("app.js ===> deviceWillDisconnect", res);
this.stopKeepAlive();
this.setGlobalData('ppScale.device.connectState', plugin.BLUE_STATE.CONNECTFAILED); this.reconnectDevice();
}); })
}, },
/**
* 自动重连设备,最多重试 max 次,超过后停止,由用户手动重连
* 只在配置页(configureDevice)活跃时执行,防止跨页面干扰
*/
reconnectDevice() { reconnectDevice() {
const reconnect = this.globalData.ppScale.reconnect; this.globalData.ppScale.plugin.Blue.disconnect((disres) => {
if (disres.errCode == 0) {
// 仅在配置页活跃时执行重连 this.globalData.ppScale.plugin.Blue.startBluetoothDevicesDiscovery();
const pages = getCurrentPages(); } else {
const currentPage = pages[pages.length - 1]; this.reconnectDevice();
if (!currentPage || !currentPage.route || !currentPage.route.includes('configureDevice')) { }
console.log("app.js ===> 非配置页,跳过自动重连"); })
return; },
}
if (reconnect.count >= reconnect.max) {
console.log("app.js ===> 自动重连已达上限,等待用户手动重试");
return;
}
reconnect.count++;
console.log(`app.js ===> 自动重连第 ${reconnect.count}/${reconnect.max}`);
// 延迟 2 秒后重连,避免连续冲突
if (reconnect.timer) {
clearTimeout(reconnect.timer);
}
reconnect.timer = setTimeout(() => {
this.globalData.ppScale.plugin.Blue.disconnect((disres) => {
if (disres.errCode == 0) {
console.log("app.js ===> 断开成功,开始重新扫描设备");
this.globalData.ppScale.plugin.Blue.startBluetoothDevicesDiscovery();
} else {
console.log("app.js ===> 断开失败,errCode:", disres.errCode);
}
});
}, 2000);
},
/**
* 重置重连计数,用于用户手动点击重试或页面离开时调用
*/
resetReconnectCount() {
const reconnect = this.globalData.ppScale.reconnect;
reconnect.count = 0;
if (reconnect.timer) {
clearTimeout(reconnect.timer);
reconnect.timer = null;
}
},
/** /**
* 注册 globalData 某个属性的监听 * 注册 globalData 某个属性的监听
@@ -306,31 +208,31 @@ App({
* @param {*} value 要设置的新值 * @param {*} value 要设置的新值
*/ */
setGlobalData(keyPath, value) { setGlobalData(keyPath, value) {
const keys = keyPath.split('.'); const keys = keyPath.split('.');
let current = this.globalData; let current = this.globalData;
let oldValue = undefined; let oldValue = undefined;
// 遍历到目标属性的父级 // 遍历到目标属性的父级
for (let i = 0; i < keys.length - 1; i++) { for (let i = 0; i < keys.length - 1; i++) {
if (!current[keys[i]]) { if (!current[keys[i]]) {
current[keys[i]] = {}; // 如果路径不存在,创建空对象 current[keys[i]] = {}; // 如果路径不存在,创建空对象
} }
current = current[keys[i]]; current = current[keys[i]];
} }
// 获取旧值 // 获取旧值
oldValue = current[keys[keys.length - 1]]; oldValue = current[keys[keys.length - 1]];
// 只有当值发生变化时才更新并通知 // 只有当值发生变化时才更新并通知
if (oldValue !== value) { if (oldValue !== value) {
current[keys[keys.length - 1]] = value; // 设置新值 current[keys[keys.length - 1]] = value; // 设置新值
// 触发监听器 // 触发监听器
if (this.globalData._callbacks[keyPath]) { if (this.globalData._callbacks[keyPath]) {
this.globalData._callbacks[keyPath].forEach(callback => { this.globalData._callbacks[keyPath].forEach(callback => {
callback(value, oldValue); callback(value, oldValue);
}); });
} }
} }
}, },
}) })
+32 -33
View File
@@ -1,10 +1,12 @@
{ {
"pages": [ "pages": [
"pages/home/home", "pages/home/home",
"pages/help/help",
"pages/searchDevice/searchDevice", "pages/searchDevice/searchDevice",
"pages/configureDevice/configureDevice", "pages/configureDevice/configureDevice",
"pages/my/my" "pages/my/my",
"pages/userInfo/userInfo",
"pages/deviceInfo/deviceInfo",
"pages/replaceNetwork/replaceNetwork"
], ],
"window": { "window": {
"navigationBarTitleText": "", "navigationBarTitleText": "",
@@ -13,38 +15,35 @@
}, },
"tabBar": { "tabBar": {
"color": "#808080", "color": "#808080",
"selectedColor": "#1385FA", "selectedColor": "#8363F9",
"borderStyle": "white", "borderStyle": "white",
"list": [ "list": [{
{ "pagePath": "pages/home/home",
"pagePath": "pages/home/home", "iconPath": "/images/tabBar/home.png",
"iconPath": "/images/tabBar/home.png", "selectedIconPath": "/images/tabBar/home_.png",
"selectedIconPath": "/images/tabBar/home_.png", "text": "首页"
"text": "首页" }, {
}, "pagePath": "pages/my/my",
{ "iconPath": "/images/tabBar/my.png",
"pagePath": "pages/my/my", "selectedIconPath": "/images/tabBar/my_.png",
"iconPath": "/images/tabBar/my.png", "text": "我的"
"selectedIconPath": "/images/tabBar/my_.png", }]
"text": "我的"
}
]
}, },
"style": "v2", "style": "v2",
"plugins": { "plugins": {
"ppScale-plugin": { "ppScale-plugin": {
"version": "0.0.24", "version": "1.2.15",
"provider": "wx0826af4e4908f524" "provider": "wx0ffb48417ce6345c"
} }
}, },
"permission": { "permission": {
"scope.userLocation": { "scope.userLocation": {
"desc": "您的位置信息将用于发现附近的蓝牙设备,以便连接蓝牙秤。" "desc": "您的位置信息将用于发现附近的蓝牙设备,以便连接蓝牙秤。"
} }
}, },
"requiredPrivateInfos": [ "requiredPrivateInfos": [
"getLocation" "getLocation"
], ],
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents" "lazyCodeLoading": "requiredComponents"
} }
+227 -248
View File
@@ -1,31 +1,36 @@
const app = getApp(); const app = getApp();
import $ from "../../utils/request"; import $ from "../../utils/request";
/**
* 根据生日计算年龄
* @param {string} birthday 生日字符串,如 "1990-05-20"
* @returns {number|null} 年龄,无法计算时返回 null
*/
function calcAge(birthday) {
if (!birthday) return null;
let birthDate = new Date(birthday.replace(/-/g, '/'));
if (isNaN(birthDate.getTime())) return null;
let today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
let monthDiff = today.getMonth() - birthDate.getMonth();
// 未过生日则减一岁
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
Component({ Component({
data: { data: {
BLUE_STATE: {}, BLUE_STATE: {},
device: null, device: null,
connectState: "", connectState: "",
userList: [],
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 时取消监听 // 存储回调函数的引用,以便在 detached 时取消监听
@@ -47,9 +52,34 @@ Component({
}; };
app.watch('ppScale.device.connectState', this._connectStateWatcher); app.watch('ppScale.device.connectState', this._connectStateWatcher);
this.fetchUserList(); 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() { detached() {
// 4. 在组件销毁时取消监听,防止内存泄漏
if (this._connectStateWatcher) { if (this._connectStateWatcher) {
app.unwatch('ppScale.device.connectState', this._connectStateWatcher); app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
} }
@@ -58,258 +88,207 @@ Component({
// 组件的方法 // 组件的方法
methods: { methods: {
// 长按型号区域初始化设备 // 二次连接设备
onDeviceLongPress() {
wx.showModal({
title: "提示",
content: "确定要初始化设备吗?将清除设备中的所有数据(用户信息、历史数据、配网数据、设置信息)。",
success: (res) => {
if (res.confirm) {
if (!app.globalData.ppScale.activeProtocol) {
wx.showToast({ title: "设备未连接,请重试", icon: "none" });
return;
}
wx.showLoading({ title: "正在初始化设备...", mask: true });
app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (status) => {
wx.hideLoading();
if (status == 0) {
wx.showToast({ title: "设备初始化成功", icon: "success" });
// 断开蓝牙连接并返回上一页
app.globalData.ppScale.plugin.Blue.stop();
setTimeout(() => {
wx.navigateBack({ delta: 1 });
}, 1500);
} else {
wx.showToast({ title: "设备初始化失败,请重试", icon: "none" });
}
});
}
}
});
},
// 手动重连设备
connectedDevice() { connectedDevice() {
app.resetReconnectCount();
this.triggerEvent('connectedDeviceEvent', { this.triggerEvent('connectedDeviceEvent', {
device: this.data.device device: this.data.device
}); });
}, },
addUser() { // 姓名输入
if (this.data.userList.length >= 10) { realnameInput(e) {
wx.showToast({ let realname = e.detail.value.replace(/\s+/g, '');
title: "超过最大用户数", this.setData({
icon: "none" realname: realname
});
return;
}
// 列表为空时,第一个用户只能是员工(主用户)
const isFirstUser = this.data.userList.length === 0;
this.selectComponent("#configureDevice2AddUser").showModal(isFirstUser);
},
getAddUserInfo() {
this.fetchUserList();
},
// 获取设备绑定的用户列表
fetchUserList() {
if (!app.globalData.ppScale.device.mac) {
wx.showToast({ title: '设备 MAC 地址为空,请重新连接', icon: 'none' });
return;
}
let sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
$.ajax("weighingScale/v2/select/user", { sn }, "GET", true, "正在获取用户列表...").then(res => {
if (res.result && res.result.length) {
let list = res.result.map(user => {
// 没有 age 时通过 birthday 计算
if (!user.age && user.birthday) {
user.age = calcAge(user.birthday);
}
return user;
});
this.setData({ userList: list });
} else {
this.setData({ userList: [] });
}
}).catch(() => {
wx.showToast({
title: "用户列表获取失败",
icon: "none"
})
}) })
}, },
// 删除用户 // 性别选择
delUserClick(e) { sexChange(e) {
let id = e.currentTarget.dataset.id; let sex = e.detail.value;
const userList = this.data.userList; console.log(sex);
const target = userList.find(u => u.id === id); this.setData({
['sex.index']: e.detail.value
// 主用户(userType=1)有子用户时不允许删除 })
if (target && target.userType === 1) { if(this.data.height.index === null) {
const hasSubUser = userList.some(u => u.userType === 0); this.setData({
if (hasSubUser) { ['height.index']: sex == 0 ? 50 : 40
wx.showToast({ title: "请先删除所有普通用户", icon: "none" }); })
return;
}
} }
wx.showModal({ if(this.data.weight.index === null) {
title: "提示", this.setData({
content: "确定要删除该用户吗?", ['weight.index']: sex == 0 ? 20 : 10
success: (res) => { })
if (res.confirm) { }
$.ajax("weighingScale/v2/del/user", { id }, "DELETE", true, "正在删除...", "application/x-www-form-urlencoded").then(() => { },
wx.showToast({
title: "删除成功", // 生日选择
icon: "success" birthdayChange(e) {
}) let v = e.detail.value;
setTimeout(() => { let [year, month, day] = v.split("-");
this.fetchUserList(); this.setData({
}, 1500) birthday: {
}).catch(() => { label: year + "年" + month + "月" + day + "日",
wx.showToast({ value: v
title: "删除失败,请重试",
icon: "none"
})
})
}
} }
}) })
}, },
// 身高选择
heightChange(e) {
this.setData({
['height.index']: e.detail.value
})
},
// 体重选择
weightChange(e) {
console.log(e.detail.value)
this.setData({
['weight.index']: e.detail.value
})
},
setUserInfo() { setUserInfo() {
if (this.data.connectState != this.data.BLUE_STATE.CONNECTSUCCESS && this.data.connectState != this.data.BLUE_STATE.WIFISUCCESS) { if(this.data.connectState == this.data.BLUE_STATE.CONNECTSUCCESS) {
wx.showToast({ if(this.data.userId) {
title: "设备连接失败,请重试。",
icon: "none"
})
return;
}
let userList = this.data.userList;
if (!userList.length) {
wx.showToast({
title: "暂无用户信息,请先添加用户",
icon: "none"
})
return;
}
// 找出主用户,所有用户下发时 userID 统一使用主用户的 userId
const mainUser = userList.find(u => u.userType === 1);
if (!mainUser) {
wx.showToast({ title: "未找到主用户,请先添加员工用户", icon: "none" });
return;
}
const mainUserId = mainUser.userId;
wx.showLoading({ title: "正在同步用户数据...", mask: true });
// 第一步:清除秤上所有用户信息(15秒超时保护)
let clearTimer = setTimeout(() => {
wx.hideLoading();
wx.showToast({ title: "清除设备数据超时,请重试", icon: "none" });
}, 15000);
app.globalData.ppScale.activeProtocol.codeClearDeviceData("01", (clearRes) => {
clearTimeout(clearTimer);
console.log("codeClearDeviceData res", clearRes);
if (clearRes !== 0x00) {
wx.hideLoading();
wx.showToast({ title: "同步用户失败,请重试", icon: "none" });
return;
}
// 第二步:全量下发本地用户列表
let syncIndex = 0;
let syncTimer = null;
// 清除超时定时器
const clearSyncTimer = () => {
if (syncTimer) {
clearTimeout(syncTimer);
syncTimer = null;
}
};
// 重置超时定时器,10秒无响应则认定失败
const resetSyncTimer = () => {
clearSyncTimer();
syncTimer = setTimeout(() => {
console.log("dataSyncUserInfo 超时,第" + (syncIndex + 1) + "个用户下发超时");
wx.hideLoading();
wx.showToast({ title: "用户信息下发超时,请重试", icon: "none" });
}, 15000);
};
const syncNext = () => {
if (syncIndex >= userList.length) {
// 全部下发完成,清除定时器
clearSyncTimer();
wx.hideLoading();
wx.showToast({ title: "用户信息同步成功", icon: "success" });
setTimeout(() => {
this._checkWifiAndNext();
}, 1500);
return;
}
const user = userList[syncIndex];
// 主用户 memberID 为空,子用户 memberID 为子用户自己的 userId
const memberID = user.userId === mainUserId ? "" : user.userId;
wx.showLoading({ title: "正在下发第" + (syncIndex + 1) + "/" + userList.length + "个用户...", mask: true });
// 每次下发前重置10秒超时定时器
resetSyncTimer();
app.globalData.ppScale.activeProtocol.dataSyncUserInfo({ app.globalData.ppScale.activeProtocol.dataSyncUserInfo({
userID: mainUserId, userID: this.data.userId,
userName: user.realname, userName: this.data.realname,
memberID: memberID, memberID: "",
age: user.age || '', age: this.getAge(this.data.birthday.value),
gender: user.sex === 2 ? 0 : user.sex, gender: this.data.sex.data[this.data.sex.index].id,
height: user.height || '', height: this.data.height.data[this.data.height.index],
isAthleteMode: 0, isAthleteMode: 0,
deviceHeaderIndex: syncIndex, currentWeight: this.data.weight.data[0][this.data.weight.index[0]] + '.' + this.data.weight.data[1][this.data.weight.index[1]],
currentWeight: user.weight || '', deviceHeaderIndex: 0,
targetWeight: "", targetWeight: "",
idealWeight: "", idealWeight: "",
recentData: [], recentData: [],
}, (res) => { }, (res) => {
console.log("dataSyncUserInfo res", res, "user:", user.realname, "userID:", mainUserId, "memberID:", memberID); if(res == 0) {
if (res == 0) { this.triggerEvent('deviceEvent', {
// 成功:重置定时器,继续下发下一个用户 status: true
resetSyncTimer(); });
syncIndex++;
syncNext();
} else { } else {
// 失败自动重试当前用户,重置定时器 console.log("dataSyncUserInfo", res)
resetSyncTimer(); wx.showToast({
syncNext(); title: "用户信息下发失败,请重试。",
icon: "none"
})
} }
}); })
}; } else {
syncNext(); 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.userId,
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) {
* 已配网(0x01) → progressIndex: 3,跳过配网步骤 const birthDate = new Date(birthDateString);
* 未配网 → progressIndex: 2,进入配网步骤 const today = new Date();
*/
_checkWifiAndNext() { let age = today.getFullYear() - birthDate.getFullYear();
wx.showLoading({ title: "正在检测配网状态...", mask: true }); const monthDiff = today.getMonth() - birthDate.getMonth();
app.globalData.ppScale.activeProtocol.codeFetchWifiConfig((res) => { const dayDiff = today.getDate() - birthDate.getDate();
wx.hideLoading();
if (res === undefined || res === null) { // 如果当前月份小于出生月份,或者同月但当前日期小于出生日期,年龄需要减 1
// 获取失败,自动重试 if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
this._checkWifiAndNext(); age--;
return; }
}
// 0x01 表示已配网,跳过配网步骤直接进入下一步 return age;
const progressIndex = res === 0x01 ? 3 : 2;
this.triggerEvent('deviceEvent', { status: true, progressIndex });
});
}, },
} }
}); });
@@ -1,6 +1,4 @@
{ {
"component": true, "component": true,
"usingComponents": { "usingComponents": {}
"configureDevice_2_addUser": "/components/configureDevice_2_addUser/configureDevice_2_addUser"
}
} }
@@ -1,99 +1,127 @@
<view class="configureDevice2"> <view class="configureDevice2">
<view class="header"> <view class="header">
<view> <view>
<view bind:longpress="fetchUserList">智能蓝牙秤</view> <view>智能蓝牙秤</view>
<view bind:longpress="onDeviceLongPress">型号:{{device.name}}</view> <view>型号:{{device.name}}</view>
</view> </view>
<view> <view>
<block wx:if="{{connectState == BLUE_STATE.CONNECTSUCCESS || connectState == BLUE_STATE.WIFISUCCESS}}"> <block wx:if="{{device && connectState == BLUE_STATE.CONNECTSUCCESS}}">
<view style="background-color: #2AC79F;"></view> <view style="background-color: #2AC79F;"></view>
<view style="color: #2AC79F;">连接成功</view> <view style="color: #2AC79F;">连接成功</view>
</block> </block>
<block wx:elif="{{connectState == BLUE_STATE.SCANING}}"> <block wx:else>
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">正在搜索...</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.READY}}">
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">蓝牙就绪</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.UNAVAILABLE}}">
<view style="background-color: #F24439;"></view>
<view style="color: #F24439;">蓝牙不可用</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.CONNECTFAILED}}">
<view style="background-color: #F24439;"></view> <view style="background-color: #F24439;"></view>
<view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view> <view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view>
</block> </block>
<block wx:else>
<view style="background-color: #999999;"></view>
<view style="color: #999999;">未连接</view>
</block>
</view> </view>
</view> </view>
<view class="section"> <view class="section">
<view class="from"> <view class="from">
<block wx:if="{{userList && userList.length}}"> <view>
<scroll-view class="~scrollView" scroll-y> <view>姓名</view>
<view class="scrollViewContent"> <block wx:if="{{userId}}">
<block wx:for="{{userList}}" wx:key="id"> <view class="valueClass">{{realname}}</view>
<view class="userList"> </block>
<view class="userAvatar"> <block wx:else>
<block wx:if="{{item.avatar}}"> <view>
<image src="{{item.avatar}}" /> <view>
</block> <input
<block wx:else> type="text"
<block wx:if="{{item.sex === 1}}"> value="{{realname}}"
<image src="/images/configureDevice/userAvatarMan.png" /> bindinput="realnameInput"
</block> placeholder="请输入您的姓名"
<block wx:else> class="valueClass"
<image src="/images/configureDevice/userAvatarWoman.png" /> placeholder-class="placeholderClass" />
</block> </view>
</block> </view>
</view> </block>
<view class="userInfo"> </view>
<view class="userInfo_1"> <view>
<view>{{item.realname}}</view> <view>性别</view>
<view class="{{item.sex === 1 ? 'man' : 'woman'}}"> <block wx:if="{{userId}}">
<view> <view class="valueClass">{{sex.data[sex.index].name}}</view>
<block wx:if="{{item.sex === 1}}"> </block>
<image src="/images/configureDevice/man.png" /> <block wx:else>
</block> <view class="~arrowAfter">
<block wx:else> <view>
<image src="/images/configureDevice/woman.png" mode=""/> <picker mode="selector" bindchange="sexChange" value="{{sex.index}}" range="{{sex.data}}" range-key="name">
</block> <block wx:if="{{sex.index === ''}}">
</view> <view class="placeholderClass">请选择您的性别</view>
<view>{{item.age}}</view> </block>
</view> <block wx:else>
</view> <view class="valueClass">{{sex.data[sex.index].name}}</view>
<view class="userInfo_2"> </block>
<view>身高:{{item.height}}cm</view> </picker>
<view></view> </view>
<view>体重:{{item.weight}}kg</view> </view>
</view> </block>
</view> </view>
<view class="delUser" bind:tap="delUserClick" data-id="{{item.id}}">-</view> <view>
</view> <view>生日</view>
</block> <block wx:if="{{userId}}">
</view> <view class="valueClass">{{birthday.label}}</view>
</scroll-view> </block>
</block> <block wx:else>
<block wx:else> <view class="~arrowAfter">
<view class="nullData"> <view>
<view> <picker mode="date" bindchange="birthdayChange" value="{{birthday.value}}">
<image src="/images/configureDevice/null.png" /> <block wx:if="{{birthday.value === ''}}">
</view> <view class="placeholderClass">请选择您的生日</view>
<view>暂无用户数据</view> </block>
</view> <block wx:else>
</block> <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>
<view class="btn"> <view class="btn">
<view bind:tap="addUser">添加用户</view>
<view bind:tap="setUserInfo">下一步</view> <view bind:tap="setUserInfo">下一步</view>
</view> </view>
<view class="describe"> <view class="describe">请认真填写和完善您家人的健康信息,用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。<text>(填写数据同时,踩亮蓝牙秤并与其保持连接)。</text></view>
请认真填写和完善员工健康信息,用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。<text>(填写数据同时,踩亮蓝牙称并与其保持连接)。</text></view>
</view> </view>
</view> </view>
<configureDevice_2_addUser id="configureDevice2AddUser" bind:returnDate="getAddUserInfo" />
@@ -24,8 +24,6 @@ input {
.configureDevice2 { .configureDevice2 {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex;
flex-flow: column;
} }
.header { .header {
@@ -80,191 +78,72 @@ input {
} }
.section { .section {
flex: 1;
overflow: hidden;
width: 100%; width: 100%;
display: flex; padding: 0 30rpx;
flex-flow: column; box-sizing: border-box;
} }
.from { .from {
width: 100%; width: 100%;
padding: 24rpx 0; margin-bottom: 66rpx;
flex: 1;
overflow: hidden;
} }
.scrollViewContent { .from>view {
width: 100%;
padding: 0 30rpx;
box-sizing: border-box;
}
.userList {
width: 100%;
height: 162rpx;
border-radius: 16px;
padding: 0 30rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
box-sizing: border-box;
margin-bottom: 24rpx;
border: 1rpx solid #E6E6EA;
}
.userAvatar {
width: 90rpx;
height: 90rpx;
box-sizing: border-box;
overflow: hidden;
border-radius: 50%;
margin-right: 24rpx;
}
.userInfo {
flex: 1;
margin-right: 24rpx;
}
.userInfo_1 {
width: 100%;
height: 32rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
margin-bottom: 20rpx;
}
.userInfo_1>view:nth-of-type(1) {
color: #333333;
font-size: 30rpx;
height: 32rpx;
font-weight: bold;
line-height: 32rpx;
margin-right: 20rpx;
}
.userInfo_1>view:nth-of-type(2) {
height: 32rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 0 8rpx;
border-radius: 8rpx;
}
.userInfo_1 .man {
background: linear-gradient(90deg, #54D9FC 0%, #6FC1FB 100%);
}
.userInfo_1 .woman {
background: linear-gradient(90deg, #FF91B6 0%, #FD6C9D 100%);
}
.userInfo_1>view:nth-of-type(2)>view:nth-of-type(1) {
width: 20rpx;
height: 20rpx;
display: flex;
align-items: center;
margin-right: 4rpx;
}
.userInfo_1>view:nth-of-type(2)>view:nth-of-type(2) {
color: #FFFFFF;
height: 32rpx;
font-weight: bold;
font-size: 22rpx;
line-height: 32rpx;
}
.userInfo_2 {
width: 100%;
height: 26rpx;
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.userInfo_2>view {
color: #77849E;
height: 26rpx;
font-size: 26rpx;
line-height: 26rpx;
}
.userInfo_2>view:nth-of-type(2) {
margin: 0 20rpx;
width: 4rpx;
height: 24rpx;
border-radius: 1rpx;
background-color: #EAECF1;
}
.delUser {
color: #FFFFFF;
width: 40rpx;
height: 40rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 34rpx;
text-align: center;
border-radius: 50%;
background-color: #F24439;
}
.nullData {
width: 100%; width: 100%;
padding: 200rpx 0 250rpx; padding: 48rpx 10rpx 0;
box-sizing: border-box;
border-bottom: 1rpx solid #EAECF1;
} }
.nullData>view:first-of-type { .from>view>view:nth-of-type(1) {
width: 230rpx; color: #252535;
height: 160rpx; height: 32rpx;
margin: 0 auto 15rpx; font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
margin-bottom: 18rpx;
} }
.nullData>view:last-of-type { .from>view>view:nth-of-type(2) {
color: #B6B6B6; width: 100%;
height: 30rpx; height: 58rpx;
font-size: 30rpx; display: flex;
line-height: 30rpx; flex-wrap: nowrap;
text-align: center; 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 { .btn {
width: 100%; width: 100%;
padding: 0 55rpx; padding: 0 26rpx;
box-sizing: border-box; box-sizing: border-box;
} }
.btn>view:nth-of-type(1) { .btn>view {
color: #1385FA;
width: 100%;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
text-align: center;
line-height: 86rpx;
border-radius: 44rpx;
margin-bottom: 40rpx;
box-sizing: border-box;
border: 1px solid #1385FA;
}
.btn>view:nth-of-type(2) {
color: #FFFFFF; color: #FFFFFF;
width: 100%; width: 100%;
height: 88rpx; height: 88rpx;
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
line-height: 86rpx; line-height: 88rpx;
border-radius: 44rpx; border-radius: 44rpx;
margin-bottom: 40rpx; margin-bottom: 40rpx;
box-sizing: border-box; background-color: #8363F9;
background-color: #1385FA;
border: 1px solid #1385FA;
} }
.describe { .describe {
@@ -272,8 +151,6 @@ input {
width: 100%; width: 100%;
font-size: 24rpx; font-size: 24rpx;
line-height: 40rpx; line-height: 40rpx;
padding: 0 30rpx 20rpx;
box-sizing: border-box;
} }
.describe text { .describe text {
@@ -1,257 +0,0 @@
import $ from "../../utils/request";
const app = getApp();
Component({
properties: {
},
data: {
animationData: null,
modalStatus: false,
// 是否是第一个用户(主用户),true 时只能选员工
isFirstUser: false,
// 用户类型:employee=员工,family=家庭用户
userType: 'employee',
// 员工模式
workNo: "",
userInfo: null,
// 家庭用户模式 - 手动填写
familyInfo: {
name: '',
sex: 1,
birthday: '',
height: '',
weight: ''
},
// 性别选择器选项
genderOptions: ['男', '女'],
genderIndex: 0,
},
lifetimes: {
// 在组件实例进入页面节点树时执行
attached() {
},
// 在组件实例被从页面节点树移除时执行
detached() {
},
},
methods: {
// 显示对话框
showModal(isFirstUser = false) {
this.setData({ isFirstUser: !!isFirstUser });
// 先瞬间将弹窗移到屏幕下方(duration:0,不产生过渡)
let initAnim = wx.createAnimation({ duration: 0 });
initAnim.translateY(1200).step();
this.setData({ animationData: initAnim.export(), modalStatus: true });
// 留一帧让渲染生效,再执行滑入动画
setTimeout(() => {
let animation = wx.createAnimation({ duration: 300, timingFunction: 'ease' });
animation.translateY(0).step();
this.setData({ animationData: animation.export() });
}, 50);
},
// 隐藏对话框
hideModal() {
// 执行滑出动画
let animation = wx.createAnimation({ duration: 300, timingFunction: 'ease' });
animation.translateY(1200).step();
this.setData({ animationData: animation.export() });
// 等动画结束后再隐藏节点
setTimeout(() => {
this.setData({ modalStatus: false });
}, 300);
},
// 关闭弹窗并重置所有数据
closeModal() {
this.setData({
isFirstUser: false,
userType: 'employee',
workNo: "",
userInfo: null,
familyInfo: {
name: '',
sex: 1,
birthday: '',
height: '',
weight: ''
},
genderIndex: 0,
});
this.hideModal();
},
// 切换用户类型,同时清空所有已填数据
switchUserType(e) {
// 主用户模式下禁止切换
if (this.data.isFirstUser) return;
const type = e.currentTarget.dataset.type;
if (type === this.data.userType) return;
this.setData({
userType: type,
workNo: "",
userInfo: null,
familyInfo: {
name: '',
sex: 1,
birthday: '',
height: '',
weight: ''
},
genderIndex: 0,
});
},
// 监听工号输入(员工模式),输入满 8 位时自动查询
onWorkNoInput(e) {
const value = e.detail.value;
this.setData({ workNo: value, userInfo: null });
if (value.trim().length === 8) {
this.searchUser();
}
},
// 监听身高输入(员工模式)
onHeightInput(e) {
this.setData({ 'userInfo.height': e.detail.value });
},
// 监听体重输入(员工模式)
onWeightInput(e) {
this.setData({ 'userInfo.weight': e.detail.value });
},
// 监听家庭用户姓名输入
onFamilyNameInput(e) {
this.setData({ 'familyInfo.name': e.detail.value });
},
// 监听家庭用户性别选择
onFamilyGenderChange(e) {
const index = e.detail.value;
// 1=男,2=女
this.setData({
genderIndex: index,
'familyInfo.sex': index === '0' || index === 0 ? 1 : 2
});
},
// 监听家庭用户生日选择
onFamilyBirthdayChange(e) {
this.setData({ 'familyInfo.birthday': e.detail.value });
},
// 监听家庭用户身高输入
onFamilyHeightInput(e) {
this.setData({ 'familyInfo.height': e.detail.value });
},
// 监听家庭用户体重输入
onFamilyWeightInput(e) {
this.setData({ 'familyInfo.weight': e.detail.value });
},
// 根据工号查询用户信息(员工模式)
searchUser() {
let workNo = this.data.workNo.trim();
if (!workNo) {
wx.showToast({
title: "请输入工号",
icon: "none"
})
return;
}
let sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
$.ajax("weighingScale/v2/getUserInfoByWkno", {
workNo: workNo,
sn: sn
}, "GET", true, "正在查询...").then(res => {
if (res.result) {
this.setData({ userInfo: res.result });
} else {
this.setData({ userInfo: null });
wx.showToast({
title: "未查询到该工号的用户信息",
icon: "none"
})
}
}).catch((err) => {
console.log(err);
this.setData({ userInfo: null });
wx.showToast({
title: (err && err.message) || "查询失败",
icon: "none"
})
})
},
// 确定提交
submit() {
const sn = app.globalData.ppScale.device.mac.replace(/:/g, '');
if (this.data.userType === 'employee') {
// 员工模式:必须先查询到用户信息
if (!this.data.userInfo) {
wx.showToast({ title: "请先查询用户信息", icon: "none" });
return;
}
let userInfo = this.data.userInfo;
if (!userInfo.height) {
wx.showToast({ title: "请输入身高", icon: "none" });
return;
}
if (!userInfo.weight) {
wx.showToast({ title: "请输入体重", icon: "none" });
return;
}
userInfo.sn = sn;
$.ajax("weighingScale/v2/edit/user", userInfo, "POST", true, "正在添加...").then(res => {
wx.showToast({ title: "添加成功", icon: "success" });
this.triggerEvent('returnDate', { userInfo });
this.closeModal();
}).catch(() => {
wx.showToast({ title: "添加失败,请重试", icon: "none" });
});
} else {
// 家庭用户模式:校验手动填写的字段
const familyInfo = this.data.familyInfo;
if (!familyInfo.name.trim()) {
wx.showToast({ title: "请输入姓名", icon: "none" });
return;
}
if (!familyInfo.birthday) {
wx.showToast({ title: "请选择生日", icon: "none" });
return;
}
if (!familyInfo.height) {
wx.showToast({ title: "请输入身高", icon: "none" });
return;
}
if (!familyInfo.weight) {
wx.showToast({ title: "请输入体重", icon: "none" });
return;
}
const submitData = {
realname: familyInfo.name.trim(),
sex: familyInfo.sex,
birthday: familyInfo.birthday,
height: familyInfo.height,
weight: familyInfo.weight,
sn: sn
};
$.ajax("weighingScale/v2/edit/user", submitData, "POST", true, "正在添加...").then(res => {
wx.showToast({ title: "添加成功", icon: "success" });
this.triggerEvent('returnDate', { userInfo: submitData });
this.closeModal();
}).catch(() => {
wx.showToast({ title: "添加失败,请重试", icon: "none" });
});
}
}
}
});
@@ -1,3 +0,0 @@
{
"component": true
}
@@ -1,165 +0,0 @@
<!--屏幕背景变暗的背景 -->
<view class="modalBg" wx:if="{{modalStatus}}" bindtap="hideModal"></view>
<!--弹出框 -->
<view animation="{{animationData}}" class="modal" wx:if="{{modalStatus}}">
<view class="header">
<view></view>
<view>添加用户</view>
</view>
<view class="seaction">
<!-- 用户类型切换(主用户模式下隐藏) -->
<view class="select" wx:if="{{!isFirstUser}}">
<view
class="{{userType === 'employee' ? 'selectActive' : ''}}"
bindtap="switchUserType"
data-type="employee"
>员工</view>
<view
class="{{userType === 'family' ? 'selectActive' : ''}}"
bindtap="switchUserType"
data-type="family"
>家庭用户</view>
</view>
<!-- 员工模式 -->
<block wx:if="{{userType === 'employee'}}">
<!-- 工号输入 -->
<view class="input">
<view>工号:</view>
<view>
<input type="text" maxlength="8" placeholder="输入工号自动显示员工信息" value="{{workNo}}" bindinput="onWorkNoInput" bindconfirm="searchUser" />
</view>
</view>
<!-- 姓名(只读) -->
<view class="only">
<view>姓名:</view>
<view>
<view>
<block wx:if="{{userInfo}}">
{{userInfo.realname || ''}}
</block>
<!-- <block wx:else>-->
<!-- <text style="color: #808080;">请先输入工号</text>-->
<!-- </block>-->
</view>
<view></view>
</view>
</view>
<!-- 性别(只读) -->
<view class="only">
<view>性别:</view>
<view>
<view>
<block wx:if="{{userInfo}}">
{{userInfo.sex === 1 ? '男' : userInfo.sex === 2 ? '女' : ''}}
</block>
<!-- <block wx:else>-->
<!-- <text style="color: #808080;">请先输入工号</text>-->
<!-- </block>-->
</view>
<view></view>
</view>
</view>
<!-- 生日(只读) -->
<view class="only">
<view>生日:</view>
<view>
<view>
<block wx:if="{{userInfo}}">
{{userInfo.birthday || ''}}
</block>
<!-- <block wx:else>-->
<!-- <text style="color: #808080;">请先输入工号</text>-->
<!-- </block>-->
</view>
<view></view>
</view>
</view>
<!-- 身高(可输入) -->
<view class="inputUnit">
<view>身高:</view>
<view>
<view>
<input type="digit" value="{{userInfo.height || ''}}" bindinput="onHeightInput" placeholder="请输入身高" />
</view>
<view>cm</view>
</view>
</view>
<!-- 体重(可输入) -->
<view class="inputUnit">
<view>体重:</view>
<view>
<view>
<input type="digit" value="{{userInfo.weight || ''}}" bindinput="onWeightInput" placeholder="请输入体重" />
</view>
<view>kg</view>
</view>
</view>
</block>
<!-- 家庭用户模式 -->
<block wx:if="{{userType === 'family'}}">
<!-- 姓名(手动输入) -->
<view class="input">
<view>姓名:</view>
<view>
<input type="text" placeholder="请输入姓名" value="{{familyInfo.name}}" bindinput="onFamilyNameInput" />
</view>
</view>
<!-- 性别(picker 选择) -->
<view class="only">
<view>性别:</view>
<view>
<view>
<picker range="{{genderOptions}}" value="{{genderIndex}}" bindchange="onFamilyGenderChange">
<view style="color: #252535; font-size: 32rpx; font-weight: 500; height: 100rpx; line-height: 100rpx;">
{{genderOptions[genderIndex]}}
</view>
</picker>
</view>
<view></view>
</view>
</view>
<!-- 生日(picker date 选择) -->
<view class="only">
<view>生日:</view>
<view>
<view>
<picker mode="date" value="{{familyInfo.birthday}}" start="1900-01-01" bindchange="onFamilyBirthdayChange">
<view style="color: {{familyInfo.birthday ? '#252535' : '#808080'}}; font-size: 32rpx; font-weight: 500; height: 100rpx; line-height: 100rpx;">
{{familyInfo.birthday || '请选择生日'}}
</view>
</picker>
</view>
<view></view>
</view>
</view>
<!-- 身高(手动输入) -->
<view class="inputUnit">
<view>身高:</view>
<view>
<view>
<input type="digit" value="{{familyInfo.height}}" bindinput="onFamilyHeightInput" placeholder="请输入身高" />
</view>
<view>cm</view>
</view>
</view>
<!-- 体重(手动输入) -->
<view class="inputUnit">
<view>体重:</view>
<view>
<view>
<input type="digit" value="{{familyInfo.weight}}" bindinput="onFamilyWeightInput" placeholder="请输入体重" />
</view>
<view>kg</view>
</view>
</view>
</block>
</view>
<view class="footer">
<view bind:tap="closeModal">取消</view>
<view bind:tap="submit">确定</view>
</view>
</view>
@@ -1,215 +0,0 @@
.modalBg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #000;
opacity: 0.2;
overflow: hidden;
z-index: 10;
}
.modal {
height: 1200rpx;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 11;
display: flex;
flex-flow: column;
overflow: hidden;
background-color: #ffffff;
border-radius: 30rpx 30rpx 0 0;
}
.header {
height: 150rpx;
width: 100%;
padding-top: 30rpx;
box-sizing: border-box;
}
.header>view:nth-of-type(1) {
width: 72rpx;
height: 6rpx;
border-radius: 3rpx;
margin: 0 auto 40rpx;
background-color: #77849E;
}
.header>view:nth-of-type(2) {
color: #252535;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
text-align: center;
}
.seaction {
flex: 1;
padding: 0 30rpx;
overflow: hidden;
}
.seaction>view:last-of-type {
margin-bottom: 0;
}
.select {
width: 100%;
height: 80rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 4rpx;
box-sizing: border-box;
margin-bottom: 40rpx;
border-radius: 16rpx;
background-color: #F3F5F8;
}
.select>view {
color: #808080;
flex: 1;
width: 0;
height: 72rpx;
line-height: 72rpx;
font-size: 32rpx;
border-radius: 16rpx;
text-align: center;
}
.selectActive {
color: #1385FA !important;
font-weight: bold;
background-color: #FFFFFF;
}
.only,
.input,
.inputUnit {
width: 100%;
height: 102rpx;
display: flex;
flex-wrap: nowrap;
margin-bottom: 32rpx;
}
.only>view:nth-of-type(1),
.input>view:nth-of-type(1),
.inputUnit>view:nth-of-type(1) {
color: #333333;
height: 102rpx;
font-size: 32rpx;
line-height: 102rpx;
}
.only>view:nth-of-type(2),
.inputUnit>view:nth-of-type(2) {
flex: 1;
width: 0;
height: 102rpx;
padding: 0 30rpx;
border-radius: 16rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
border: 1rpx solid #E6E6EA;
}
.only>view:nth-of-type(2)>view:nth-of-type(1),
.inputUnit>view:nth-of-type(2)>view:nth-of-type(1) {
flex: 1;
width: 0;
color: #252535;
font-size: 32rpx;
font-weight: 500;
height: 100rpx;
line-height: 100rpx;
}
.only>view:nth-of-type(2)>view:nth-of-type(2),
.inputUnit>view:nth-of-type(2)>view:nth-of-type(2) {
color: #77849E;
height: 28rpx;
font-size: 28rpx;
line-height: 28rpx;
}
.input>view:nth-of-type(2) {
flex: 1;
width: 0;
height: 102rpx;
padding: 0 30rpx;
border-radius: 16rpx;
border: 1rpx solid #E6E6EA;
}
.input>view:nth-of-type(2) input,
.inputUnit>view:nth-of-type(2)>view:nth-of-type(1) input {
width: 100%;
height: 100%;
color: #252535;
font-size: 32rpx;
font-weight: 500;
}
.inputUnit>view:nth-of-type(2) {
}
.searchBtn {
color: #FFFFFF;
width: 120rpx;
height: 102rpx;
font-size: 28rpx;
font-weight: bold;
text-align: center;
line-height: 102rpx;
margin-left: 16rpx;
border-radius: 16rpx;
background-color: #1385FA;
}
.footer {
width: 100%;
padding: 0 30rpx;
height: 120rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
background-color: #FFFFFF;
border-top: 1rpx solid #EAECF1;
}
.footer>view:nth-of-type(1) {
color: #1385FA;
width: 330rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
border-radius: 44rpx;
text-align: center;
line-height: 86rpx;
box-sizing: border-box;
border: 1rpx solid #1385FA;
}
.footer>view:nth-of-type(2) {
color: #FFFFFF;
width: 330rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
border-radius: 44rpx;
text-align: center;
line-height: 86rpx;
box-sizing: border-box;
background-color: #1385FA;
border: 1rpx solid #1385FA;
}
+106 -92
View File
@@ -1,10 +1,10 @@
const app = getApp(); const app = getApp();
import $ from "../../utils/request";
Component({ Component({
data: { data: {
progress: 0, progress: 0,
// loading=正在获取,failed=获取失败,success=获取成功
wifiStatus: 'loading',
wifiList: [], wifiList: [],
selectWifi: null, selectWifi: null,
@@ -14,61 +14,27 @@ Component({
lifetimes: { lifetimes: {
attached() { attached() {
// WiFi 列表获取由父页面在 activeProtocol 就绪后显式调用,此处不自动触发 this.initWifi();
}, },
detached() { detached() {
console.log('configureDevice3 detached'); // 在组件实例被从页面节点树移除时执行
console.log('MyComponent detached!');
} }
}, },
// 组件的方法 // 组件的方法
methods: { methods: {
initWifi() { initWifi() {
this.setData({ wifiStatus: 'loading' }); wx.showLoading({
wx.showLoading({ title: "正在获取Wi-Fi列表...", mask: true }); title: "正在获取Wi-Fi列表...",
const activeProtocol = app.globalData.ppScale.activeProtocol; mask: true
if (!activeProtocol) {
wx.hideLoading();
this.setData({ wifiStatus: 'failed' });
return;
}
// 15秒超时:断开设备静默重连
const timer = setTimeout(() => {
wx.hideLoading();
this.setData({ wifiStatus: 'failed' });
// 延长时间 失败调用退出wifi配网
activeProtocol.dataExitWifiConfig((res) => {
console.log("dataExitWifiConfig", res)
})
}, 15000);
// 延时两秒后再调用接口
setTimeout(() => {
activeProtocol.dataFindSurroundDevice((res) => {
console.log("wifi列表", res)
clearTimeout(timer);
wx.hideLoading();
if (res.length === 0) {
activeProtocol.dataExitWifiConfig((res) => {
console.log("dataExitWifiConfig", res)
})
this.setData({ wifiStatus: 'failed' });
return;
}
this.setData({ wifiList: res, wifiStatus: 'success' });
});
}, 2000);
},
// 最小化后重连,重置所有状态并重新获取 WiFi 列表
reInitWifi() {
this.setData({
progress: 0,
wifiStatus: 'loading',
wifiList: [],
selectWifi: null,
selectWifiPWD: ""
}); });
this.initWifi(); app.globalData.ppScale.activeProtocol.dataFindSurroundDevice((res) => {
wx.hideLoading();
this.setData({
wifiList: res
})
})
}, },
selectDevice(e) { selectDevice(e) {
@@ -91,53 +57,101 @@ Component({
}, },
setWifiPWD() { setWifiPWD() {
this.setData({ progress: 2 }); this.setData({
progress: 2
})
let version = app.globalData.ppScale.version; app.globalData.ppScale.activeProtocol.dataConfigNetWork({
if (version === 'domain1') { domain: app.globalData.ppScale.domain,
app.globalData.ppScale.activeProtocol.dataConfigNetWork({ ssid: this.data.selectWifi.ssid,
domain: app.globalData.ppScale.domain1, password: this.data.selectWifiPWD
ssid: this.data.selectWifi.ssid, }, (res) => {
password: this.data.selectWifiPWD console.log("setNetwork.js dataConfigNetWork", res);
}, (res) => {
console.log("setNetwork.js dataConfigNetWork 1", res);
this.netWorkCallBack(res);
});
}
if (version === 'domain2') {
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
domain: app.globalData.ppScale.domain2,
ssid: this.data.selectWifi.ssid,
password: this.data.selectWifiPWD,
userName: "apiUser",
userPassword: "3acebb95eb49577e9c2a2082589b9bd6",
}, (res) => {
console.log("setNetwork.js dataConfigUserNetWork 2", res);
this.netWorkCallBack(res);
});
}
},
netWorkCallBack(res) { if(res === 23) {
if(res == 23) { app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid;
app.globalData.ppScale.wifi.ssid = this.data.selectWifi.ssid; app.globalData.ppScale.wifi.password = this.data.selectWifiPWD;
app.globalData.ppScale.wifi.password = this.data.selectWifiPWD;
let mac = app.globalData.ppScale.device.mac;
this.triggerEvent('deviceEvent', { let deviceId = app.globalData.ppScale.device.connection.deviceId;
status: true if(mac && deviceId) {
}); let scaleDeviceId = mac.replace(/:/g, '');
} else { let params = {
app.globalData.ppScale.plugin.Blue.stop(); equipmentName: app.globalData.ppScale.device.name,
wx.showToast({ scaleDeviceId: scaleDeviceId,
icon: "none", deviceId: deviceId
title: "配网失败,错误码:" + res };
}) $.ajax("weighingScale/binding/device", params, "POST").then(res => {
setTimeout(() => { if (res.success) {
wx.navigateBack({ app.globalData.ppScale.activeProtocol.codeSetBindingState((res) => {
delta: 2 console.log("setNetwork.js codeSetBindingState", res);
if(res == 0) {
this.triggerEvent('deviceEvent', {
status: true
});
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
title: "绑定失败,请重试。",
icon: "none"
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
})
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: res.message
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
}).catch(err => {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: err.message
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
})
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "Mac 地址与 deviceId 获取失败,请重新绑定"
})
setTimeout(() => {
wx.navigateBack({
delta: 2
})
}, 1500)
}
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
}) })
}, 1500) setTimeout(() => {
} wx.navigateBack({
delta: 2
})
}, 1500)
}
})
} }
} }
}); });
@@ -7,33 +7,18 @@
</view> </view>
<view class="progress0_content"> <view class="progress0_content">
<block wx:if="{{wifiList && wifiList.length}}"> <scroll-view class="scrollView" scroll-y>
<scroll-view class="scrollView" scroll-y> <view class="scrollViewContent">
<view class="scrollViewContent"> <block wx:for="{{wifiList}}" wx:key="index">
<block wx:for="{{wifiList}}" wx:key="index"> <view data-item="{{item}}" bind:tap="selectDevice" class="~arrowAfter">
<view data-item="{{item}}" bind:tap="selectDevice" class="~arrowAfter"> <view>
<view> <image src="/images/configureDevice/wifi.png" />
<image src="/images/configureDevice/wifi.png" />
</view>
<view>{{item.ssid}}</view>
</view> </view>
</block> <view>{{item.ssid}}</view>
</view> </view>
</scroll-view>
</block>
<block wx:else>
<view class="nullData">
<view>
<image src="/images/configureDevice/null.png" />
</view>
<block wx:if="{{wifiStatus === 'loading'}}">
<view>正在获取WiFi列表中...</view>
</block>
<block wx:else>
<view bind:tap="reInitWifi">获取WiFi失败,点击重试</view>
</block> </block>
</view> </view>
</block> </scroll-view>
</view> </view>
</view> </view>
</block> </block>
@@ -35,25 +35,6 @@
line-height: 30rpx; line-height: 30rpx;
} }
.nullData {
width: 100%;
padding: 200rpx 0 250rpx;
}
.nullData>view:first-of-type {
width: 230rpx;
height: 160rpx;
margin: 0 auto 15rpx;
}
.nullData>view:last-of-type {
color: #B6B6B6;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
text-align: center;
}
.progress0_content { .progress0_content {
width: 100%; width: 100%;
height: calc(100% - 166rpx); height: calc(100% - 166rpx);
@@ -188,7 +169,7 @@
margin: 0 auto; margin: 0 auto;
text-align: center; text-align: center;
border-radius: 44rpx; border-radius: 44rpx;
background-color: #1385FA; background-color: #8363F9;
} }
@@ -206,7 +187,7 @@
} }
.progress2>view:nth-of-type(2) { .progress2>view:nth-of-type(2) {
color: #1385FA; color: #8363F9;
width: 100%; width: 100%;
height: 36rpx; height: 36rpx;
font-size: 36rpx; font-size: 36rpx;
@@ -1,58 +1,9 @@
const app = getApp();
import $ from "../../utils/request";
Component({ Component({
data: {},
methods: { methods: {
bindOk() { bindOk() {
this.triggerEvent('deviceEvent', { status: true }); this.triggerEvent('deviceEvent', {
}, status: true
});
// 开始 OTA 升级
startOtaUpgrade() {
const ppScale = app.globalData.ppScale;
const activeProtocol = ppScale.activeProtocol;
if (!activeProtocol) {
wx.showToast({ title: '设备未连接,请重新连接', icon: 'none' });
return;
}
const res = ppScale.device.version;
// 解析固件版本号:格式 "006.005.004.305" → [mcu, ble, wifi, res]
const [mcuVer, bleVer, wifiVer, resVer] = (res.firmwareRevision || "").split(".");
$.ajax("weighingScale/v2/firmware/version", {
type: res.modelNumber
}, "GET", false, "").then(serverRes => {
if (serverRes.result) {
/**
* 判断服务端版本是否大于设备端版本(需要升级)
* @param {string} deviceVer - 设备端单段版本,如 "006"
* @param {string} serverVer - 服务端完整版本,如 "0.0.6"
* @returns {boolean} true 表示服务端版本更新,需要升级
*/
const isServerNewer = (deviceVer, serverVer) => {
// 设备端单段数字化(去前导零),如 "006" → 6
const deviceNum = parseInt(deviceVer, 10);
// 服务端版本各段累乘1000合并为整数,如 "0.0.6" → 6"1.0.2" → 1002
const serverNum = (serverVer || "").split(".").map(v => parseInt(v, 10)).reduce((acc, v) => acc * 1000 + v, 0);
return serverNum > deviceNum;
};
const needUpdate = isServerNewer(mcuVer, serverRes.result.mcuVersion) || isServerNewer(bleVer, serverRes.result.bleVersion) || isServerNewer(wifiVer, serverRes.result.wifiVersion) || isServerNewer(resVer, serverRes.result.resVersion);
if (needUpdate) {
// status: false = 成功,true = 失败
activeProtocol.codeOtaUpdate((status) => {
console.log("OTA 升级结果:", status);
});
}
}
}).catch(() => {
wx.showToast({ title: '获取最新版本失败', icon: 'none' });
});
} }
} }
}); });
@@ -9,4 +9,4 @@
<view class="describe">随时随地同步测量数据</view> <view class="describe">随时随地同步测量数据</view>
<view class="btn" bind:tap="bindOk">完成</view> <view class="btn" bind:tap="bindOk">完成</view>
</view> </view>
@@ -7,7 +7,7 @@
.icon { .icon {
width: 100%; width: 100%;
margin-bottom: 400rpx; margin-bottom: 475rpx;
} }
.icon>view:first-of-type { .icon>view:first-of-type {
@@ -45,58 +45,5 @@
line-height: 88rpx; line-height: 88rpx;
text-align: center; text-align: center;
border-radius: 44rpx; border-radius: 44rpx;
margin-bottom: 45rpx; background-color: #8363F9;
background-color: #1385FA;
}
.ota {
color: #1385FA;
width: 100%;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 86rpx;
text-align: center;
border-radius: 44rpx;
box-sizing: border-box;
border: 1rpx solid #1385FA;
}
/* OTA 升级进度样式 */
.ota-progress-container {
width: 100%;
margin-bottom: 30rpx;
padding: 20rpx;
background-color: #F5F5F5;
border-radius: 12rpx;
box-sizing: border-box;
}
.ota-message {
color: #252535;
font-size: 28rpx;
margin-bottom: 15rpx;
text-align: center;
}
.progress-bar {
width: 100%;
height: 8rpx;
background-color: #E0E0E0;
border-radius: 4rpx;
overflow: hidden;
margin-bottom: 10rpx;
}
.progress-fill {
height: 100%;
background-color: #1385FA;
transition: width 0.3s ease;
}
.progress-text {
color: #1385FA;
font-size: 24rpx;
text-align: center;
font-weight: bold;
} }
@@ -22,17 +22,14 @@ Component({
title: "正在获取Wi-Fi列表...", title: "正在获取Wi-Fi列表...",
mask: true mask: true
}); });
const activeProtocol = app.globalData.ppScale.activeProtocol; app.globalData.ppScale.activeProtocol.dataFindSurroundDevice((res) => {
if (!activeProtocol) {
wx.hideLoading();
wx.showToast({ title: '设备未连接,请重试', icon: 'none' });
return;
}
activeProtocol.dataFindSurroundDevice((res) => {
console.log("connectedDevice ===》dataFindSurroundDevice", res); console.log("connectedDevice ===》dataFindSurroundDevice", res);
wx.hideLoading(); wx.hideLoading();
this.setData({ wifiList: Array.isArray(res) ? res : [] }); this.setData({
}); wifiList: res
})
})
}, },
selectDevice(e) { selectDevice(e) {
@@ -91,5 +91,5 @@
margin: 0 auto; margin: 0 auto;
text-align: center; text-align: center;
border-radius: 44rpx; border-radius: 44rpx;
background-color: #1385FA; background-color: #8363F9;
} }
+33 -50
View File
@@ -23,6 +23,7 @@ Component({
this.setNerwork(); this.setNerwork();
}, },
detached() { detached() {
} }
}, },
@@ -31,60 +32,42 @@ Component({
setNerwork() { setNerwork() {
let ssid = this.properties.ssid; let ssid = this.properties.ssid;
let password = this.properties.password; let password = this.properties.password;
let version = app.globalData.ppScale.version; app.globalData.ppScale.activeProtocol.dataConfigNetWork({
if (version === 'domain1') { domain: app.globalData.ppScale.domain,
app.globalData.ppScale.activeProtocol.dataConfigNetWork({ ssid: ssid,
domain: app.globalData.ppScale.domain1, password: password
ssid: ssid, }, (res) => {
password: password console.log("setNetwork.js dataConfigNetWork", res);
}, (res) => {
console.log("setNetwork.js dataConfigNetWork 1", res);
this.netWorkCallBack(res);
});
}
if (version === 'domain2') {
app.globalData.ppScale.activeProtocol.dataConfigUserNetWork({
domain: app.globalData.ppScale.domain2,
ssid: ssid,
password: password,
userName: "apiUser",
userPassword: "3acebb95eb49577e9c2a2082589b9bd6"
}, (res) => {
console.log("setNetwork.js dataConfigUserNetWork 2", res);
this.netWorkCallBack(res);
});
}
},
netWorkCallBack(res) { if(res === 23) {
if(res === 23) { app.globalData.ppScale.wifi.ssid = ssid;
app.globalData.ppScale.wifi.ssid = this.properties.ssid; app.globalData.ppScale.wifi.password = password;
app.globalData.ppScale.wifi.password = this.properties.password;
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, ''); let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, '');
if(scaleDeviceId) { if(scaleDeviceId) {
let params = { let params = {
equipmentCode: scaleDeviceId, equipmentCode: scaleDeviceId,
wifiName: this.properties.ssid wifiName: ssid
}; };
$.ajax("weighingScale/edit/device", params, "POST").then((res) => { $.ajax("weighingScale/edit/device", params, "POST").then((res) => {
this.triggerEvent('wifiEvent', { this.triggerEvent('wifiEvent', {
status: true status: true
}); });
})
}
} else {
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
}) })
setTimeout(() => {
this.triggerEvent('wifiEvent', {
status: false
});
}, 1500)
} }
} else { })
app.globalData.ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "配网失败,错误码:" + res
})
setTimeout(() => {
this.triggerEvent('wifiEvent', {
status: false
});
}, 1500)
}
} }
} }
}); });
@@ -12,7 +12,7 @@
} }
.replaceNetwork3>view:nth-of-type(2) { .replaceNetwork3>view:nth-of-type(2) {
color: #1385FA; color: #8363F9;
width: 100%; width: 100%;
height: 36rpx; height: 36rpx;
font-size: 36rpx; font-size: 36rpx;
@@ -45,5 +45,5 @@
line-height: 88rpx; line-height: 88rpx;
text-align: center; text-align: center;
border-radius: 44rpx; border-radius: 44rpx;
background-color: #1385FA; background-color: #8363F9;
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

+177 -258
View File
@@ -1,274 +1,193 @@
const app = getApp(); const ppScale = getApp().globalData.ppScale;
const ppScale = app.globalData.ppScale; import $ from "../../utils/request";
Page({ Page({
data: { data: {
progress: { progress: {
index: 0, index: 0,
data: ['配置蓝牙', '初始化用户信息', '配备网络', '完成'] data: ['配置蓝牙', '初始化用户信息', '配备网络', '完成']
}, },
progressNext: false, progressNext: false,
device: null device: null
}, },
onLoad() {
ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("===》devicesModel", res);
ppScale.device.mac = res.deviceMac;
onLoad() { ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
// 一次性数据初始化,订阅逻辑在 onShow 中注册 console.log('===》deviceConnect', res);
},
ppScale.plugin.ScaleAction.startDataProgress(true);
ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol();
ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("===》codeUpdateMTU", res);
ppScale.activeProtocol.codeFetchBindingState((res) => {
console.log("===》codeFetchBindingState", res);
// 记录 stop() 调用时间,用于 onShow 动态计算安全延迟 ppScale.activeProtocol.codeSyncTime((codeSyncTime) => {
_stopTime: 0, console.log("===》codeSyncTime", codeSyncTime)
onShow() { wx.hideLoading();
console.log("configureDevice onShow"); if (res === 1) {
const elapsed = Date.now() - (this._stopTime || 0); wx.showModal({
const delay = Math.max(0, 500 - elapsed); title: '提示',
setTimeout(() => { content: '当前设备已被绑定,你确定要覆盖绑定吗?',
// 注册 app 级别的全局 bus 订阅(stop() 已清空,直接重新订阅) success: (res) => {
app.registerBusListeners(); 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 => {
ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "设备初始化成功,请重新绑定。",
})
// device.list = [];
// device.mac = null;
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500);
});
} else {
ppScale.plugin.Blue.stop();
wx.showToast({
icon: "none",
title: "设备初始化失败。",
})
}
})
} else if (res.cancel) {
// device.mac = null;
ppScale.plugin.Blue.stop();
}
}
})
} 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)
})
}
}
})
})
});
});
});
},
// 页面级 bus 订阅 // 选择了某个设备
ppScale.plugin.bus.subscribe("devicesModel", (res) => { deviceChange(e) {
console.log("===》devicesModel", res); let status = e.detail.status;
ppScale.device.mac = res.deviceMac; if(status) {
this._macReady = true; wx.showLoading({
this._tryProgress(); title: "蓝牙配对中...",
}); mask: true
});
this.setData({
progressNext: true
})
let device = e.detail.device;
this.connectedDevice_(device);
}
},
ppScale.plugin.bus.subscribe("deviceConnect", (res) => { connectedDevice(e) {
console.log('===》deviceConnect', res); wx.showLoading({
ppScale.plugin.ScaleAction.startDataProgress(true); title: "正在尝试连接...",
ppScale.activeProtocol = ppScale.plugin.ScaleAction.getActiveProtocol(); mask: true
});
this.setData({
progressNext: false
})
let device = e.detail.device;
this.connectedDevice_(device);
},
let currentStep = this.data.progress.index; connectedDevice_(device) {
if(device) {
this.setData({
device: device
})
ppScale.plugin.Blue.createBLEConnection(device);
}
},
// 步骤 1/2/3:最小化后重连,只需恢复连接状态 setDeviceUserInfo(e) {
if (currentStep >= 1) { this.setData({
ppScale.activeProtocol.codeUpdateMTU((mtuRes) => { progressNext: true
console.log("===》重连 codeUpdateMTU", mtuRes); })
ppScale.device.name = this.data.device.name; let status = e.detail.status;
ppScale.device.connection = this.data.device; if(status) {
wx.hideLoading(); this.setProgress();
if (currentStep === 2) { }
const comp = this.selectComponent('#configureDevice3'); },
if (comp) comp.reInitWifi();
}
});
return;
}
// 步骤 0:首次连接设备 setDeviceConfig(e) {
ppScale.activeProtocol.codeUpdateMTU((mtuRes) => { let status = e.detail.status;
console.log("===》codeUpdateMTU", mtuRes); if(status) {
ppScale.activeProtocol.codeSyncTime((codeSyncTime) => { this.setProgress();
console.log("===》codeSyncTime", codeSyncTime); }
wx.hideLoading(); },
ppScale.device.name = this.data.device.name;
ppScale.device.connection = this.data.device;
const nameArr = this.data.device.name.split("-");
ppScale.version = nameArr.length === 5 ? "domain2" : "domain1";
this._connectReady = true;
this._tryProgress();
});
});
});
// 如果之前已选择过设备,自动扫描并重连 setConfigSuccessful() {
if (this.data.device) { ppScale.plugin.Blue.stop();
wx.showLoading({ title: "正在重新连接...", mask: true }); wx.switchTab({
ppScale.plugin.bus.subscribe("devicesList", (res) => { url: "/pages/home/home"
let fIndex = res.findIndex(item => item.deviceId === this.data.device.deviceId); })
if (fIndex >= 0) { },
ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
}
});
}
// 通过完整链路重新初始化蓝牙(权限检查 → 打开适配器 → start) setProgress() {
this.checkBluetoothPermissionAndInit(); this.setData({
}, delay); ["progress.index"]: this.data.progress.index + 1
}, })
},
// 选择了某个设备 onUnload() {
deviceChange(e) { ppScale.plugin.Blue.stop();
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) {
app.resetReconnectCount();
wx.showLoading({ title: "正在尝试连接...", mask: true });
this.setData({ progressNext: false });
let device = e.detail.device;
// 先断开旧连接再重新连接
ppScale.plugin.Blue.disconnect((disres) => {
this.connectedDevice_(device);
});
},
connectedDevice_(device) {
if (device) {
this.setData({
device: device
})
ppScale.plugin.Blue.createBLEConnection(device);
ppScale.plugin.bus.subscribe("deviceInfo", (res) => {
console.log("===》deviceInfo", res);
ppScale.device.version = res;
})
}
},
setDeviceUserList(e) {
let { status, progressIndex } = e.detail;
if (status) {
// progressIndex 由子组件根据配网状态决定:2=进入配网,3=跳过配网
if (progressIndex !== undefined) {
this.setProgressTo(progressIndex);
} else {
this.setProgress();
}
}
},
setDeviceConfig(e) {
let status = e.detail.status;
if (status) {
this.setProgress();
}
},
setConfigSuccessful() {
app.cleanupConnection();
wx.switchTab({
url: "/pages/home/home"
})
},
setProgress() {
const newIndex = this.data.progress.index + 1;
this.setProgressTo(newIndex);
},
// 直接跳转到指定步骤,统一处理各步骤的初始化副作用
setProgressTo(newIndex) {
this.setData({ "progress.index": newIndex });
// 进入步骤2(配网)时,等待组件渲染完成后由父页面显式触发 WiFi 列表获取
if (newIndex === 2) {
setTimeout(() => {
const comp = this.selectComponent('#configureDevice3');
if (comp) comp.initWifi();
}, 300);
}
// 进入步骤3(OTA升级)时,等待组件渲染完成后由父页面显式触发升级
if (newIndex === 3) {
setTimeout(() => {
const comp = this.selectComponent('#configureDevice4');
if (comp) comp.startOtaUpgrade();
}, 300);
}
},
// 连接完成 + mac 获取完成,双条件满足后才进入下一步
_connectReady: false,
_macReady: false,
_tryProgress() {
if (this._connectReady && this._macReady && this.data.progressNext) {
this._connectReady = false;
this._macReady = false;
this.setData({ progressNext: false });
this.setProgress();
}
},
checkBluetoothPermissionAndInit() {
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.bluetooth']) {
this.openBluetoothAdapter();
} else {
wx.authorize({
scope: 'scope.bluetooth',
success: () => {
this.openBluetoothAdapter();
},
fail: () => {
wx.hideLoading();
wx.showModal({
title: '提示',
content: '蓝牙权限被拒绝,无法连接设备。是否前往设置开启?',
confirmText: '去开启',
cancelText: '不开启',
success: (modalRes) => {
if (modalRes.confirm) {
wx.openSetting();
}
}
});
}
});
}
},
fail: () => {
wx.hideLoading();
}
});
},
openBluetoothAdapter() {
wx.openBluetoothAdapter({
success: () => {
// 蓝牙适配器打开成功,设置设备配置后启动扫描
let setting = ppScale.device.setting;
ppScale.plugin.Blue.setDeviceSetting(setting);
let deviceNames = setting.map(item => item.deviceName);
ppScale.plugin.Blue.start(deviceNames, false);
},
fail: (err) => {
wx.hideLoading();
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请确保手机蓝牙已开启。",
showCancel: false
});
}
}
});
},
onHide() {
console.log("configureDevice onHide");
app.cleanupConnection();
// 配网步骤:立即清空 WiFi 列表(stop 后数据已失效)
if (this.data.progress.index === 2) {
const comp = this.selectComponent('#configureDevice3');
if (comp) {
comp.setData({ progress: 0, wifiList: [], selectWifi: null, selectWifiPWD: "" });
}
}
this._connectReady = false;
this._macReady = false;
this._stopTime = Date.now();
},
onUnload() {
console.log("configureDevice onUnload");
app.cleanupConnection();
this._connectReady = false;
this._macReady = false;
this._stopTime = Date.now();
}
}) })
+4 -4
View File
@@ -3,7 +3,7 @@
<block wx:for="{{progress.data}}" wx:key="index"> <block wx:for="{{progress.data}}" wx:key="index">
<view class="progressList"> <view class="progressList">
<view style="background-color: {{progress.index >= index ? '#BFDEFD' : '#C1DFFE'}};"> <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 style="height: {{progress.index >= index ? '24rpx' : '40rpx'}};width: {{progress.index >= index ? '24rpx' : '40rpx'}};background-color: {{progress.index >= index ? '#8363F9' : '#77849E'}};">{{progress.index >= index ? '' : index + 1}}</view>
</view> </view>
<view class="{{progress.index >= index ? 'active' : ''}}">{{item}}</view> <view class="{{progress.index >= index ? 'active' : ''}}">{{item}}</view>
</view> </view>
@@ -15,13 +15,13 @@
<configureDevice1 bind:deviceEvent="deviceChange"></configureDevice1> <configureDevice1 bind:deviceEvent="deviceChange"></configureDevice1>
</block> </block>
<block wx:if="{{progress.index === 1}}"> <block wx:if="{{progress.index === 1}}">
<configureDevice2 bind:deviceEvent="setDeviceUserList" bind:connectedDeviceEvent="connectedDevice"></configureDevice2> <configureDevice2 bind:deviceEvent="setDeviceUserInfo" bind:connectedDeviceEvent="connectedDevice"></configureDevice2>
</block> </block>
<block wx:if="{{progress.index === 2}}"> <block wx:if="{{progress.index === 2}}">
<configureDevice3 id="configureDevice3" bind:deviceEvent="setDeviceConfig"></configureDevice3> <configureDevice3 bind:deviceEvent="setDeviceConfig"></configureDevice3>
</block> </block>
<block wx:if="{{progress.index === 3}}"> <block wx:if="{{progress.index === 3}}">
<configureDevice4 id="configureDevice4" bind:deviceEvent="setConfigSuccessful"></configureDevice4> <configureDevice4 bind:deviceEvent="setConfigSuccessful"></configureDevice4>
</block> </block>
</view> </view>
</view> </view>
+1 -1
View File
@@ -70,7 +70,7 @@
} }
.active { .active {
color: #3194FB !important; color: #8363F9 !important;
font-weight: bold !important; font-weight: bold !important;
} }
+46
View File
@@ -0,0 +1,46 @@
const app = getApp();
import $ from "../../utils/request";
Page({
data: {
deviceInfo: null,
},
onShow() {
this.getDevice();
},
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
this.setData({
deviceInfo: res.result[0]
})
})
},
openReplaceNetwork() {
wx.navigateTo({
url: "/pages/replaceNetwork/replaceNetwork"
})
},
delDevice() {
let scaleDeviceId = this.data.deviceInfo.macAddress.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);
});
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "设备详情",
"disableScroll": true
}
+32
View File
@@ -0,0 +1,32 @@
<view class="device">
<view>
<block wx:if="{{deviceInfo && deviceInfo.type}}">
<image src="/images/devices/{{deviceInfo.type}}.png" />
</block>
</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 class="arrowAfter" bind:tap="openReplaceNetwork">
<view>Wi-Fi名称</view>
<view>{{deviceInfo.wifiName}}</view>
</view>
<view>
<view>成员</view>
<view>{{deviceInfo.subUserNum}}人</view>
</view>
</view>
<view class="btn" bind:tap="delDevice">删除设备</view>
+102
View File
@@ -0,0 +1,102 @@
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;
}
.arrowAfter {
padding-right: 60rpx !important;
}
.arrowAfter::after {
right: 30rpx;
}
.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: #8363F9;
}
-66
View File
@@ -1,66 +0,0 @@
// pages/help/help.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
-4
View File
@@ -1,4 +0,0 @@
{
"navigationBarTitleText": "帮助信息",
"usingComponents": {}
}
-2
View File
@@ -1,2 +0,0 @@
<!--pages/help/help.wxml-->
<text>pages/help/help.wxml</text>
-1
View File
@@ -1 +0,0 @@
/* pages/help/help.wxss */
+26 -14
View File
@@ -3,14 +3,22 @@ import $ from "../../utils/request";
Page({ Page({
data: { data: {
token: null, token: null,
userInfo: null,
deviceList: []
}, },
onShow() { onShow() {
let userInfo = wx.getStorageSync("userInfo") || null;
let token = wx.getStorageSync("token") || null; let token = wx.getStorageSync("token") || null;
this.setData({ this.setData({
token: token, token: token,
// deviceList: [] userInfo: userInfo,
deviceList: []
}) })
if(token) {
this.getDevice();
}
}, },
// 点击登录或注册 // 点击登录或注册
@@ -35,10 +43,12 @@ Page({
let params = { let params = {
code: code code: code
}; };
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "加载中...").then((res) => { $.ajax("weighingScale/checkOpenIdLogin/v2", params, "POST", true, "加载中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token); wx.setStorageSync("token", res.result.token);
this.setData({ this.setData({
token: res.result.token token: res.result.token,
userInfo: res.result.user
}) })
if(bol) { if(bol) {
@@ -47,6 +57,16 @@ Page({
}) })
}, },
// 获取已经绑定的设备列表
getDevice() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => {
this.setData({
deviceList: res.result
})
})
},
// 添加设备 // 添加设备
openSearchDevice() { openSearchDevice() {
wx.navigateTo({ wx.navigateTo({
@@ -54,18 +74,10 @@ Page({
}) })
}, },
// 点击查看帮助 // 打开设备详情
openHelp() { openDeviceInfo() {
wx.navigateTo({ wx.navigateTo({
url: "/pages/help/help" url: "/pages/deviceInfo/deviceInfo"
}) })
},
onShareAppMessage() {
return {
title: '智能蓝牙秤',
path: '/pages/home/home',
imageUrl: '/images/share/share.jpg',
}
} }
}) })
+22 -16
View File
@@ -1,5 +1,5 @@
<view class="bg"> <view class="bg">
<image src="/images/home/bg.jpg"/> <image src="/images/home/bg.png"/>
</view> </view>
<view class="home"> <view class="home">
@@ -8,26 +8,32 @@
<view> <view>
<image src="/images/home/user.png" /> <image src="/images/home/user.png" />
</view> </view>
<block wx:if="{{token}}"> <block wx:if="{{userInfo || token}}">
<view>已登录</view> <view>{{userInfo ? userInfo.realname : '已登录'}}</view>
</block> </block>
<block wx:else> <block wx:else>
<view class="arrowAfter" data-bol="{{false}}" 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 class="addDevice">
<view>请添加设备</view>
<view>添加设备后,解锁更多体验</view>
<block wx:if="{{token}}">
<view bind:tap="openSearchDevice">添加设备</view>
</block>
<block wx:else>
<view data-bol="{{true}}" bind:tap="openLoginOrReg">添加设备</view>
</block>
<view bind:tap="openHelp">无法连接设备? 点击查看</view>
</view> </view>
<block wx:if="{{deviceList && deviceList.length}}">
<view class="device" bind:tap="openDeviceInfo">
<view>
<image src="/images/devices/{{deviceList[0].type}}.png" />
</view>
<view>设备名称:{{deviceList[0].equipmentName}}</view>
</view>
</block>
<block wx:else>
<view class="addDevice">
<block wx:if="{{userInfo && token}}">
<view bind:tap="openSearchDevice">添加设备</view>
</block>
<block wx:else>
<view data-bol="{{true}}" bind:tap="openLoginOrReg">添加设备</view>
</block>
</view>
</block>
</view> </view>
+34 -52
View File
@@ -17,7 +17,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
padding: 215rpx 60rpx 30rpx; padding: 215rpx 60rpx 120rpx;
box-sizing: border-box; box-sizing: border-box;
} }
@@ -57,26 +57,40 @@
.title>view:nth-of-type(2) { .title>view:nth-of-type(2) {
color: #FFFFFF; color: #FFFFFF;
height: 58rpx; height: 80rpx;
font-size: 58rpx; font-size: 80rpx;
font-weight: bold; font-weight: bold;
line-height: 58rpx; line-height: 80rpx;
margin-bottom: 34rpx; margin-bottom: 45rpx;
text-align: center;
} }
.title>view:nth-of-type(3) { .title>view:nth-of-type(3) {
color: #FFFFFF; color: #FFFFFF;
height: 32rpx; height: 40rpx;
font-size: 32rpx; font-size: 40rpx;
line-height: 32rpx; line-height: 40rpx;
margin-bottom: 48rpx; text-align: center;
} }
.title>view:nth-of-type(4) { .device {
width: 120rpx; width: 100%;
height: 6rpx; }
border-radius: 3rpx;
background-color: #FFFFFF; .device>view:nth-of-type(1) {
width: 500rpx;
height: 500rpx;
margin: 0 auto 16rpx;
}
.device>view:nth-of-type(2) {
color: #ffffff;
width: 100%;
height: 32rpx;
font-weight: bold;
font-size: 32rpx;
line-height: 32rpx;
text-align: center;
} }
.addDevice { .addDevice {
@@ -84,47 +98,15 @@
margin: 0 auto; margin: 0 auto;
} }
.addDevice>view:nth-of-type(1) { .addDevice>view {
color: #FFFFFF; color: #FFFFFF;
width: 100%; width: 100%;
height: 36rpx; height: 88rpx;
font-size: 36rpx;
font-weight: bold;
text-align: center;
line-height: 36rpx;
margin-bottom: 30rpx;
}
.addDevice>view:nth-of-type(2) {
color: #FFFFFF;
width: 100%;
height: 30rpx;
font-size: 30rpx;
text-align: center;
line-height: 30rpx;
margin-bottom: 80rpx;
}
.addDevice>view:nth-of-type(3) {
color: #FFFFFF;
width: 100%;
height: 106rpx;
font-size: 32rpx; font-size: 32rpx;
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
line-height: 106rpx; line-height: 88rpx;
border-radius: 16rpx; border-radius: 44rpx;
box-sizing: border-box; border: 1rpx solid #FFFFFF;
margin-bottom: 10rpx; background-color: rgba(0, 0, 0, .4);
border: 1rpx solid #FFFFFF;
} }
.addDevice>view:nth-of-type(4) {
width: 100%;
color: #FFFFFF;
font-size: 30rpx;
height: 70rpx;
line-height: 70rpx;
text-align: center;
text-decoration-line: underline;
}
+89 -20
View File
@@ -2,34 +2,96 @@ import $ from "../../utils/request";
Page({ Page({
data: { data: {
token: null userInfo: null,
token: null,
deviceInfo: null
}, },
onShow() { onShow() {
let token = wx.getStorageSync("token") || null; let token = wx.getStorageSync("token") || null;
let userInfo = wx.getStorageSync("userInfo") || null;
this.setData({ this.setData({
userInfo: userInfo,
token: token token: token
}) })
if(token) {
this.getDevice(false);
}
}, },
openLoginOrReg() { openLoginOrReg() {
if (!this.data.token) { if(this.data.token) {
this.openLoginOrReg_();
} else {
this.starLogin().then(() => { this.starLogin().then(() => {
this.getDevice(true);
}).catch(() => { }).catch(() => {
wx.showToast({ wx.showToast({
title: "登录失败,请重试!", title: "登录失败,请重试!",
icon: "none" icon: "none"
}) })
})
}
},
openLoginOrReg_() {
let deviceInfo = this.data.deviceInfo;
if(deviceInfo) {
wx.navigateTo({
url: "/pages/userInfo/userInfo"
})
} else {
wx.showModal({
title: "提示",
content: "当前用户暂未绑定设备,需要绑定吗?",
confirmText: "去绑定",
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
}
}
}) })
} }
}, },
wifiChange() { // 打开设备详情
wx.navigateTo({ openDeviceInfo() {
url: "/pages/searchDevice/searchDevice" if(this.data.token) {
}) this.openDeviceInfo_();
}, } else {
this.starLogin().then(() => {
this.openDeviceInfo_();
}).catch(() => {
wx.showToast({
title: "登录失败,请重试!",
icon: "none"
})
})
}
},
openDeviceInfo_ () {
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"
})
}
}
})
}
},
starLogin() { starLogin() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -39,10 +101,12 @@ Page({
let params = { let params = {
code: res.code code: res.code
}; };
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => { $.ajax("weighingScale/checkOpenIdLogin/v2", params, "POST", true, "登录中...").then((res) => {
wx.setStorageSync("userInfo", res.result.user);
wx.setStorageSync("token", res.result.token); wx.setStorageSync("token", res.result.token);
this.setData({ this.setData({
token: res.result.token, token: res.result.token,
userInfo: res.result.user
}) })
resolve(); resolve();
}).catch((err) => { }).catch((err) => {
@@ -56,6 +120,19 @@ Page({
}) })
}, },
// 获取已经绑定的设备列表
getDevice(bol) {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
this.setData({
deviceInfo: res.result && res.result.length ? res.result[0] : null
})
if(bol) {
this.openLoginOrReg_();
}
})
},
// 退出登录 // 退出登录
exitLogin() { exitLogin() {
wx.showModal({ wx.showModal({
@@ -78,13 +155,5 @@ Page({
} }
} }
}) })
},
onShareAppMessage() {
return {
title: '智能蓝牙秤',
path: '/pages/home/home',
imageUrl: '/images/share/share.jpg',
}
} }
}) })
+29 -4
View File
@@ -1,23 +1,48 @@
<view class="userInfo"> <view class="userInfo">
<view class="user" bind:tap="openLoginOrReg"> <view class="user {{userInfo || token ? 'arrowAfter' : ''}}" bind:tap="openLoginOrReg">
<view> <view>
<image src="/images/my/user.png" /> <image src="/images/my/user.png" />
</view> </view>
<view> <view>
<block wx:if="{{token}}">已登录</block> <block wx:if="{{userInfo || token}}">
{{userInfo ? userInfo.realname : '已登录'}}
</block>
<block wx:else>未登录</block> <block wx:else>未登录</block>
</view> </view>
</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>
<view class="content"> <view class="content">
<view class="service"> <view class="service">
<view class="title">我的服务</view> <view class="title">我的服务</view>
<view class="list arrowAfter" bind:tap="wifiChange"> <view class="list arrowAfter" bind:tap="openDeviceInfo">
<view> <view>
<image src="/images/my/1.png" /> <image src="/images/my/1.png" />
</view> </view>
<view>更换网络</view> <view>设备绑定</view>
<view>{{deviceInfo ? '已绑定('+ deviceInfo.equipmentName +')' : '未绑定'}}</view>
</view>
<view class="list arrowAfter">
<view>
<image src="/images/my/3.png" />
</view>
<view>隐私协议</view>
<view></view> <view></view>
</view> </view>
</view> </view>
+5 -7
View File
@@ -1,6 +1,6 @@
.userInfo { .userInfo {
width: 100%; width: 100%;
/* height: 488rpx; */ height: 488rpx;
margin-bottom: 24rpx; margin-bottom: 24rpx;
box-sizing: border-box; box-sizing: border-box;
padding: 185rpx 40rpx 0; padding: 185rpx 40rpx 0;
@@ -12,8 +12,7 @@
height: 136rpx; height: 136rpx;
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
padding-bottom: 23px; margin-bottom: 46rpx;
/* margin-bottom: 46rpx; */
} }
.user>view:first-of-type { .user>view:first-of-type {
@@ -76,8 +75,7 @@
width: 100%; width: 100%;
padding: 0 30rpx; padding: 0 30rpx;
box-sizing: border-box; box-sizing: border-box;
margin-bottom: 600rpx; margin-bottom: 480rpx;
/* margin-bottom: 480rpx; */
} }
.content .arrowAfter::after { .content .arrowAfter::after {
@@ -154,7 +152,7 @@
} }
.btn>view { .btn>view {
color: #1385FA; color: #8363F9;
width: 580rpx; width: 580rpx;
height: 88rpx; height: 88rpx;
line-height: 88rpx; line-height: 88rpx;
@@ -162,6 +160,6 @@
border-radius: 44rpx; border-radius: 44rpx;
text-align: center; text-align: center;
background-color: #F5F7FB; background-color: #F5F7FB;
border: 1rpx solid #1385FA; border: 1rpx solid #8363F9;
} }
+40 -69
View File
@@ -15,20 +15,41 @@ Page({
} }
}, },
// 存储回调函数的引用,以便在 onUnload 时取消监听 // 存储回调函数的引用,以便在 detached 时取消监听
_connectStateWatcher: null, _connectStateWatcher: null,
onLoad(options) { onLoad(options) {
// 一次性数据初始化
this.checkBluetoothPermissionAndInit(); this.checkBluetoothPermissionAndInit();
console.log(`[replaceNetwork] connectState 获取: ${app.globalData.ppScale.device.connectState}`); app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("searchDevice ===》devicesModel", res);
app.globalData.ppScale.device.mac = res.deviceMac;
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('connectedDevice ===》deviceConnect', res);
app.globalData.ppScale.plugin.ScaleAction.startDataProgress(true);
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("connectedDevice ===》codeUpdateMTU", res);
app.globalData.ppScale.device.name = this.data.device.name;
app.globalData.ppScale.device.connection = this.data.device;
wx.hideLoading();
this.selectComponent('#replaceNetwork1Component').getWiFiList();
});
});
});
console.log(`[Component] connectState 获取: ${app.globalData.ppScale.device.connectState}`);
this.setData({ this.setData({
BLUE_STATE: app.globalData.ppScale.plugin.BLUE_STATE, BLUE_STATE: app.globalData.ppScale.plugin.BLUE_STATE,
connectState: app.globalData.ppScale.device.connectState connectState: app.globalData.ppScale.device.connectState
}) })
this._connectStateWatcher = (newValue, oldValue) => { this._connectStateWatcher = (newValue, oldValue) => {
console.log(`[replaceNetwork] connectState 变化: ${oldValue} -> ${newValue}`); console.log(`[Component] connectState 变化: ${oldValue} -> ${newValue}`);
this.setData({ this.setData({
connectState: newValue || '' connectState: newValue || ''
}); });
@@ -36,41 +57,6 @@ Page({
app.watch('ppScale.device.connectState', this._connectStateWatcher); app.watch('ppScale.device.connectState', this._connectStateWatcher);
}, },
onShow() {
console.log("replaceNetwork onShow");
setTimeout(() => {
// 注册 app 级别的全局 bus 订阅(stop() 已清空,直接重新订阅)
app.registerBusListeners();
// 页面级 bus 订阅
app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("replaceNetwork ===》devicesModel", res);
app.globalData.ppScale.device.mac = res.deviceMac;
});
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('replaceNetwork ===》deviceConnect', res);
app.globalData.ppScale.plugin.ScaleAction.startDataProgress(true);
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((mtuRes) => {
console.log("replaceNetwork ===》codeUpdateMTU", mtuRes);
app.globalData.ppScale.device.name = this.data.device.name;
app.globalData.ppScale.device.connection = this.data.device;
const nameArr = this.data.device.name.split("-");
app.globalData.ppScale.version = nameArr.length === 5 ? "domain2" : "domain1";
wx.hideLoading();
if (this.data.progress === 0) {
const comp = this.selectComponent('#replaceNetwork1Component');
if (comp) comp.getWiFiList();
}
});
});
// 通过完整链路重新初始化蓝牙(权限检查 → 打开蓝牙 → 获取设备 → start)
this.checkBluetoothPermissionAndInit();
}, 300);
},
checkBluetoothPermissionAndInit() { checkBluetoothPermissionAndInit() {
wx.showLoading({ wx.showLoading({
title: "正在检查蓝牙权限...", title: "正在检查蓝牙权限...",
@@ -192,42 +178,32 @@ Page({
let seviceList = app.globalData.ppScale.device.setting.find((item) => { let seviceList = app.globalData.ppScale.device.setting.find((item) => {
return item.deviceName === res.result[0].type return item.deviceName === res.result[0].type
}); });
if (!seviceList) {
wx.hideLoading();
wx.showToast({ title: '未找到匹配的设备类型', icon: 'none' });
return;
}
app.globalData.ppScale.plugin.Blue.setDeviceSetting([seviceList]); app.globalData.ppScale.plugin.Blue.setDeviceSetting([seviceList]);
app.globalData.ppScale.plugin.Blue.start(res.result[0].type, false); app.globalData.ppScale.plugin.Blue.start(res.result[0].type, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => { app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
console.log("searchDevice ===> devicesList", res_); console.log("searchDevice ===> devicesList", res_);
let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId); let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId);
if (fIndex >= 0) { if (fIndex >= 0) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery(); app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
wx.showLoading({ title: "正在连接设备...", mask: true }); wx.showLoading({
this.setData({ device: res_[fIndex] }); title: "正在连接设备...",
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[fIndex]); mask: true
} });
this.setData({
device: res_[fIndex]
})
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[fIndex]);
}
}); });
}) })
}, },
// 手动重连设备 // 点击设备重连
connectedDevice() { connectedDevice() {
app.resetReconnectCount();
let device = this.data.device; let device = this.data.device;
if(device) { if(device) {
wx.showLoading({ ppScale.plugin.Blue.createBLEConnection(device);
title: "正在重新连接设备...",
mask: true
});
app.globalData.ppScale.plugin.Blue.disconnect((disres) => {
if (disres.errCode == 0) {
app.globalData.ppScale.plugin.Blue.createBLEConnection(device);
} else {
app.globalData.ppScale.plugin.Blue.createBLEConnection(device);
}
});
} }
}, },
@@ -265,15 +241,10 @@ Page({
}) })
} }
}, },
onHide() { // 卸载事件监听
console.log("replaceNetwork onHide");
app.cleanupConnection();
},
onUnload() { onUnload() {
console.log("replaceNetwork onUnload"); app.globalData.ppScale.plugin.Blue.stop();
app.cleanupConnection();
if (this._connectStateWatcher) { if (this._connectStateWatcher) {
app.unwatch('ppScale.device.connectState', this._connectStateWatcher); app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
} }
+2 -18
View File
@@ -5,30 +5,14 @@
<view>型号:{{device.name}}</view> <view>型号:{{device.name}}</view>
</view> </view>
<view> <view>
<block wx:if="{{connectState == BLUE_STATE.CONNECTSUCCESS || connectState == BLUE_STATE.WIFISUCCESS}}"> <block wx:if="{{device && connectState == BLUE_STATE.CONNECTSUCCESS}}">
<view style="background-color: #2AC79F;"></view> <view style="background-color: #2AC79F;"></view>
<view style="color: #2AC79F;">连接成功</view> <view style="color: #2AC79F;">连接成功</view>
</block> </block>
<block wx:elif="{{connectState == BLUE_STATE.SCANING}}"> <block wx:else>
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">正在搜索...</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.READY}}">
<view style="background-color: #3194FB;"></view>
<view style="color: #3194FB;">蓝牙就绪</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.UNAVAILABLE}}">
<view style="background-color: #F24439;"></view>
<view style="color: #F24439;">蓝牙不可用</view>
</block>
<block wx:elif="{{connectState == BLUE_STATE.CONNECTFAILED}}">
<view style="background-color: #F24439;"></view> <view style="background-color: #F24439;"></view>
<view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view> <view bind:tap="connectedDevice" style="color: #F24439;">连接失败,点击重试</view>
</block> </block>
<block wx:else>
<view style="background-color: #999999;"></view>
<view style="color: #999999;">未连接</view>
</block>
</view> </view>
</view> </view>
+7 -8
View File
@@ -9,7 +9,7 @@ Page({
}, },
onLoad(options) { onLoad(options) {
// 一次性数据初始化(蓝牙初始化在 onShow 中统一处理) this.checkBluetoothPermissionAndInit();
}, },
onShow() { onShow() {
@@ -47,11 +47,10 @@ Page({
if (scopeToRequest.length > 0) { if (scopeToRequest.length > 0) {
try { try {
// 逐个授权所有缺失的权限 await wx.authorize({
for (const scope of scopeToRequest) { scope: scopeToRequest[0]
await wx.authorize({ scope }); });
} this.checkBluetoothPermissionAndInit();
this.openBluetoothAdapter();
} catch (authErr) { } catch (authErr) {
if (this.data.isShowingModal) { if (this.data.isShowingModal) {
return; return;
@@ -244,8 +243,8 @@ Page({
onUnload() { onUnload() {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery(); app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
this.setData({ this.setData({
isShowingModal: false isShowingModal: false
}); });
} }
}) })
+1 -1
View File
@@ -44,7 +44,7 @@ page {
0% { 0% {
width: 200rpx; width: 200rpx;
height: 200rpx; height: 200rpx;
background-color: #3194FB; background-color: #8363F9;
} }
100% { 100% {
width: 556rpx; width: 556rpx;
+435
View File
@@ -0,0 +1,435 @@
const app = getApp();
import $ from "../../utils/request";
Page({
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,
onLoad(options) {
this.checkBluetoothPermissionAndInit();
app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("searchDevice ===》devicesModel", res);
app.globalData.ppScale.device.mac = res.deviceMac;
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('connectedDevice ===》deviceConnect', res);
app.globalData.ppScale.plugin.ScaleAction.startDataProgress(true);
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
console.log("connectedDevice ===》codeUpdateMTU", res);
app.globalData.ppScale.device.name = this.data.device.name;
app.globalData.ppScale.device.connection = this.data.device;
wx.hideLoading();
});
});
});
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
})
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],
})
}
}
},
// 姓名输入
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) {
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.userId,
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) {
wx.showToast({
title: "用户信息更新成功。",
icon: "none"
})
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
} 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;
},
checkBluetoothPermissionAndInit() {
wx.showLoading({
title: '正在检查蓝牙权限...',
mask: true
})
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.bluetooth']) {
this.openBluetoothAdapter();
} else {
wx.hideLoading();
wx.authorize({
scope: 'scope.bluetooth',
success: () => {
this.openBluetoothAdapter();
},
fail: (err) => {
wx.hideLoading();
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) => {
wx.hideLoading();
wx.showToast({
title: '获取权限设置失败',
icon: 'none'
});
wx.navigateBack({
delta: 1
});
}
});
},
openBluetoothAdapter() {
wx.showLoading({
title: "正在初始化蓝牙...",
mask: true
});
wx.openBluetoothAdapter({
success: () => {
this.getDeviceSettingList();
},
fail: (err) => {
wx.hideLoading();
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
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
});
}
});
}
},
});
},
// 获取自己已经配对上的设备
getDeviceSettingList() {
let params = {};
$.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => {
wx.showLoading({
title: "正在寻找设备...",
mask: true
});
app.globalData.ppScale.device.list = [];
let seviceList = app.globalData.ppScale.device.setting.find((item) => {
return item.deviceName === res.result[0].type
});
app.globalData.ppScale.plugin.Blue.setDeviceSetting([seviceList]);
app.globalData.ppScale.plugin.Blue.start(res.result[0].type, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
console.log("searchDevice ===> devicesList", res_);
let fIndex = res_.findIndex(item => item.deviceId === res.result[0].deviceId);
if (fIndex >= 0) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
wx.showLoading({
title: "正在连接设备...",
mask: true
});
this.setData({
device: res_[fIndex]
})
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[fIndex]);
}
});
})
},
// 点击设备重连
connectedDevice() {
let device = this.data.device;
if(device) {
wx.showLoading({
title: "正在重新连接设备...",
mask: true
});
app.globalData.ppScale.plugin.Blue.createBLEConnection(device);
}
},
onUnload() {
app.globalData.ppScale.plugin.Blue.stop();
if (this._connectStateWatcher) {
app.unwatch('ppScale.device.connectState', this._connectStateWatcher);
}
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "个人信息",
"disableScroll": true
}
+102
View File
@@ -0,0 +1,102 @@
<view class="userInfo">
<view class="header">
<view>
<view>智能蓝牙秤</view>
<view>型号:{{device.name}}</view>
</view>
<view>
<block wx:if="{{device && 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>
<view>
<view>
<input
type="text"
value="{{realname}}"
bindinput="realnameInput"
placeholder="请输入您的姓名"
class="valueClass"
placeholder-class="placeholderClass" />
</view>
</view>
</view>
<view>
<view>性别</view>
<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>
</view>
<view>
<view>生日</view>
<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>
</view>
<view>
<view>身高</view>
<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>
</view>
<view>
<view>体重</view>
<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>
</view>
</view>
<view class="btn">
<view bind:tap="setUserInfo">完成</view>
</view>
<view class="describe">请认真填写和完善您家人的健康信息,用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。<text>(填写数据同时,踩亮蓝牙秤并与其保持连接)。</text></view>
</view>
</view>
+166
View File
@@ -0,0 +1,166 @@
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;
}
.userInfo {
width: 100%;
height: 100%;
display: flex;
flex-flow: column;
padding: 24rpx 30rpx;
box-sizing: border-box;
}
.header {
width: 100%;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 30rpx 40rpx;
box-sizing: border-box;
border-radius: 16rpx;
margin-bottom: 24rpx;
background-color: #FFFFFF;
}
.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%;
flex: 1;
overflow: hidden;
padding: 0 30rpx;
box-sizing: border-box;
background-color: #FFFFFF;
}
.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: #8363F9;
}
.describe {
color: #77849E;
width: 100%;
font-size: 24rpx;
line-height: 40rpx;
}
.describe text {
color: #F24439;
}
+39 -39
View File
@@ -1,41 +1,41 @@
{ {
"appid": "wx6c71f3ebcdcddffd", "appid": "wxd98be3eccdba8f7f",
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "3.8.5", "libVersion": "3.8.5",
"packOptions": { "packOptions": {
"ignore": [], "ignore": [],
"include": [] "include": []
}, },
"setting": { "setting": {
"coverView": true, "coverView": true,
"es6": true, "es6": true,
"postcss": true, "postcss": true,
"minified": true, "minified": true,
"enhance": true, "enhance": true,
"showShadowRootInWxmlPanel": true, "showShadowRootInWxmlPanel": true,
"packNpmRelationList": [], "packNpmRelationList": [],
"babelSetting": { "babelSetting": {
"ignore": [], "ignore": [],
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"compileWorklet": false, "compileWorklet": false,
"uglifyFileName": false, "uglifyFileName": false,
"uploadWithSourceMap": true, "uploadWithSourceMap": true,
"packNpmManually": false, "packNpmManually": false,
"minifyWXSS": true, "minifyWXSS": true,
"minifyWXML": true, "minifyWXML": true,
"localPlugins": false, "localPlugins": false,
"disableUseStrict": false, "disableUseStrict": false,
"useCompilerPlugins": false, "useCompilerPlugins": false,
"condition": false, "condition": false,
"swc": false, "swc": false,
"disableSWC": true "disableSWC": true
}, },
"condition": {}, "condition": {},
"editorSetting": { "editorSetting": {
"tabIndent": "tab", "tabIndent": "tab",
"tabSize": 4 "tabSize": 4
}, },
"simulatorPluginLibVersion": {} "simulatorPluginLibVersion": {}
} }
+1 -1
View File
@@ -19,6 +19,6 @@
"checkInvalidKey": true, "checkInvalidKey": true,
"ignoreDevUnusedFiles": true "ignoreDevUnusedFiles": true
}, },
"libVersion": "3.14.2", "libVersion": "3.8.6",
"condition": {} "condition": {}
} }
+2 -2
View File
@@ -20,7 +20,7 @@ const hideLoading = () => {
} }
} }
const ajax = (url, params, methos, loading = true, title = "加载中...", contentType = "application/json") => { const ajax = (url, params, methos, loading = true, title = "加载中...") => {
let requestUrl = app.globalData.wxRequestUrl + url; let requestUrl = app.globalData.wxRequestUrl + url;
if (loading) { if (loading) {
showLoading(title); showLoading(title);
@@ -28,7 +28,7 @@ const ajax = (url, params, methos, loading = true, title = "加载中...", conte
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let header = { let header = {
"content-type": contentType "content-type": "application/json"
}; };
let token = wx.getStorageSync("token"); let token = wx.getStorageSync("token");