| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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);
- }
- });
- }
|