Files
bodyWeight/pages/home/home.js
T
2026-05-11 09:45:03 +08:00

71 lines
1.3 KiB
JavaScript

import $ from "../../utils/request";
Page({
data: {
token: null,
},
onShow() {
let token = wx.getStorageSync("token") || null;
this.setData({
token: token,
// deviceList: []
})
},
// 点击登录或注册
openLoginOrReg(e) {
let bol = e.currentTarget.dataset.bol;
wx.login({
success: (res) => {
if (res.code) {
this.checkOpenIdLogin(res.code, bol);
} else {
wx.showToast({
icon: "none",
title: "登录失败,请稍后再试!",
})
}
}
})
},
// 微信一键登录
checkOpenIdLogin(code, bol) {
let params = {
code: code
};
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "加载中...").then((res) => {
wx.setStorageSync("token", res.result.token);
this.setData({
token: res.result.token
})
if(bol) {
this.openSearchDevice();
}
})
},
// 添加设备
openSearchDevice() {
wx.navigateTo({
url: "/pages/searchDevice/searchDevice"
})
},
// 点击查看帮助
openHelp() {
wx.navigateTo({
url: "/pages/help/help"
})
},
onShareAppMessage() {
return {
title: '智能蓝牙秤',
path: '/pages/home/home',
imageUrl: '/images/share/share.jpg',
}
}
})