gree_leran/utils/userUtils.js

48 lines
903 B
JavaScript
Raw Normal View History

2024-06-20 15:36:19 +00:00
import{mark,bind,unbind,updatePassword} from'@/apis/user.js'
class userUtils{
constructor(){
2024-06-22 14:19:10 +00:00
this.login();
2024-06-20 15:36:19 +00:00
// this.getImage();
}
//获取用户code的同步封装
getCode(){
return new Promise((resolve, reject) => {
uni.login({
success: (res) => {
resolve(res.code);
},
fail: (error) => {
reject(error);
}
});
});
}
/**
* 登录方法存储登录的所有信息
*/
async login(){
//获取code
let code=await this.getCode();
let res=await mark(code);
console.log("结果2",res)
if(res.code==200){
uni.setStorageSync('rds-token',res.msg);
2024-06-22 07:20:39 +00:00
uni.showToast({
icon: "none",
title: "登录成功"
})
2024-06-20 15:36:19 +00:00
}else{
uni.removeStorageSync('rds-token');
2024-06-22 07:20:39 +00:00
uni.showToast({
icon: "none",
title: "登录失败,请检查网络"
})
2024-06-20 15:36:19 +00:00
}
return res;
}
}
export default new userUtils()