| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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() {
- // 退出登录,断开极光推送连接
- // #ifdef APP-PLUS
- HttpRequest
- .getT('/app/Login/out')
- .then(res => {
- console.log('退出登录成功', res)
- })
- // #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)
- }
- }
|