优化业主端和商城端鉴权

This commit is contained in:
java110 2021-06-04 12:09:22 +08:00
parent 9a4e9525a9
commit 88cfbe1436
5 changed files with 102 additions and 36 deletions

71
api/webView/webViewApi.js Normal file
View File

@ -0,0 +1,71 @@
import {
request
} from '../java110Request.js'
import
url
from '../../constant/url.js'
import
mapping
from '../../constant/MappingConstant.js'
import {
formatDate,
dateTimeStringToDateString
} from '../../utils/DateUtil.js'
const ACTION_NAVIGATE_TO = "navigateTo"; // 跳转
const ACTION_REFRESH_TOKEN = "refreshToken";
/**
* 检查回话
*/
export function checkSession(that,url){
checkSession().then(function() {
//申请会话
}, function(error) { //回话过期
// #ifdef H5
//先微信登录
wechatRefreshToken();
// #endif
//小程序登录
// #ifdef MP-WEIXIN
doLogin();
// #endif
// #ifdef APP-PLUS
//查询临时钥匙
let _key = wx.getStorageSync(mapping.OWNER_KEY);
if (_key) {
doLoginOwnerByKey(_key);
} else {
uni.navigateTo({
url: '/pages/showlogin/showlogin?wAppId=' + getWAppId()
});
return;
}
// #endif
});
}
/**
* @param {Object} event事件
*/
export function reciveMessage(event,that) {
console.log('商城回传的参数', event);
let _data = event.data;
console.log('_data', _data)
if (_data.action == ACTION_NAVIGATE_TO) {
uni.navigateTo({
url: '/pages/hcWebView/hcWebView?url=' + _data.url
});
return;
} else if (_data.action == ACTION_REFRESH_TOKEN) {
//校验是否登录,如果没有登录跳转至温馨提示页面
checkSession(that,_data.url);
}
}

View File

@ -15,7 +15,9 @@ const baseUrl = '/';
const commonBaseUrl = 'https://hc.demo.winqi.cn/'; const commonBaseUrl = 'https://hc.demo.winqi.cn/';
//商城的url //商城的url
const mallUrl = 'http://mallapp.homecommunity.cn/#/?hcCommunityId=7020181217000001&hcCode=123456789'; const mallUrl = 'http://mallapp.homecommunity.cn/';
const mallUrlIndexPage = mallUrl+'#/?hcCommunityId=7020181217000001&hcCode=123456789&mallFrom=HC';
// #ifndef H5 // #ifndef H5
//服务器域名 小程序 或者 app 时 后端地址 //服务器域名 小程序 或者 app 时 后端地址
@ -37,6 +39,7 @@ const logLevel="DEBUG"; // 日志级别
export default{ export default{
baseUrl:baseUrl, baseUrl:baseUrl,
mallUrl:mallUrl, mallUrl:mallUrl,
mallUrlIndexPage:mallUrlIndexPage,
commonBaseUrl: commonBaseUrl, commonBaseUrl: commonBaseUrl,
DEFAULT_COMMUNITY_ID:DEFAULT_COMMUNITY_ID, DEFAULT_COMMUNITY_ID:DEFAULT_COMMUNITY_ID,
DEFAULT_COMMUNITY_NAME:DEFAULT_COMMUNITY_NAME, DEFAULT_COMMUNITY_NAME:DEFAULT_COMMUNITY_NAME,

View File

@ -354,7 +354,8 @@
,{ ,{
"path" : "pages/mall/mall", "path" : "pages/mall/mall",
"style" : { "style" : {
"navigationBarTitleText": "商圈" "navigationBarTitleText": "商圈",
"navigationStyle":"custom"
} }
} }
, ,
@ -514,7 +515,8 @@
"style" : "style" :
{ {
"navigationBarTitleText": "", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false,
"navigationStyle":"custom"
} }
} }

View File

@ -12,9 +12,18 @@
url: '' url: ''
} }
}, },
mounted() {
// #ifdef H5
window.addEventListener("message", this.reciveMessage);
// #endif
},
onLoad(options) { onLoad(options) {
this.url = options.url; let _url = options.url;
this.url = conf.mallUrl + '#' + _url;
console.log('_hcUrl',this.url);
}, },
methods: { methods: {
reciveMessage: function(event) { reciveMessage: function(event) {

View File

@ -1,11 +1,13 @@
<template> <template>
<view class="h5-html"> <view class="h5-html">
 <web-view ref="webview"    :src="url"  @onPostMessage="reciveMessage"></web-view>  <web-view ref="webview"  :src="url"  @onPostMessage="reciveMessage"></web-view>
</view> </view>
</template> </template>
<script> <script>
import conf from '../../conf/config.js' import conf from '../../conf/config.js'
export default { export default {
data() { data() {
return { return {
@ -17,39 +19,18 @@
window.addEventListener("message",this.reciveMessage); window.addEventListener("message",this.reciveMessage);
// #endif // #endif
}, },
onLoad() { onLoad(options) {
this.url = conf.mallUrl; let _url = options.url;
},
// onReady() {
// var that = this;
// var height = 0; //
// var statusBarHeight = 0;
// uni.getSystemInfo({
// //
// success: (sysinfo) => {
// height = sysinfo.windowHeight - that.$navHeight - sysinfo.statusBarHeight; //
// statusBarHeight = sysinfo.statusBarHeight;
// },
// complete: () => {}
// });
// var pages = getCurrentPages(); if(_url){
// var page = pages[pages.length - 1]; this.url = conf.mallUrl + _url;
}else{
// var currentWebview = page.$getAppWebview(); //webview this.url = conf.mallUrlIndexPage;
}
// setTimeout(function() { },
// var wv = currentWebview.children()[0];
// wv.setStyle({ //web-viewpx
// top: that.$navHeight + statusBarHeight,
// height: height
// })
// }, 500); //
// },
methods: { methods: {
reciveMessage: function(event) { reciveMessage: function(event) {
console.log('商城回传的参数', event);
} }
} }
} }