node.js 2.57 KB
"use strict";function t(t, e, i){return e in t?Object.defineProperty(t, e, { value:i, enumerable:!0, configurable:!0, writable:!0 }):t[e]=i, t;}Component({ data:{ ctrl:{}, isiOS:wx.getSystemInfoSync().system.includes("iOS") }, properties:{ childs:Array, opts:Array }, options:{ addGlobalClass:!0 }, attached(){this.triggerEvent("add", this, { bubbles:!0, composed:!0 });}, methods:{ noop(){}, getNode(t){try {for (var e=t.split("_"), i=this.data.childs[e[0]], r=1;r<e.length;r++)i=i.children[e[r]];return i;} catch {return { text:"", attrs:{}, children:[] };}}, play(t){if (this.root.triggerEvent("play"), this.root.data.pauseVideo){for (var e=!1, i=t.target.id, r=this.root._videos.length;r--;) this.root._videos[r].id===i?e=!0:this.root._videos[r].pause();if (!e){const o=wx.createVideoContext(i, this);o.id=i, this.root.playbackRate&&o.playbackRate(this.root.playbackRate), this.root._videos.push(o);}}}, imgTap(t){const e=this.getNode(t.target.dataset.i);if (e.a) return this.linkTap(e.a);if (!e.attrs.ignore&&(this.root.triggerEvent("imgtap", e.attrs), this.root.data.previewImg)){const i=this.root.imgList[e.i];wx.previewImage({ showmenu:this.root.data.showImgMenu, current:i, urls:this.root.imgList });}}, imgLoad(e){let i; const r=e.target.dataset.i; const o=this.getNode(r);o.w?(this.data.opts[1]&&!this.data.ctrl[r]||this.data.ctrl[r]===-1)&&(i=1):i=e.detail.width, i&&this.setData(t({}, `ctrl.${r}`, i)), this.checkReady();}, checkReady(){const t=this;this.root.data.lazyLoad||(this.root.imgList._unloadimgs-=1, this.root.imgList._unloadimgs||setTimeout(() =>{t.root.getRect().then((e) =>{t.root.triggerEvent("ready", e);}).catch(() =>{t.root.triggerEvent("ready", {});});}, 350));}, linkTap(t){const e=t.currentTarget?this.getNode(t.currentTarget.dataset.i):{}; const i=e.attrs||t; const r=i.href;this.root.triggerEvent("linktap", Object.assign({ innerText:this.root.getText(e.children||[]) }, i)), r&&(r[0]==="#"?this.root.navigateTo(r.slice(1)).catch(() =>{}):(r.split("?")[0].includes("://")?this.root.data.copyLink&&wx.setClipboardData({ data:r, success(){return wx.showToast({ title:"链接已复制" });} }):wx.navigateTo({ url:r, fail(){wx.switchTab({ url:r, fail(){} });} })));}, mediaError(e){const i=e.target.dataset.i; const r=this.getNode(i);if (r.name==="video"||r.name==="audio"){let o=(this.data.ctrl[i]||0)+1;if (o>r.src.length&&(o=0), o<r.src.length) return this.setData(t({}, `ctrl.${i}`, o));} else r.name==="img"&&(this.data.opts[2]&&this.setData(t({}, `ctrl.${i}`, -1)), this.checkReady());this.root&&this.root.triggerEvent("error", { source:r.name, attrs:r.attrs, errMsg:e.detail.errMsg });} } });