[bug]解决新用户扫描海报二维码,重新登录后未回显的问题
This commit is contained in:
@ -13,23 +13,25 @@ import {
|
|||||||
} from "@/utils";
|
} from "@/utils";
|
||||||
|
|
||||||
export default function toLogin(push, backUrl) {
|
export default function toLogin(push, backUrl) {
|
||||||
// console.log('需要重新登录')
|
console.log('token失效,需要重新登录')
|
||||||
store.commit("LOGOUT");
|
store.commit("LOGOUT");
|
||||||
// 如果没有授权,走登录的接口重新授权
|
// 如果没有授权,走登录的接口重新授权
|
||||||
// 授权获取失败会跳转到授权的接口
|
// 授权获取失败会跳转到授权的接口
|
||||||
// console.log(store.getters.isAuthorization, '是否有登陆权限')
|
console.log(store.getters.isAuthorization, '是否有登陆权限')
|
||||||
if (store.getters.isAuthorization) {
|
if (store.getters.isAuthorization) {
|
||||||
login()
|
login()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// console.log(store.getters.isAuthorizationPage, '判断是不是登录页面或者授权页面')
|
console.log(store.getters.isAuthorizationPage, '判断是不是登录页面或者授权页面')
|
||||||
// 判断当前是不是已经在登录页面或者授权页,防止二次跳转
|
// 判断当前是不是已经在登录页面或者授权页,防止二次跳转
|
||||||
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') {
|
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') {
|
||||||
|
console.log('已经是登录页面或者授权页面,跳出方法')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是不是扫描的砍价海报进来的
|
// 判断是不是扫描的砍价海报进来的
|
||||||
if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) {
|
if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) {
|
||||||
|
console.log('是扫描的砍价海报进来的')
|
||||||
let url = handleQrCode();
|
let url = handleQrCode();
|
||||||
if (url) {
|
if (url) {
|
||||||
replaceLogin({
|
replaceLogin({
|
||||||
@ -38,9 +40,11 @@ export default function toLogin(push, backUrl) {
|
|||||||
partake: url.uid
|
partake: url.uid
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
console.log('是扫描的砍价海报进来的,但是没有获取到参数')
|
||||||
replaceLogin()
|
replaceLogin()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.log('无特殊情况,重新登录')
|
||||||
replaceLogin()
|
replaceLogin()
|
||||||
}
|
}
|
||||||
store.commit("UPDATE_AUTHORIZATION", false);
|
store.commit("UPDATE_AUTHORIZATION", false);
|
||||||
|
@ -112,22 +112,21 @@ export const copyClipboard = (data) => {
|
|||||||
|
|
||||||
export const replaceLogin = (msg) => {
|
export const replaceLogin = (msg) => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
if (msg) {
|
console.log('尝试开始重新登录')
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '重新登录中...',
|
title: '重新登录中...',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
duration: 2000
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
|
||||||
// 这里代表已经失去登录状态以及401强制推出登录了
|
// 这里代表已经失去登录状态以及401强制推出登录了
|
||||||
store.commit('LOGOUT')
|
store.commit('LOGOUT')
|
||||||
console.log('如果是微信小程序,跳转到授权页', Vue.prototype.$deviceType, msg)
|
|
||||||
if (Vue.prototype.$deviceType == 'routine') {
|
if (Vue.prototype.$deviceType == 'routine') {
|
||||||
|
console.log('当前是微信小程序,开始调用登录方法')
|
||||||
// 如果是微信小程序,跳转到授权页
|
// 如果是微信小程序,跳转到授权页
|
||||||
login({
|
login({
|
||||||
fail: () => {
|
fail: () => {
|
||||||
console.log('如果是微信小程序,跳转到授权页')
|
console.log('自动登录失败,重定向授权页面')
|
||||||
replace({
|
reLaunch({
|
||||||
path: '/pages/authorization/index',
|
path: '/pages/authorization/index',
|
||||||
query: {
|
query: {
|
||||||
redirect: `/${getCurrentPageUrl()}`,
|
redirect: `/${getCurrentPageUrl()}`,
|
||||||
@ -139,6 +138,7 @@ export const replaceLogin = (msg) => {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 如果不是小程序跳转到登录页
|
// 如果不是小程序跳转到登录页
|
||||||
|
console.log('当前是app,跳转到登录页面')
|
||||||
push({
|
push({
|
||||||
path: '/pages/user/Login/index',
|
path: '/pages/user/Login/index',
|
||||||
query: {
|
query: {
|
||||||
@ -178,6 +178,8 @@ export const authorize = (authorizeStr) => {
|
|||||||
resolve('获取授权成功')
|
resolve('获取授权成功')
|
||||||
},
|
},
|
||||||
fail() {
|
fail() {
|
||||||
|
|
||||||
|
console.log('授权失败跳转首页')
|
||||||
switchTab({
|
switchTab({
|
||||||
path: '/pages/home/index',
|
path: '/pages/home/index',
|
||||||
// query
|
// query
|
||||||
@ -191,19 +193,28 @@ export const authorize = (authorizeStr) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const login = (option) => {
|
export const login = (option) => {
|
||||||
|
console.log('开始登录 ————————————————————')
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log('获取环境商')
|
||||||
getProvider().then(provider => {
|
getProvider().then(provider => {
|
||||||
// 调用登录接口
|
// 调用登录接口
|
||||||
|
console.log('调用登录接口')
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: provider,
|
provider: provider,
|
||||||
success: function (loginRes) {
|
success: function (loginRes) {
|
||||||
// 微信登录
|
// 微信登录
|
||||||
|
console.log('登录接口调用成功')
|
||||||
|
console.log('开始检查用户信息授权')
|
||||||
let code = loginRes.code;
|
let code = loginRes.code;
|
||||||
// 检查授权, 检查用户信息授权
|
// 检查授权, 检查用户信息授权
|
||||||
authorize('userInfo').then(() => {
|
authorize('userInfo').then(() => {
|
||||||
|
console.log('授权通过')
|
||||||
|
console.log('开始获取用户信息')
|
||||||
uni.getUserInfo({
|
uni.getUserInfo({
|
||||||
provider: provider,
|
provider: provider,
|
||||||
success: function (user) {
|
success: function (user) {
|
||||||
|
console.log('获取用户信息成功')
|
||||||
|
console.log('开始调用登录接口')
|
||||||
if (Vue.prototype.$deviceType == 'routine') {
|
if (Vue.prototype.$deviceType == 'routine') {
|
||||||
wxappAuth({
|
wxappAuth({
|
||||||
encryptedData: user.encryptedData,
|
encryptedData: user.encryptedData,
|
||||||
@ -213,14 +224,16 @@ export const login = (option) => {
|
|||||||
}).then(({
|
}).then(({
|
||||||
data
|
data
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log('登录接口调用成功')
|
||||||
|
console.log('开始处理登录信息保存,并获取用户详情')
|
||||||
resolve(data)
|
resolve(data)
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
store.commit("LOGIN", data.token, dayjs(data.expires_time));
|
store.commit("LOGIN", data.token, dayjs(data.expires_time));
|
||||||
store.dispatch('USERINFO', true)
|
store.dispatch('USERINFO', true)
|
||||||
console.log(store)
|
console.log(store)
|
||||||
handleGetUserInfo()
|
handleGetUserInfo()
|
||||||
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
console.log('登录接口调用失败')
|
||||||
reject()
|
reject()
|
||||||
console.log(error)
|
console.log(error)
|
||||||
handleFail(option, '微信登录失败')
|
handleFail(option, '微信登录失败')
|
||||||
@ -228,29 +241,34 @@ export const login = (option) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail() {
|
fail() {
|
||||||
|
console.log('获取用户信息失败')
|
||||||
// 获取用户信息失败
|
// 获取用户信息失败
|
||||||
reject()
|
reject()
|
||||||
handleFail(option, '获取用户信息失败')
|
handleFail(option, '获取用户信息失败')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
console.log('用户未授权')
|
||||||
reject()
|
reject()
|
||||||
console.log(error)
|
console.log(error)
|
||||||
handleFail(option, '拒绝授权')
|
handleFail(option, '用户未授权')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail() {
|
fail() {
|
||||||
|
console.log('调用登录接口失败')
|
||||||
// 调用登录接口失败
|
// 调用登录接口失败
|
||||||
reject()
|
reject()
|
||||||
handleFail(option, '登录失败')
|
handleFail(option, '登录失败')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
handleFail(option, '获取环境服务商失败')
|
||||||
reject()
|
reject()
|
||||||
console.log(error)
|
console.log(error)
|
||||||
handleFail(option, '获取环境服务商失败')
|
handleFail(option, '获取环境服务商失败')
|
||||||
})
|
})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
handleFail(option, '登录失败')
|
||||||
console.log(error)
|
console.log(error)
|
||||||
handleFail(option, '登录失败')
|
handleFail(option, '登录失败')
|
||||||
})
|
})
|
||||||
@ -265,25 +283,29 @@ export const handleGetUserInfo = () => {
|
|||||||
var currentPage = pages[pages.length - 1] //获取当前页面的对象
|
var currentPage = pages[pages.length - 1] //获取当前页面的对象
|
||||||
let url = "/pages/home/index"
|
let url = "/pages/home/index"
|
||||||
let query = {}
|
let query = {}
|
||||||
console.log('currentPage')
|
|
||||||
if (currentPage) {
|
if (currentPage) {
|
||||||
|
const {
|
||||||
|
redirect,
|
||||||
|
...querys
|
||||||
|
} = currentPage.options
|
||||||
// 获取到最后一个页面
|
// 获取到最后一个页面
|
||||||
if (
|
if (
|
||||||
currentPage.route != 'pages/Loading/index' &&
|
currentPage.route != 'pages/Loading/index' &&
|
||||||
currentPage.route != 'pages/user/Login/index'
|
currentPage.route != 'pages/user/Login/index'
|
||||||
) {
|
) {
|
||||||
url = currentPage.route
|
url = currentPage.route
|
||||||
|
query = {
|
||||||
|
...querys
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (currentPage.route == 'pages/authorization/index') {
|
if (currentPage.route == 'pages/authorization/index') {
|
||||||
const {
|
|
||||||
redirect,
|
|
||||||
...querys
|
|
||||||
} = currentPage.options
|
|
||||||
url = redirect
|
url = redirect
|
||||||
query = {
|
query = {
|
||||||
...querys
|
...querys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log(url)
|
console.log(url)
|
||||||
if (url == '/pages/home/index' || url == '/pages/shop/GoodsClass/index' || url == '/pages/shop/ShoppingCart/index' || url == '/pages/user/User/index') {
|
if (url == '/pages/home/index' || url == '/pages/shop/GoodsClass/index' || url == '/pages/shop/ShoppingCart/index' || url == '/pages/user/User/index') {
|
||||||
@ -292,10 +314,27 @@ export const handleGetUserInfo = () => {
|
|||||||
query
|
query
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
switchTab({
|
console.log('获取用户信息后跳转回显的页面')
|
||||||
|
// 为了防止返回上一页是授权页面,先重定向到首页,再跳转
|
||||||
|
console.log({
|
||||||
|
path: `/${url}`,
|
||||||
|
query
|
||||||
|
})
|
||||||
|
reLaunch({
|
||||||
path: '/pages/home/index',
|
path: '/pages/home/index',
|
||||||
// query
|
// query
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (url.indexOf('/') == 0) {
|
||||||
|
url = url.slice(1)
|
||||||
|
}
|
||||||
|
push({
|
||||||
|
path: `/${url}`,
|
||||||
|
query
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// push({
|
// push({
|
||||||
// path: `${url}`,
|
// path: `${url}`,
|
||||||
// query
|
// query
|
||||||
@ -307,7 +346,6 @@ export const handleGetUserInfo = () => {
|
|||||||
|
|
||||||
const handleFail = (option, msg) => {
|
const handleFail = (option, msg) => {
|
||||||
// 此处是处理登录失效的问题的
|
// 此处是处理登录失效的问题的
|
||||||
console.log(store)
|
|
||||||
option && option.fail ? option.fail() : replaceLogin('登录失败,请重新登录')
|
option && option.fail ? option.fail() : replaceLogin('登录失败,请重新登录')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +467,7 @@ export function push(location, complete, fail, success) {
|
|||||||
|
|
||||||
export function replace(location, complete, fail, success) {
|
export function replace(location, complete, fail, success) {
|
||||||
handleLoginStatus(location, complete, fail, success).then(params => {
|
handleLoginStatus(location, complete, fail, success).then(params => {
|
||||||
|
console.log(params)
|
||||||
uni.redirectTo(params)
|
uni.redirectTo(params)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// 没有权限
|
// 没有权限
|
||||||
@ -436,6 +475,16 @@ export function replace(location, complete, fail, success) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reLaunch(location, complete, fail, success) {
|
||||||
|
handleLoginStatus(location, complete, fail, success).then(params => {
|
||||||
|
console.log(params)
|
||||||
|
uni.reLaunch(params)
|
||||||
|
}).catch(error => {
|
||||||
|
// 没有权限
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function go(delta) {
|
export function go(delta) {
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
delta
|
delta
|
||||||
|
@ -10,12 +10,11 @@ fly.config.baseURL = VUE_APP_API_URL
|
|||||||
|
|
||||||
fly.interceptors.response.use(
|
fly.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
console.log(response)
|
// console.log(response)
|
||||||
// 定时刷新access-token
|
// 定时刷新access-token
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error)
|
|
||||||
if (error.toString() == 'Error: Network Error') {
|
if (error.toString() == 'Error: Network Error') {
|
||||||
toLogin();
|
toLogin();
|
||||||
return Promise.reject({ msg: "未登录", toLogin: true });
|
return Promise.reject({ msg: "未登录", toLogin: true });
|
||||||
|
Reference in New Issue
Block a user