import HttpRequest from '@/common/httpRequest' import queue from '@/common/queue' /** * 处理微信登录 */ export function wxLogin(callback) { uni.showLoading({ title: '登录中' }) uni.login({ provider: 'weixin', success: (wxRes) => { queue.setData('openId', wxRes.authResult.openid) queue.setData('unionId', wxRes.authResult.unionId) let data = { wxOpenId: loginRes.authResult.openid, token: loginRes.authResult.access_token } HttpRequest .postT('/app/Login/wxAppLogin', data) .then(res => { uni.hideLoading() if (typeof callback == 'function') { callback(res) } login(res) }) .catch(() => { if (typeof callback == 'function') { callback(false) } uni.hideLoading() }) }, fail: () => { uni.hideLoading() } }) } /** * 正常登录处理 */ export function phoneLogin(params) { uni.showLoading({ title: '登录中' }) HttpRequest .post('/app/Login/registerAndLogin', { phone: params.phone, msg: params.msg, platform: 'app' }) .then(res => { login(res) }) .finally(() => { uni.hideLoading() }) } /** * 处理登录逻辑 */ export function login(res) { if (res.code == 0) { queue.setData("userId", res.user.userId) queue.setData("token", res.token) queue.setData("phone", res.user.phone) queue.setData("userName", res.user.userName) queue.setData("avatar", res.user.avatar) queue.setData("invitationCode", res.user.invitationCode) queue.setData("inviterCode", res.user.inviterCode) getIsVip() uni.hideLoading() if (res.user.userType) { queue.setData("userType", res.user.userType) uni.reLaunch({ url: '/pages/my/index', }) } else { uni.reLaunch({ url: '/pages/my/jobApplicant/guidePage', }) } } else { plus.nativeUI.toast('出错了:', res.msg) } } /** * 获取vip数据 */ function getIsVip() { HttpRequest.get("/app/UserVip/isUserVip").then((res) => { if (res.code == 0) { queue.setData("isVip", res.data); } }); }