82 lines
1.9 KiB
JavaScript
82 lines
1.9 KiB
JavaScript
import $ from "../../utils/request";
|
|
|
|
Page({
|
|
data: {
|
|
token: null
|
|
},
|
|
|
|
onShow() {
|
|
let token = wx.getStorageSync("token") || null;
|
|
this.setData({
|
|
token: token
|
|
})
|
|
},
|
|
|
|
openLoginOrReg() {
|
|
if (!this.data.token) {
|
|
this.starLogin().then(() => {
|
|
|
|
}).catch(() => {
|
|
wx.showToast({
|
|
title: "登录失败,请重试!",
|
|
icon: "none"
|
|
})
|
|
})
|
|
}
|
|
},
|
|
|
|
wifiChange() {
|
|
wx.navigateTo({
|
|
url: "/pages/searchDevice/searchDevice"
|
|
})
|
|
},
|
|
|
|
starLogin() {
|
|
return new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success: (res) => {
|
|
if (res.code) {
|
|
let params = {
|
|
code: res.code
|
|
};
|
|
$.ajax("weighingScale/v2/checkOpenIdLogin", params, "POST", true, "登录中...").then((res) => {
|
|
wx.setStorageSync("token", res.result.token);
|
|
this.setData({
|
|
token: res.result.token,
|
|
})
|
|
resolve();
|
|
}).catch((err) => {
|
|
reject();
|
|
})
|
|
} else {
|
|
reject();
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
|
|
// 退出登录
|
|
exitLogin() {
|
|
wx.showModal({
|
|
title: "提示",
|
|
content: "你确定要退出登录吗?",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
$.ajax("weighingScale/logout", {}, "POST", true, "正在退出登录...").then(res => {
|
|
wx.showToast({
|
|
icon: "none",
|
|
title: res.message
|
|
})
|
|
setTimeout(() => {
|
|
wx.clearStorageSync();
|
|
wx.switchTab({
|
|
url: "/pages/home/home"
|
|
})
|
|
}, 1500)
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}) |