You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
zhishifufei_uniapp/libs/routine.js

106 lines
1.8 KiB

import {
routineLogin,
} from '../api/user';
import Cache from '@/utils/cache';
import {
STATE_R_KEY,
} from './../config/cache';
class Routine {
/**
* 新版小程序获取用户信息 2021 4.13微信小程序开始正式启用
*/
getUserProfile(code) {
return new Promise((resolve, reject) => {
uni.getUserProfile({
lang: 'zh_CN',
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success(user) {
if (code) user.code = code;
resolve({
userInfo: user,
islogin: false
});
},
fail(res) {
reject(res);
}
})
})
}
/**
* 获取用户信息
*/
/* authorize() {
let that = this;
return new Promise((resolve, reject) => {
if (checkLogin())
return resolve({
userInfo: Cache.get(USER_INFO, true),
islogin: true,
});
uni.authorize({
scope: that.scopeUserInfo,
success() {
resolve({
islogin: false
});
},
fail(res) {
reject(res);
}
})
})
} */
async getCode() {
let provider = await this.getProvider();
return new Promise((resolve, reject) => {
uni.login({
provider: provider,
success(res) {
if (res.code) Cache.set(STATE_R_KEY, res.code, 10800);
return resolve(res.code);
},
fail() {
return reject(null);
}
})
})
}
/**
* 获取服务供应商
*/
getProvider() {
return new Promise((resolve, reject) => {
uni.getProvider({
service: 'oauth',
success(res) {
resolve(res.provider);
},
fail() {
resolve(false);
}
});
});
}
authUserInfo(data) {
return new Promise((resolve, reject) => {
routineLogin(data).then(res => {
return resolve(res);
}).catch(res => {
return reject(res);
})
})
}
}
export default new Routine();