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

46 lines
1.1 KiB
JavaScript

"use strict";
const common_vendor = require("../common/vendor.js");
const apis_user = require("../apis/user.js");
class userUtils {
constructor() {
this.login();
}
//获取用户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);
common_vendor.index.showToast({
icon: "none",
title: "登录成功"
});
} else {
common_vendor.index.removeStorageSync("rds-token");
common_vendor.index.showToast({
icon: "none",
title: "登录失败,请检查网络"
});
}
return res;
}
}
const utils = new userUtils();
exports.utils = utils;