import HttpRequest from '@/common/httpRequest' /** * 处理微信登录 */ export function wxLogin(callback) { uni.showLoading({ title: '登录中' }) uni.login({ provider: 'weixin', success: (wxRes) => { setData('openId', wxRes.authResult.openid) 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) { setData("userId", res.user.userId) setData("token", res.token) setData("phone", res.user.phone) setData("userName", res.user.userName) setData("avatar", res.user.avatar) setData("invitationCode", res.user.invitationCode) setData("inviterCode", res.user.inviterCode) getIsVip() uni.hideLoading() if (res.user.userType) { 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) { setData("isVip", res.data); } }); } /** * 会员登录到期提醒 */ export function membershipExpirationReminder(data) { if (data?.daysLeft) { setTimeout(() => { uni.showModal({ title: '会员到期提醒', content: data.remind }) }, 1000) } } /** * 获取极光推送相关登录信息 */ export function getJPLoginParams() { // 极光推送SDK初始化注册ID let registrationId = getData('registerID') || '' // 设备类型:0 安卓、1 iOS、2 鸿蒙 let deviceType = 0 if (uni.getSystemInfoSync().platform == "ios") { deviceType = 1 } return { registrationId, deviceType } } /** * 退出登录,断开极光推送连接 */ export function logoutJP(callback) { // 退出登录,断开极光推送连接 // #ifdef APP-PLUS HttpRequest .getT('/app/Login/out') .then(res => { console.log('退出登录成功', res) }) .finally(() => { callback && callback() }) // #endif // #ifndef APP-PLUS callback && callback() // #endif } function setData(key, value) { try { uni.setStorageSync(key, value); } catch (e) { console.log(e) } } function getData(key) { try { const value = uni.getStorageSync(key); if (value) { return value; } } catch (e) { console.log(e) } }