mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-23 21:36:38 +08:00
优化代码
This commit is contained in:
parent
89d90be40a
commit
0721ef6402
@ -15,14 +15,44 @@ import {
|
|||||||
|
|
||||||
import url from '../../../constant/url.js'
|
import url from '../../../constant/url.js'
|
||||||
|
|
||||||
|
import {addMinutes} from "../utils/DateUtil.js"
|
||||||
|
|
||||||
export function pageOnLoad(options) {
|
export function pageOnLoad(options) {
|
||||||
let _key = options.key;
|
let _key = options.key;
|
||||||
if (isNotNull(_key)) {
|
if (isNotNull(_key)) {
|
||||||
//根据key 去做登录
|
//根据key 去做登录
|
||||||
doLoginOwnerByKey(_key, callback);
|
doLoginOwnerByKey(_key, function(){
|
||||||
|
// 可能存在 页面初始化等一些问题 这里删除连接中的key 然后刷新页面
|
||||||
|
window.location.href = window.location.href.replace('key=','_keySuccess=')
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageWAppId()
|
getPageWAppId(options);
|
||||||
|
|
||||||
|
if (isNull(_key)) {
|
||||||
|
onLoadHasAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onLoadHasAuth(){
|
||||||
|
let _url = window.location.href;
|
||||||
|
// if(_url.indexOf('hasLoaded')>-1){
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// _url = _url.indexOf("?")> -1 ?(_url+"&hasLoaded=ON"):(_url+"?hasLoaded=ON")
|
||||||
|
|
||||||
|
let _hasLoadedObj = uni.getStorageSync("_hasLoadedObj");
|
||||||
|
|
||||||
|
let nowDate = new Date();
|
||||||
|
if (_hasLoadedObj && _hasLoadedObj.expireTime > nowDate.getTime()) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
uni.setStorageSync("_hasLoadedObj",{
|
||||||
|
expireTime:addMinutes(new Date(),15).getTime()
|
||||||
|
});
|
||||||
|
doPageCheckSession(_url,_url,function(){});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +71,7 @@ export function doLoginOwnerByKey(_key, callback = () => {}) {
|
|||||||
let _param = res.data;
|
let _param = res.data;
|
||||||
if (_param.code != 0) {
|
if (_param.code != 0) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/showlogin/showlogin?wAppId=' + getPageWAppId()
|
url: '/pages/showlogin/showlogin?wAppId=' + getWAppId()
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -53,14 +83,19 @@ export function doLoginOwnerByKey(_key, callback = () => {}) {
|
|||||||
fail: function(error) {
|
fail: function(error) {
|
||||||
// 调用服务端登录接口失败
|
// 调用服务端登录接口失败
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/showlogin/showlogin?wAppId=' + getPageWAppId()
|
url: '/pages/showlogin/showlogin?wAppId=' + getWAppId()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPageWAppId() {
|
export function getPageWAppId(options) {
|
||||||
let wAppId = getWAppId();
|
let wAppId = options.wAppId;
|
||||||
|
if (!isNull(wAppId)) {
|
||||||
|
saveWAppId(wAppId)
|
||||||
|
return wAppId;
|
||||||
|
}
|
||||||
|
wAppId = getWAppId();
|
||||||
if (isNull(wAppId)) {
|
if (isNull(wAppId)) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
@ -76,14 +111,25 @@ export function getPageWAppId() {
|
|||||||
* 页面 session
|
* 页面 session
|
||||||
* @param {Object} _call 回调函数
|
* @param {Object} _call 回调函数
|
||||||
*/
|
*/
|
||||||
export function pageCheckSession(_pageUrl,_call) {
|
export function doPageCheckSession(errorUrl,_pageUrl,_call) {
|
||||||
let loginFlag = getLoginFlag();
|
let loginFlag = getLoginFlag();
|
||||||
let nowDate = new Date();
|
let nowDate = new Date();
|
||||||
if (loginFlag && loginFlag.expireTime > nowDate.getTime()) {
|
if (loginFlag && loginFlag.expireTime > nowDate.getTime()) {
|
||||||
_call();
|
_call();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wechatRefreshToken('', 0, location.origin+'/#'+_pageUrl);
|
if(_pageUrl){
|
||||||
|
wechatRefreshToken(errorUrl, 0, location.origin+'/#'+_pageUrl);
|
||||||
|
}else{
|
||||||
|
wechatRefreshToken(errorUrl, 0, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 页面 session
|
||||||
|
* @param {Object} _call 回调函数
|
||||||
|
*/
|
||||||
|
export function pageCheckSession(_pageUrl,_call) {
|
||||||
|
doPageCheckSession('',_pageUrl,_call)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wechatRefreshToken(errorUrl, _login, _redirectUrl) {
|
export function wechatRefreshToken(errorUrl, _login, _redirectUrl) {
|
||||||
@ -171,8 +217,10 @@ export function getPageLoginCode(options) {
|
|||||||
let code = options.code;
|
let code = options.code;
|
||||||
if (code == '' || code == undefined) {
|
if (code == '' || code == undefined) {
|
||||||
//跳转鉴权 //1标识登录页面 请下发code 不要下发key
|
//跳转鉴权 //1标识登录页面 请下发code 不要下发key
|
||||||
wechatRefreshToken('', 1, window.location.href);
|
wechatRefreshToken(window.location.href, 1, window.location.href);
|
||||||
}
|
}
|
||||||
resolve(code);
|
resolve(code);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user