Compare commits
1 Commits
v1.0.20
...
9ecd6d963b
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ecd6d963b |
@@ -60,6 +60,13 @@
|
|||||||
} catch (_) {
|
} catch (_) {
|
||||||
// state 解析失败,忽略
|
// state 解析失败,忽略
|
||||||
}
|
}
|
||||||
|
// 存入 localStorage,确保 loading 页面复用时也能获取(redirectTo 可能不触发 onLoad)
|
||||||
|
if (action) {
|
||||||
|
localStorage.setItem('__auth_action', action);
|
||||||
|
}
|
||||||
|
if (callbackDeviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', callbackDeviceId);
|
||||||
|
}
|
||||||
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||||
if (action) {
|
if (action) {
|
||||||
loadingUrl += '&action=' + action;
|
loadingUrl += '&action=' + action;
|
||||||
|
|||||||
@@ -36,16 +36,13 @@ export default {
|
|||||||
code = urlParams.get('code') || '';
|
code = urlParams.get('code') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 兜底:从 localStorage 恢复(redirect_uri 参数为主,localStorage 为备用)
|
// 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理)
|
||||||
if (!this.action) {
|
if (!this.action) {
|
||||||
this.action = localStorage.getItem('__auth_action') || '';
|
this.action = localStorage.getItem('__auth_action') || '';
|
||||||
}
|
}
|
||||||
if (!this.deviceId) {
|
if (!this.deviceId) {
|
||||||
this.deviceId = localStorage.getItem('__auth_device_id') || '';
|
this.deviceId = localStorage.getItem('__auth_device_id') || '';
|
||||||
}
|
}
|
||||||
// 清理 localStorage(一次性使用,避免残留影响下次流程)
|
|
||||||
localStorage.removeItem('__auth_action');
|
|
||||||
localStorage.removeItem('__auth_device_id');
|
|
||||||
console.log('[loading] onLoad - action:', this.action, 'deviceId:', this.deviceId, 'code:', code ? 'yes' : 'no');
|
console.log('[loading] onLoad - action:', this.action, 'deviceId:', this.deviceId, 'code:', code ? 'yes' : 'no');
|
||||||
|
|
||||||
if (this.action === 'userinfo') {
|
if (this.action === 'userinfo') {
|
||||||
@@ -87,6 +84,11 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.statusText = '正在获取授权...';
|
this.statusText = '正在获取授权...';
|
||||||
|
|
||||||
|
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
|
if (this.deviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
const redirectUri = config.authRedirectUri || (
|
const redirectUri = config.authRedirectUri || (
|
||||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
@@ -221,6 +223,12 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.statusText = '正在获取用户信息...';
|
this.statusText = '正在获取用户信息...';
|
||||||
|
|
||||||
|
// 存入 localStorage(页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
|
localStorage.setItem('__auth_action', 'userinfo');
|
||||||
|
if (this.deviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
const redirectUri = config.authRedirectUri || (
|
const redirectUri = config.authRedirectUri || (
|
||||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
@@ -317,16 +325,22 @@ export default {
|
|||||||
* 跳回首页并标记为"我的"tab
|
* 跳回首页并标记为"我的"tab
|
||||||
*/
|
*/
|
||||||
goToHomeWithAction() {
|
goToHomeWithAction() {
|
||||||
const url = this.deviceId
|
// 兼容页面复用:优先 this.deviceId,其次 localStorage
|
||||||
? `/pages/index/index?device_id=${this.deviceId}&action=mine`
|
const deviceId = this.deviceId || localStorage.getItem('__auth_device_id') || '';
|
||||||
|
const url = deviceId
|
||||||
|
? `/pages/index/index?device_id=${deviceId}&action=mine`
|
||||||
: '/pages/index/index?action=mine';
|
: '/pages/index/index?action=mine';
|
||||||
|
localStorage.removeItem('__auth_device_id');
|
||||||
|
localStorage.removeItem('__auth_action');
|
||||||
uni.redirectTo({ url });
|
uni.redirectTo({ url });
|
||||||
},
|
},
|
||||||
|
|
||||||
goToHome() {
|
goToHome() {
|
||||||
const url = this.deviceId
|
const deviceId = this.deviceId || localStorage.getItem('__auth_device_id') || '';
|
||||||
? `/pages/index/index?device_id=${this.deviceId}`
|
const url = deviceId
|
||||||
|
? `/pages/index/index?device_id=${deviceId}`
|
||||||
: '/pages/index/index';
|
: '/pages/index/index';
|
||||||
|
localStorage.removeItem('__auth_device_id');
|
||||||
uni.redirectTo({ url });
|
uni.redirectTo({ url });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -325,6 +325,12 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 存入 localStorage(loading 页面复用时 onLoad 不会重新触发,需要从 localStorage 读取)
|
||||||
|
localStorage.setItem('__auth_action', 'userinfo');
|
||||||
|
if (this.deviceId) {
|
||||||
|
localStorage.setItem('__auth_device_id', this.deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
// 回调地址:必须与微信公众号后台注册地址一致,不能带自定义参数
|
||||||
const redirectUri = config.authRedirectUri || (
|
const redirectUri = config.authRedirectUri || (
|
||||||
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
|
|||||||
Reference in New Issue
Block a user