请求解析

This commit is contained in:
Abin committed 2026-01-05 18:08:52 +08:00
1 parent 0b9c772cfc
commit bb18cb696a
14 files changed
+1241

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
// Parser/trees/cssHandler.wxs
module.exports = {
getStyle: function(style, display) {
var res = "";
var reg = getRegExp("float\s*:\s*[^;]*", "i");
if (reg.test(style)) res += reg.exec(style)[0];
reg = getRegExp("margin[^;]*auto", "i");
if (reg.test(style)) res += (";" + reg.exec(style)[0]);
reg = getRegExp("display\s*:\s*([^;]*)", "i");
if (reg.test(style) && reg.exec(style)[1]!="flex") res += (';' + reg.exec(style)[0]);
else res += (';display:' + display);
reg = getRegExp("[^;\s]*width\s*:\s*[^;]*", "ig");
var width = reg.exec(style);
while (width) {
res += (';' + width[0]);
width = reg.exec(style);
}
return res;
},
setImgStyle: function(item, imgMode) {
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
item.attrs.style += ';width:100%';
if (imgMode == "widthFix")
item.attrs.style += ";height:auto !important";
return [item];
},
setStyle: function(item) {
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
item.attrs.style += ';width:100%';
return [item];
}
}
+67
View File
@@ -0,0 +1,67 @@
// Parser/trees/trees.js
Component({
properties: {
nodes: {
type: Array,
value: []
},
controls: {
type: Object,
value: {}
}
},
methods: {
//冒泡事件
playEvent(e) {
this.triggerEvent('play', e.currentTarget.dataset.id, {
bubbles: true,
composed: true
});
},
previewEvent(e) {
if (!e.target.dataset.hasOwnProperty('ignore')) {
this.triggerEvent('preview', e.currentTarget.dataset.src, {
bubbles: true,
composed: true
});
}
},
tapEvent(e) {
this.triggerEvent('linkpress', e.currentTarget.dataset.href, {
bubbles: true,
composed: true
});
},
errorEvent(e) {
//尝试加载其他源
if (!this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > 1) {
this.data.controls[e.currentTarget.dataset.id] = {
play: false,
index: 1
}
} else if (this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > (this.data.controls[e.currentTarget.dataset.id].index + 1)) {
this.data.controls[e.currentTarget.dataset.id].index++;
}
this.setData({
controls: this.data.controls
})
this.triggerEvent('error', {
target: e.currentTarget,
message: e.detail.errMsg
}, {
bubbles: true,
composed: true
});
},
//内部方法:加载视频
_loadVideo(e) {
this.data.controls[e.currentTarget.dataset.id] = {
play: true,
index: 0
}
this.setData({
controls: this.data.controls
})
},
}
})
+6
View File
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"trees":"./trees"
}
}
+34
View File
@@ -0,0 +1,34 @@
<!--Parser/trees/trees.wxml-->
<wxs module="cssHandler" src="./cssHandler.wxs" />
<block wx:for='{{nodes}}' wx:key="index">
<block wx:if="{{!item.continue}}">
<!--图片-->
<rich-text wx:if="{{item.name=='img'}}" style="{{cssHandler.getStyle(item.attrs.style,'inline-block')}}" nodes='{{cssHandler.setImgStyle(item,controls.imgMode)}}' data-ignore='{{item.attrs.ignore}}' data-src='{{item.attrs.src}}' bindtap='previewEvent' />
<!--文本-->
<block wx:elif="{{item.type=='text'}}">
<text wx:if="{{!item.decode}}" decode>{{item.text}}</text>
<rich-text wx:else style="display:inline-block" nodes="{{[item]}}"></rich-text>
</block>
<text wx:elif="{{item.name=='br'}}">\n</text>
<!--视频-->
<block wx:elif="{{item.name=='video'}}">
<view wx:if="{{item.attrs.id>'video3'&&!controls[item.attrs.id].play}}" class="video" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" bindtap="_loadVideo">
<view class="video-triangle" />
</view>
<video wx:else src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' autoplay="{{item.attrs.autoplay||controls[item.attrs.id].play}}"
class="v" muted="{{item.attrs.muted}}" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" bindplay='playEvent'
binderror="errorEvent" />
</block>
<!--音频-->
<audio wx:elif="{{item.name=='audio'}}" src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' poster='{{item.attrs.poster}}'
name='{{item.attrs.name}}' author='{{item.attrs.author}}' style="{{item.attrs.style}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" binderror="errorEvent" />
<!--富文本-->
<rich-text wx:else class="{{item.name}}" style="{{cssHandler.getStyle(item.attrs.style,'block')}}" nodes="{{cssHandler.setStyle(item)}}" />
</block>
<!--链接-->
<navigator wx:elif="{{item.name=='a'}}" url="{{item.attrs.href}}" style="{{item.attrs.style}}" data-href='{{item.attrs.href}}' hover-class="navigator-hover" hover-start-time="25" hover-stay-time="300" bindtap="tapEvent">
<trees id="node" nodes="{{item.children}}" controls="{{controls}}" />
</navigator>
<!--继续递归-->
<trees wx:else id="node" class="{{item.name}}" style="{{item.attrs.style}}" nodes="{{item.children}}" controls="{{controls}}" />
</block>
+69
View File
@@ -0,0 +1,69 @@
/* 链接受到点击的hover-class,可自定义修改 */
.navigator-hover {
opacity: 0.7;
text-decoration: underline;
}
/* 以下内容不建议修改 */
:host {
display: inherit;
float: inherit;
}
.sub, .sup, .bdo, .bdi, .ruby, .rt {
display: inline-block !important;
}
.div, .blockquote, .p{
display:block;
}
.b, .strong {
display: inline;
font-weight: bold;
}
.em, .i {
display: inline;
font-style: italic;
}
.del {
display: inline;
text-decoration: line-through;
}
.ins {
display: inline;
text-decoration: underline;
}
.code {
display: inline;
font-family: monospace;
}
.big {
font-size:1.2em;
display:inline;
}
.small {
font-size:0.8em;
display:inline;
}
.q, .span, .label, .abbr {
display: inline;
}
.q::before {
content: '"';
}
.q::after {
content: '"';
}
.video {
background-color: rgb(0, 0, 0);
width: 100%;
height: auto;
display: inline-block;
position: relative;
}
.video-triangle {
border-width: 15px 0 15px 30px;
border-style: solid;
border-color: transparent transparent transparent white;
position: absolute;
left: 50%;
top: 50%;
margin: -15px 0 0 -15px;
}