更换WIFI
This commit is contained in:
+86
-40
@@ -15,13 +15,86 @@ Page({
|
||||
userInfo: userInfo,
|
||||
token: token
|
||||
})
|
||||
if(token && userInfo) {
|
||||
this.getDevice();
|
||||
if(token) {
|
||||
this.getDevice(false);
|
||||
}
|
||||
},
|
||||
|
||||
openLoginOrReg() {
|
||||
if(this.data.userInfo === null && this.data.token === null) {
|
||||
if(this.data.token) {
|
||||
this.openLoginOrReg_();
|
||||
} else {
|
||||
this.starLogin().then(() => {
|
||||
this.getDevice(true);
|
||||
}).catch(() => {
|
||||
wx.showToast({
|
||||
title: "登录失败,请重试!",
|
||||
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"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 打开设备详情
|
||||
openDeviceInfo() {
|
||||
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() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
@@ -35,55 +108,28 @@ Page({
|
||||
token: res.result.token,
|
||||
userInfo: res.result.user
|
||||
})
|
||||
resolve();
|
||||
}).catch((err) => {
|
||||
reject();
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "登录失败,请稍后再试!",
|
||||
})
|
||||
reject();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 打开设备详情
|
||||
openDeviceInfo() {
|
||||
if(this.data.userInfo && this.data.token) {
|
||||
let deviceInfo = this.data.deviceInfo;
|
||||
if(deviceInfo) {
|
||||
wx.navigateTo({
|
||||
url: "/pages/deviceInfo/deviceInfo"
|
||||
})
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: "当前暂未绑定设备,需要绑定吗?",
|
||||
confirmText: "去绑定",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.navigateTo({
|
||||
url: "/pages/searchDevice/searchDevice"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "请先登录"
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 获取已经绑定的设备列表
|
||||
getDevice() {
|
||||
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_();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user