Commit 767226bd authored by wlxuqu's avatar wlxuqu

1. 更新uparse

2. 优化tabs组建在头条小程序的布局
parent a32cd0f6
...@@ -10,7 +10,7 @@ try{ ...@@ -10,7 +10,7 @@ try{
} }
module.exports = { module.exports = {
created() { beforeCreate() {
// 将vuex方法挂在到$u中 // 将vuex方法挂在到$u中
// 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗') // 使用方法为:如果要修改vuex的state中的user.name变量为"史诗" => this.$u.vuex('user.name', '史诗')
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1') // 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
......
/** /**
* html 解析器 * html 解析器
* @tutorial https://github.com/jin-yufeng/Parser * @tutorial https://github.com/jin-yufeng/Parser
* @version 20200728 * @version 20200828
* @author JinYufeng * @author JinYufeng
* @listens MIT * @listens MIT
*/ */
...@@ -243,7 +243,7 @@ MpHtmlParser.prototype.setNode = function() { ...@@ -243,7 +243,7 @@ MpHtmlParser.prototype.setNode = function() {
} }
var width; var width;
if (styleObj.width) width = styleObj.width; if (styleObj.width) width = styleObj.width;
else if (attrs.width) width = attrs.width.includes('%') ? attrs.width : attrs.width + 'px'; else if (attrs.width) width = attrs.width.includes('%') ? attrs.width : parseFloat(attrs.width) + 'px';
if (width) { if (width) {
styleObj.width = width; styleObj.width = width;
attrs.width = '100%'; attrs.width = '100%';
...@@ -256,7 +256,7 @@ MpHtmlParser.prototype.setNode = function() { ...@@ -256,7 +256,7 @@ MpHtmlParser.prototype.setNode = function() {
attrs.height = styleObj.height; attrs.height = styleObj.height;
styleObj.height = ''; styleObj.height = '';
} else if (attrs.height && !attrs.height.includes('%')) } else if (attrs.height && !attrs.height.includes('%'))
attrs.height += 'px'; attrs.height = parseFloat(attrs.height) + 'px';
} }
for (var key in styleObj) { for (var key in styleObj) {
var value = styleObj[key]; var value = styleObj[key];
......
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
init() { init() {
for (var i = this.nodes.length, n; n = this.nodes[--i];) { for (var i = this.nodes.length, n; n = this.nodes[--i];) {
if (n.name == 'img') { if (n.name == 'img') {
this.top.imgList.setItem(n.attrs.i, n.attrs.src); this.top.imgList.setItem(n.attrs.i, n.attrs['original-src'] || n.attrs.src);
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (this.lazyLoad && !this.observer) { if (this.lazyLoad && !this.observer) {
this.observer = uni.createIntersectionObserver(this).relativeToViewport({ this.observer = uni.createIntersectionObserver(this).relativeToViewport({
......
...@@ -34,7 +34,10 @@ ...@@ -34,7 +34,10 @@
} }
// #endif // #endif
// #ifdef H5 || APP-PLUS-NVUE || MP-360 // #ifdef H5 || APP-PLUS-NVUE || MP-360
var windowWidth = uni.getSystemInfoSync().windowWidth, var {
windowWidth,
platform
} = uni.getSystemInfoSync(),
cfg = require('./libs/config.js'); cfg = require('./libs/config.js');
// #endif // #endif
// #ifdef APP-PLUS-NVUE // #ifdef APP-PLUS-NVUE
...@@ -63,7 +66,7 @@ ...@@ -63,7 +66,7 @@
* @event {Function} imgtap 图片点击事件 * @event {Function} imgtap 图片点击事件
* @event {Function} linkpress 链接点击事件 * @event {Function} linkpress 链接点击事件
* @author JinYufeng * @author JinYufeng
* @version 20200728 * @version 20200828
* @listens MIT * @listens MIT
*/ */
export default { export default {
...@@ -216,12 +219,13 @@ ...@@ -216,12 +219,13 @@
'</div><script>"use strict";function e(e){if(window.__dcloud_weex_postMessage||window.__dcloud_weex_){var t={data:[e]};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(t):window.__dcloud_weex_.postMessage(JSON.stringify(t))}}document.body.onclick=function(){e({action:"click"})},' + '</div><script>"use strict";function e(e){if(window.__dcloud_weex_postMessage||window.__dcloud_weex_){var t={data:[e]};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(t):window.__dcloud_weex_.postMessage(JSON.stringify(t))}}document.body.onclick=function(){e({action:"click"})},' +
(this.showWithAnimation ? 'document.body.style.animation="_show .5s",' : '') + (this.showWithAnimation ? 'document.body.style.animation="_show .5s",' : '') +
'setTimeout(function(){e({action:"load",text:document.body.innerText,height:document.getElementById("parser").scrollHeight})},50);\x3c/script>'; 'setTimeout(function(){e({action:"load",text:document.body.innerText,height:document.getElementById("parser").scrollHeight})},50);\x3c/script>';
if (platform == 'android') html = html.replace(/%/g, '%25');
this.$refs.web.evalJs("document.write('" + html.replace(/'/g, "\\'") + "');document.close()"); this.$refs.web.evalJs("document.write('" + html.replace(/'/g, "\\'") + "');document.close()");
} }
this.$refs.web.evalJs( this.$refs.web.evalJs(
'var t=document.getElementsByTagName("title");t.length&&e({action:"getTitle",title:t[0].innerText});for(var o,n=document.getElementsByTagName("style"),r=1;o=n[r++];)o.innerHTML=o.innerHTML.replace(/body/g,"#parser");for(var a,c=document.getElementsByTagName("img"),s=[],i=0==c.length,d=0,l=0,g=0;a=c[l];l++)parseInt(a.style.width||a.getAttribute("width"))>' + 'var t=document.getElementsByTagName("title");t.length&&e({action:"getTitle",title:t[0].innerText});for(var o,n=document.getElementsByTagName("style"),r=1;o=n[r++];)o.innerHTML=o.innerHTML.replace(/body/g,"#parser");for(var a,c=document.getElementsByTagName("img"),s=[],i=0==c.length,d=0,l=0,g=0;a=c[l];l++)parseInt(a.style.width||a.getAttribute("width"))>' +
windowWidth + '&&(a.style.height="auto"),a.onload=function(){++d==c.length&&(i=!0)},a.onerror=function(){++d==c.length&&(i=!0),' + (cfg.errorImg ? 'this.src="' + cfg.errorImg + '",' : '') + windowWidth + '&&(a.style.height="auto"),a.onload=function(){++d==c.length&&(i=!0)},a.onerror=function(){++d==c.length&&(i=!0),' + (cfg.errorImg ? 'this.src="' + cfg.errorImg + '",' : '') +
'e({action:"error",source:"img",target:this})},a.hasAttribute("ignore")||"A"==a.parentElement.nodeName||(a.i=g++,s.push(a.src),a.onclick=function(){e({action:"preview",img:{i:this.i,src:this.src}})});e({action:"getImgList",imgList:s});for(var u,m=document.getElementsByTagName("a"),f=0;u=m[f];f++)u.onclick=function(){var t,o=this.getAttribute("href");if("#"==o[0]){var n=document.getElementById(o.substr(1));n&&(t=n.offsetTop)}return e({action:"linkpress",href:o,offset:t}),!1};for(var h,y=document.getElementsByTagName("video"),v=0;h=y[v];v++)h.style.maxWidth="100%",h.onerror=function(){e({action:"error",source:"video",target:this})}' + 'e({action:"error",source:"img",target:this})},a.hasAttribute("ignore")||"A"==a.parentElement.nodeName||(a.i=g++,s.push(a.getAttribute("original-src")||a.src||a.getAttribute("data-src")),a.onclick=function(){e({action:"preview",img:{i:this.i,src:this.src}})});e({action:"getImgList",imgList:s});for(var u,m=document.getElementsByTagName("a"),f=0;u=m[f];f++)u.onclick=function(){var t,o=this.getAttribute("href");if("#"==o[0]){var n=document.getElementById(o.substr(1));n&&(t=n.offsetTop)}return e({action:"linkpress",href:o,offset:t}),!1};for(var h,y=document.getElementsByTagName("video"),v=0;h=y[v];v++)h.style.maxWidth="100%",h.onerror=function(){e({action:"error",source:"video",target:this})}' +
(this.autopause ? ',h.onplay=function(){for(var e,t=0;e=y[t];t++)e!=this&&e.pause()}' : '') + (this.autopause ? ',h.onplay=function(){for(var e,t=0;e=y[t];t++)e!=this&&e.pause()}' : '') +
';for(var _,p=document.getElementsByTagName("audio"),w=0;_=p[w];w++)_.onerror=function(){e({action:"error",source:"audio",target:this})};' + ';for(var _,p=document.getElementsByTagName("audio"),w=0;_=p[w];w++)_.onerror=function(){e({action:"error",source:"audio",target:this})};' +
(this.autoscroll ? 'for(var T,E=document.getElementsByTagName("table"),B=0;T=E[B];B++){var N=document.createElement("div");N.style.overflow="scroll",T.parentNode.replaceChild(N,T),N.appendChild(T)}' : '') + (this.autoscroll ? 'for(var T,E=document.getElementsByTagName("table"),B=0;T=E[B];B++){var N=document.createElement("div");N.style.overflow="scroll",T.parentNode.replaceChild(N,T),N.appendChild(T)}' : '') +
...@@ -284,7 +288,7 @@ ...@@ -284,7 +288,7 @@
} }
if (!img.hasAttribute('ignore') && img.parentElement.nodeName != 'A') { if (!img.hasAttribute('ignore') && img.parentElement.nodeName != 'A') {
img.i = j++; img.i = j++;
_ts.imgList.push(img.src || img.getAttribute('data-src')); _ts.imgList.push(img.getAttribute('original-src') || img.src || img.getAttribute('data-src'));
img.onclick = function() { img.onclick = function() {
var preview = true; var preview = true;
this.ignore = () => preview = false; this.ignore = () => preview = false;
...@@ -525,7 +529,7 @@ ...@@ -525,7 +529,7 @@
style += '</style>'; style += '</style>';
html = style + html; html = style + html;
} }
// 处理rpx // 处理 rpx
if (html.includes('rpx')) if (html.includes('rpx'))
html = html.replace(/[0-9.]+\s*rpx/g, $ => (parseFloat($) * windowWidth / 750) + 'px'); html = html.replace(/[0-9.]+\s*rpx/g, $ => (parseFloat($) * windowWidth / 750) + 'px');
return html; return html;
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
margin: effect3d && uCurrent != index ? '0 20rpx' : 0, margin: effect3d && uCurrent != index ? '0 20rpx' : 0,
backgroundColor: bgColor backgroundColor: bgColor
}"> }">
<image class="u-swiper-image" :src="item[name]" :mode="imgMode"></image> <image class="u-swiper-image" :src="item[name] || item" :mode="imgMode"></image>
<view v-if="title" class="u-swiper-title u-line-1" :style="[{ <view v-if="title && item.title" class="u-swiper-title u-line-1" :style="[{
'padding-bottom': titlePaddingBottom 'padding-bottom': titlePaddingBottom
}, titleStyle]"> }, titleStyle]">
{{ item.title }} {{ item.title }}
......
...@@ -308,6 +308,9 @@ ...@@ -308,6 +308,9 @@
.u-scroll-box { .u-scroll-box {
position: relative; position: relative;
/* #ifdef MP-TOUTIAO */
white-space: nowrap;
/* #endif */
} }
/* #ifdef H5 */ /* #ifdef H5 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment