u-parse.js 3.6 KB
"use strict";const l=require("../../../../common/vendor.js"),c=require("./parser.js"),d=()=>"./node/node.js",r=[],u={name:"u-parse",data(){return{nodes:[]}},props:{containerStyle:{type:String,default:""},content:{type:String,default:""},copyLink:{type:[Boolean,String],default:!0},domain:String,errorImg:{type:String,default:""},lazyLoad:{type:[Boolean,String],default:!1},loadingImg:{type:String,default:""},pauseVideo:{type:[Boolean,String],default:!0},previewImg:{type:[Boolean,String],default:!0},scrollTable:[Boolean,String],selectable:[Boolean,String],setTitle:{type:[Boolean,String],default:!0},showImgMenu:{type:[Boolean,String],default:!0},tagStyle:Object,useAnchor:[Boolean,Number]},emits:["load","ready","imgtap","linktap","play","error"],components:{node:d},watch:{content(t){this.setContent(t)}},created(){this.plugins=[];for(let t=r.length;t--;)this.plugins.push(new r[t](this))},mounted(){this.content&&!this.nodes.length&&this.setContent(this.content)},beforeDestroy(){this._hook("onDetached")},methods:{in(t,e,i){t&&e&&i&&(this._in={page:t,selector:e,scrollTop:i})},navigateTo(t,e){return new Promise((i,s)=>{if(!this.useAnchor){s(Error("Anchor is disabled"));return}e=e||parseInt(this.useAnchor)||0;let o=" ";o=">>>";const n=l.index.createSelectorQuery().in(this._in?this._in.page:this).select((this._in?this._in.selector:"._root")+(t?`${o}#${t}`:"")).boundingClientRect();this._in?n.select(this._in.selector).scrollOffset().select(this._in.selector).boundingClientRect():n.selectViewport().scrollOffset(),n.exec(a=>{if(!a[0]){s(Error("Label not found"));return}const h=a[1].scrollTop+a[0].top-(a[2]?a[2].top:0)+e;this._in?this._in.page[this._in.scrollTop]=h:l.index.pageScrollTo({scrollTop:h,duration:300}),i()})})},getText(t){let e="";return function i(s){for(let o=0;o<s.length;o++){const n=s[o];if(n.type==="text")e+=n.text.replace(/&amp;/g,"&");else if(n.name==="br")e+=`
`;else{const a=n.name==="p"||n.name==="div"||n.name==="tr"||n.name==="li"||n.name[0]==="h"&&n.name[1]>"0"&&n.name[1]<"7";a&&e&&e[e.length-1]!==`
`&&(e+=`
`),n.children&&i(n.children),a&&e[e.length-1]!==`
`?e+=`
`:(n.name==="td"||n.name==="th")&&(e+="	")}}}(t||this.nodes),e},getRect(){return new Promise((t,e)=>{l.index.createSelectorQuery().in(this).select("#_root").boundingClientRect().exec(i=>i[0]?t(i[0]):e(Error("Root label not found")))})},pauseMedia(){for(let t=(this._videos||[]).length;t--;)this._videos[t].pause()},setPlaybackRate(t){this.playbackRate=t;for(let e=(this._videos||[]).length;e--;)this._videos[e].playbackRate(t)},setContent(t,e){(!e||!this.imgList)&&(this.imgList=[]);const i=new c.Parser(this).parse(t);if(this.$set(this,"nodes",e?(this.nodes||[]).concat(i):i),this._videos=[],this.$nextTick(()=>{this._hook("onLoad"),this.$emit("load")}),this.lazyLoad||this.imgList._unloadimgs<this.imgList.length/2){let s=0;const o=n=>{(!n||!n.height)&&(n={}),n.height===s?this.$emit("ready",n):(s=n.height,setTimeout(()=>{this.getRect().then(o).catch(o)},350))};this.getRect().then(o).catch(o)}else this.imgList._unloadimgs||this.getRect().then(s=>{this.$emit("ready",s)}).catch(()=>{this.$emit("ready",{})})},_hook(t){for(let e=r.length;e--;)this.plugins[e][t]&&this.plugins[e][t]()}}};Array||l.resolveComponent("node")();function g(t,e,i,s,o,n){return l.e({a:!o.nodes[0]},o.nodes[0]?{b:l.p({childs:o.nodes,opts:[i.lazyLoad,i.loadingImg,i.errorImg,i.showImgMenu,i.selectable],name:"span"})}:{},{c:l.n((i.selectable?"_select ":"")+"_root"),d:l.s(i.containerStyle)})}const m=l._export_sfc(u,[["render",g],["__file","D:/vue/大健康商城/healthMall/uni_modules/uview-plus/components/u-parse/u-parse.vue"]]);wx.createComponent(m);