import $ from "../../utils/request"; Page({ data: { token: null, userInfo: null, deviceList: [] }, onShow() { let userInfo = wx.getStorageSync("userInfo") || null; let token = wx.getStorageSync("token") || null; this.setData({ token: token, userInfo: userInfo, deviceList: [] }) if(token) { this.getDevice(); } }, // 点击登录或注册 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/checkOpenIdLogin", params, "POST", true, "加载中...").then((res) => { wx.setStorageSync("userInfo", res.result.user); wx.setStorageSync("token", res.result.token); this.setData({ token: res.result.token, userInfo: res.result.user }) if(bol) { this.openSearchDevice(); } }) }, // 获取已经绑定的设备列表 getDevice() { let params = {}; $.ajax("weighingScale/list/device", params, "GET", true, "获取设备列表").then((res) => { this.setData({ deviceList: res.result }) }) }, // 添加设备 openSearchDevice() { wx.navigateTo({ url: "/pages/searchDevice/searchDevice" }) }, // 打开设备详情 openDeviceInfo() { wx.navigateTo({ url: "/pages/deviceInfo/deviceInfo" }) } })