gree_leran/unpackage/dist/dev/mp-weixin/utils/userUtils.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

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