优化代码

This commit is contained in:
java110 2021-06-23 19:28:07 +08:00
parent 3a2da3bf10
commit f7504cdaed
4 changed files with 59 additions and 44 deletions

View File

@ -26,7 +26,13 @@ import {
import conf from '../../conf/config.js'
import {encodeUrl} from '../../utils/UrlUtil.js'
import {isNull} from '../../utils/StringUtil.js'
import {
encodeUrl
} from '../../utils/UrlUtil.js';
import {getStorageSync,setStorageSync} from '../../utils/StorageUtil.js'
const ACTION_NAVIGATE_TO = "navigateTo"; // 跳转
const ACTION_REFRESH_TOKEN = "refreshToken";
@ -64,34 +70,18 @@ export function getHcCode(_objData) {
/**
* 检查回话
*/
export function actionRefreshToken(that, url) {
export function actionRefreshToken(that) {
checkSession().then(function() {
//这部分是 业主端回话有效的情况
console.log('业主端回话有效');
let _url = url;
if(url.indexOf("http") < 0 && url.indexOf("https") < 0){
_url = conf.mallUrl + url;
}
console.log('_url',_url)
if (_url.indexOf("?") > -1) {
_url += "&"
} else {
_url += "?"
}
//申请会话
getHcCode().then(_data => {
_url += ("hcCode=" + _data.hcCode);
_url = encodeUrl(_url);
uni.navigateTo({
url: '/pages/hcWebViewRefresh/hcWebViewRefresh?url=' + _url
});
}, err => {
uni.navigateTo({
url: '/pages/hcWebViewRefresh/hcWebViewRefresh'
});
}, function(error) { //回话过期
console.log('回话已经过期');
wechatRefreshToken();
let _hasOwnerUrl = window.location.origin+'/#/pages/hcWebViewRefresh/hcWebViewRefresh';
let _mallAuthUrl = conf.mallUrl;
wechatRefreshToken(_mallAuthUrl, '0', _hasOwnerUrl);
});
}
@ -176,17 +166,18 @@ export function reciveMessage(event, that) {
console.log('商城回传的参数', event);
let _data = event.data;
if(_data.hasOwnProperty("url") && !isNull(_data.url)){
setStorageSync(mapping.HC_MALL_CUR_URL,_data.url);
}
console.log('_data', _data)
if (_data.action == ACTION_NAVIGATE_TO) {
_data.url = encodeUrl(_data.url);
uni.navigateTo({
url: '/pages/hcWebView/hcWebView?url=' + _data.url
url: '/pages/hcWebView/hcWebView'
});
return;
} else if (_data.action == ACTION_REFRESH_TOKEN) {
//校验是否登录,如果没有登录跳转至温馨提示页面
_data.url = encodeUrl(_data.url);
actionRefreshToken(that, _data.url);
actionRefreshToken(that);
} else if (_data.action == ACTION_NAVIGATE_TO_PAGE) {
//_data.url = encodeUrl(_data.url);
window.location.href = _data.url;

View File

@ -27,6 +27,8 @@ class MappingConstant {
static HC_TEST_COMMUNITY_NAME = conf.DEFAULT_COMMUNITY_NAME;
static W_APP_ID = "wAppId";//微信公众号ID
static HC_MALL_CUR_URL = "HC_MALL_CUR_URL";
}

View File

@ -6,10 +6,16 @@
<script>
import conf from '../../conf/config.js'
import {decodeUrl} from '../../utils/UrlUtil.js'
import {
decodeUrl
} from '../../utils/UrlUtil.js'
import {
reciveMessage
} from '../../api/webView/webViewApi.js'
import {
isNull
} from '../../utils/StringUtil.js'
export default {
data() {
return {
@ -23,15 +29,13 @@
},
onLoad(options) {
let _url = options.url;
_url = decodeUrl(_url);
if(_url.indexOf("http")>-1){
this.url = _url;
}else{
this.url = conf.mallUrl + '#' + _url;
if (isNull(_url)) {
_url = getStorageSync(mapping.HC_MALL_CUR_URL);
}
console.log('_hcUrl',this.url);
if (_url.indexOf("http") < 0 && _url.indexOf("https") < 0) {
_url = conf.mallUrl + '#' + _url;
}
this.url = _url;
},
methods: {
reciveMessage: function(event) {

View File

@ -7,14 +7,23 @@
<script>
import conf from '../../conf/config.js'
import {
reciveMessage
reciveMessage,
getHcCode
} from '../../api/webView/webViewApi.js'
import {decodeUrl} from '../../utils/UrlUtil.js'
import {
isNotNull
} from '../../utils/StringUtil.js'
import {
decodeUrl,
encodeUrl
} from '../../utils/UrlUtil.js'
const context = require("../../context/Java110Context.js");
export default {
data() {
return {
url: ''
url: '',
}
},
mounted() {
@ -23,15 +32,24 @@
// #endif
},
onLoad(options) {
let _url = options.url;
//_url = decodeUrl(_url);
this.url = conf.mallUrlRefresh + "&url=" + _url;
let _key = options.key;
if (isNotNull(_key)) {
context.onLoad(options, this._getHcCode);
} else {
this._getHcCode()
}
},
methods: {
onReciveMessage: function(event) {
console.log('商城回传的参数', event);
reciveMessage(event);
},
_getHcCode: function() {
getHcCode().then(_data => {
this.url = conf.mallUrlRefresh + "?hcCode=" + _data.hcCode;
}, err => {
});
}
}
}