From f7504cdaed88bcf35cfff8693321af7d6ded63c7 Mon Sep 17 00:00:00 2001 From: java110 <928255095@qq.com> Date: Wed, 23 Jun 2021 19:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/webView/webViewApi.js | 45 +++++++++------------ constant/MappingConstant.js | 2 + pages/hcWebView/hcWebView.vue | 22 +++++----- pages/hcWebViewRefresh/hcWebViewRefresh.vue | 34 ++++++++++++---- 4 files changed, 59 insertions(+), 44 deletions(-) diff --git a/api/webView/webViewApi.js b/api/webView/webViewApi.js index 7520369..4f89cce 100644 --- a/api/webView/webViewApi.js +++ b/api/webView/webViewApi.js @@ -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; diff --git a/constant/MappingConstant.js b/constant/MappingConstant.js index 9f530ee..f532e7e 100755 --- a/constant/MappingConstant.js +++ b/constant/MappingConstant.js @@ -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"; } diff --git a/pages/hcWebView/hcWebView.vue b/pages/hcWebView/hcWebView.vue index 7ba5f61..87ecf22 100644 --- a/pages/hcWebView/hcWebView.vue +++ b/pages/hcWebView/hcWebView.vue @@ -6,10 +6,16 @@