From e3cfbd5d81c59ca884592e62b70edeab8551f41f Mon Sep 17 00:00:00 2001 From: clark-t Date: Fri, 9 Aug 2019 11:25:16 +0800 Subject: [PATCH] =?UTF-8?q?8.09=20=E7=B4=A7=E6=80=A5=E4=B8=8A=E7=BA=BF?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20a=20=E9=93=BE=E9=94=9A=E7=82=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 单页跳转透传 hash * add cambrian logo and title * add cambrian logo and title * fixed: 修复 iOS 百度 APP 下的页面无法滚动的问题 * [feat] MIP 交互机制升级 (#656) * add parser * 添加全局行为 * 增加 event 语法规则 * 添加 navigateTo,fix code * rewrite mip event * finish mip event parse * add visitor * update * add arrow * fix property & callexpression bug * 整合全局方法 * fix callexpression bug * 调整代码 * update code * fix objectexpression bug * update whitelist * update test case * add test case * modify test case * add DOM * 修复 Identifier bug * 修复 Identifier bug * add mip-action * update code * add argument scope * 修改路径 * update path * 打通 action 数据传递 * fix mdata bug * fix element action bug * 增加兼容逻辑 * 重写 mip-bind 方法 * update code * add setData parse fallback * update bindStyle * update bindStyle * update bindStyle * 增加 watch * 增加 input 的双向绑定 * 删除无用文件 * 修改 mip-bin 入口 * update code * 拆分 bind.js * 拆分 mip-bind/bind.js * add input global event * update event action spec * 修复 style binding * remove only * update input global event and toggleVisibility * 去除 mip-shell/render.js 调用 MIP. 的逻辑 * change lexer from class to function * add test page * 优化 lexer 机制 * 修改 lexer 策略 * update test page * update unit test * 补 testcase * 补全 testcase * 修改 ArrayLiteral 对最后一个 comma 的处理 * 增加测试描述 * add unit test * add complex function testcase * fix scrollTO hidden element * fix can not find mip1 custom element action * 修复 setData 接收 Vue 响应式对象时疯狂报错的问题 * fix isObject * 修复 mip-bind 覆盖 MIP.setData 的bug * 修复 lgtm 所提示的循环中使用 splice 的问题 * fix lgtm alerts * 修复 bind & vnavigateTo 在 IOS8 下面无法正常工作的兼容性 bug * 移除 mip-img popup 对 loaded 的筛选 (#668) * 移除 mip-img popup 对 loaded 的筛选 * fix: hash 锚点追加的问题&pc 页面空白问题&添加百度 APP iOS 通信功能 * fix: hash 锚点追加的问题&pc 页面空白问题&添加百度 APP iOS 通信功能 * fix: hash 锚点追加的问题&pc 页面空白问题&添加百度 APP iOS 通信功能 * fix: hash 锚点追加的问题&pc 页面空白问题&添加百度 APP iOS 通信功能 --- packages/mip/src/styles/mip-page.less | 23 ++++++----- packages/mip/src/viewer.js | 59 ++++++++++++++++++++------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/packages/mip/src/styles/mip-page.less b/packages/mip/src/styles/mip-page.less index 485e1611..073931e5 100644 --- a/packages/mip/src/styles/mip-page.less +++ b/packages/mip/src/styles/mip-page.less @@ -1,15 +1,18 @@ @import "./variable.less"; -body::before { - display: block; - content: ''; - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - background: #fff; - z-index: 99999; +// PC 环境下快照不会引入 mip.js,导致 body 的这层白色的 mask 消失不了 +@media (max-width: 768px) { + body::before { + display: block; + content: ''; + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: #fff; + z-index: 99999; + } } body::after, diff --git a/packages/mip/src/viewer.js b/packages/mip/src/viewer.js index 0f6d2150..6108e778 100644 --- a/packages/mip/src/viewer.js +++ b/packages/mip/src/viewer.js @@ -159,7 +159,7 @@ let viewer = { */ sendMessageToBaiduApp (eventName, data = {}) { // 和端通信, 可以上报性能数据,也可以通知隐藏 loading - if (platform.isBaiduApp() && platform.isAndroid()) { + if (platform.isBaiduApp()) { let act = { [OUTER_MESSAGE_MIP_PAGE_LOAD]: 'hideloading', [OUTER_MESSAGE_PERFORMANCE_UPDATE]: 'perf', @@ -167,15 +167,25 @@ let viewer = { [OUTER_MESSAGE_REPLACE_STATE]: 'click' }[eventName] - act && window._flyflowNative && window._flyflowNative.exec( - 'bd_mip', - 'onMessage', - JSON.stringify({ - type: 5, // 必选,和端的约定 - act, - data - }), '' - ) + if (platform.isAndroid()) { + act && window._flyflowNative && window._flyflowNative.exec( + 'bd_mip', + 'onMessage', + JSON.stringify({ + type: 5, // 必选,和 android 端的约定 + act, + data + }), '' + ) + } + if (platform.isIOS()) { + let iframe = document.createElement('iframe'); + let paramStr = encodeURIComponent(JSON.stringify({ act, data })) + iframe.style.display = 'none'; + document.body.appendChild(iframe); + iframe.src = `baiduboxapp://mipPageShow?service=bd_mip&action=onMeessage&args=${paramStr}&callbackId=''`; + setTimeout(() => iframe.parentNode.removeChild(iframe)); + } } }, @@ -335,14 +345,33 @@ let viewer = { let routePath = (window.MIP.standalone && !window.MIP.util.isCacheUrl(location.href)) ? to : makeCacheUrl(to) let routeSplits = routePath.split('#') let hashStr = '#' - let curHashObj = MIP.hash._getHashObj(routeSplits[1] || '') - let targetHashObj = MIP.hash._getHashObj(location.hash) - let retObj = Object.assign({}, targetHashObj, curHashObj) + let targetHashobj = MIP.hash._getHashObj(routeSplits[1] || '') + let sourceHashObj = MIP.hash._getHashObj(location.hash) + let couldPassHash = true; + let retHashObj = {}; + + // 处理一下锚点的情况,删除前一个页面的锚点 + for (let key in sourceHashObj) { + if (sourceHashObj[key].sep !== '=') { + delete sourceHashObj[key]; + } + } + // 如果是锚点的跳转,就不透传 hash 了,透传的 hash 会导致锚点失效 + for (let key in targetHashobj) { + if (targetHashobj[key].sep !== '=') { + couldPassHash = false; + break; + } + } + + retHashObj = couldPassHash + ? Object.assign({}, sourceHashObj, targetHashobj) + : targetHashobj - for (let key in retObj) { + for (let key in retHashObj) { // 不透传熊掌号相关的 hash,只保证第一次 logo + title 展现 if (key !== 'cambrian') { - hashStr += `${key}${retObj[key].sep}${retObj[key].value}&` + hashStr += `${key}${retHashObj[key].sep}${retHashObj[key].value}&` } }