79 lines
1.7 KiB
JavaScript
79 lines
1.7 KiB
JavaScript
/* login.js */
|
|
import {
|
|
login
|
|
} from "../../utils/api"
|
|
import {
|
|
getbuddyList
|
|
} from "../../utils/api"
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
username: "",
|
|
password: "",
|
|
showError: false,
|
|
canIUseGetUserProfile: false,
|
|
},
|
|
sing(info) {
|
|
console.log(1)
|
|
wx.login({
|
|
success(res) {
|
|
console.log(res)
|
|
login({
|
|
code: res.code,
|
|
nickName: info.nickName,
|
|
avatarUrl: info.avatarUrl,
|
|
}).then((res) => {
|
|
console.log(res)
|
|
wx.setStorageSync('currentUser', res.data);
|
|
getbuddyList().then((res) => {
|
|
console.log(res)
|
|
app.globalData.restapi.setUserList(res.data)
|
|
|
|
})
|
|
// 页面跳转
|
|
wx.switchTab({
|
|
url: '../conversations/conversations'
|
|
});
|
|
})
|
|
}
|
|
})
|
|
},
|
|
loging() {
|
|
let that = this
|
|
wx.getUserProfile({
|
|
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
success: (res) => {
|
|
console.log(res.userInfo)
|
|
that.sing(res.userInfo)
|
|
}
|
|
})
|
|
},
|
|
login: function (info) {
|
|
console.log(info)
|
|
this.sing()
|
|
|
|
// let username = e.detail.value.username;
|
|
// let password = e.detail.value.password;
|
|
// if (username.trim() !== "" && password.trim() !== "") {
|
|
// let user = restapi.findUser(username,password);
|
|
// if (user) {
|
|
// wx.setStorageSync('currentUser',user);
|
|
// // 页面跳转
|
|
// wx.switchTab({
|
|
// url:'../conversations/conversations'
|
|
// });
|
|
// return;
|
|
// }
|
|
// }
|
|
// this.setData({
|
|
// showError:true
|
|
// });
|
|
},
|
|
onLoad() {
|
|
if (wx.getUserProfile) {
|
|
this.setData({
|
|
canIUseGetUserProfile: true
|
|
})
|
|
}
|
|
}
|
|
}) |