From 706a8f069ba3a6239f67441d7234a3f37bed0d75 Mon Sep 17 00:00:00 2001 From: itgaojian163 Date: Fri, 7 Feb 2025 16:29:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6mp-html,=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 18 +- app.json | 5 +- app.wxss | 4 + .../container-loading/container-loading.js | 50 +- .../container-loading/container-loading.wxml | 6 +- .../container-loading/container-loading.wxss | 12 + components/content-loading/loading.wxss | 2 + components/mp-html/index.js | 152 +++++ components/mp-html/index.json | 1 + components/mp-html/index.wxml | 4 + components/mp-html/index.wxss | 11 + components/mp-html/node/node.js | 147 +++++ components/mp-html/node/node.json | 1 + components/mp-html/node/node.wxml | 34 ++ components/mp-html/node/node.wxss | 157 +++++ components/mp-html/parser.js | 537 ++++++++++++++++++ components/page-loading/page-loading.wxss | 2 + imgs/load_err.png | Bin 0 -> 16724 bytes pages/company/company.wxml | 4 +- pages/company/company.wxss | 6 - pages/domain/domain.js | 38 +- pages/domain/domain.wxml | 2 +- pages/index/index.js | 38 +- pages/index/index.wxml | 28 +- pages/industry-area/industry-area.wxml | 2 +- pages/invest-detail/invest-detail.wxml | 2 +- pages/plates/plates.wxml | 4 +- pages/policy-detail/policy-detail.wxml | 4 +- .../superiority-detail.wxml | 2 +- pages/unique-detail/unique-detail.wxml | 5 +- project.config.json | 2 +- utils/http.js | 3 +- 32 files changed, 1189 insertions(+), 94 deletions(-) create mode 100644 components/mp-html/index.js create mode 100644 components/mp-html/index.json create mode 100644 components/mp-html/index.wxml create mode 100644 components/mp-html/index.wxss create mode 100644 components/mp-html/node/node.js create mode 100644 components/mp-html/node/node.json create mode 100644 components/mp-html/node/node.wxml create mode 100644 components/mp-html/node/node.wxss create mode 100644 components/mp-html/parser.js create mode 100644 imgs/load_err.png diff --git a/app.js b/app.js index d38cb27..c7274e3 100644 --- a/app.js +++ b/app.js @@ -1,19 +1,15 @@ //app.js App({ onLaunch() { - // 展示本地存储能力 - // const logs = wx.getStorageSync('logs') || [] - // logs.unshift(Date.now()) - // wx.setStorageSync('logs', logs) - // 登录 - wx.login({ - success: res => { - // 发送 res.code 到后台换取 openId, sessionKey, unionId - } - }) + // wx.login({ + // success: res => { + // // 发送 res.code 到后台换取 openId, sessionKey, unionId + // } + // }) }, globalData: { userInfo: null, - imgPath: 'http://106.74.34.136:8084/daqi/route/file/true/' + // imgPath: 'http://106.74.34.136:8084/daqi/route/file/true/' + imgPath: 'https://www.xzszwhy.cn/daqi/route/file/true/' } }) \ No newline at end of file diff --git a/app.json b/app.json index b1772ee..c402f75 100644 --- a/app.json +++ b/app.json @@ -15,7 +15,7 @@ ], "window": { "navigationBarTextStyle": "black", - "navigationBarTitleText": "达拉特招商", + "navigationBarTitleText": "达拉特旗招商", "navigationBarBackgroundColor": "#ffffff" }, "tabBar": { @@ -51,6 +51,7 @@ }, "usingComponents": { "page-loading": "/components/page-loading/page-loading", - "container-loading": "/components/container-loading/container-loading" + "container-loading": "/components/container-loading/container-loading", + "mp-html": "/components/mp-html/index" } } \ No newline at end of file diff --git a/app.wxss b/app.wxss index cba2cfb..4341bbf 100644 --- a/app.wxss +++ b/app.wxss @@ -273,4 +273,8 @@ page::after { align-self: center; justify-content: center; margin-top: 70rpx; +} + +.rich-text { + width: 100%; } \ No newline at end of file diff --git a/components/container-loading/container-loading.js b/components/container-loading/container-loading.js index a0565e4..3b60416 100644 --- a/components/container-loading/container-loading.js +++ b/components/container-loading/container-loading.js @@ -1,30 +1,30 @@ // components/container-loading/container-loading.js Component({ - /** - * 组件的属性列表 - */ - properties: { - loadingState: { - type: Boolean, - value: true - } - }, - observers: { - 'loadingState': function (newVal) { - this.setData({ - loadingVisible: newVal - }); + /** + * 组件的属性列表 + */ + properties: { + loadingState: { + type: String, + value: 'loading' + } + }, + observers: { + 'loadingState': function (newVal) { + this.setData({ + loadingVisible: newVal + }); + } + }, + data: { + loadingVisible: 'loading' + }, + + /** + * 组件的方法列表 + */ + methods: { + } - }, - data: { - loadingVisible: true - }, - - /** - * 组件的方法列表 - */ - methods: { - - } }) \ No newline at end of file diff --git a/components/container-loading/container-loading.wxml b/components/container-loading/container-loading.wxml index 0060029..5d7cd3d 100644 --- a/components/container-loading/container-loading.wxml +++ b/components/container-loading/container-loading.wxml @@ -1,7 +1,9 @@ - + + + - + \ No newline at end of file diff --git a/components/container-loading/container-loading.wxss b/components/container-loading/container-loading.wxss index 9289783..e144297 100644 --- a/components/container-loading/container-loading.wxss +++ b/components/container-loading/container-loading.wxss @@ -10,6 +10,7 @@ .loading { position: relative; width: 40px; + border-radius: 20px; perspective: 500px; align-self: center; margin-top: 80rpx; @@ -21,6 +22,7 @@ width: 15px; height: 15px; content: ""; + border-radius: 20px; animation: jumping 0.5s infinite alternate; background: rgba(0, 0, 0, 0); } @@ -34,6 +36,16 @@ animation-delay: 0.15s; } +.loading_err { + display: flex; + flex-direction: row; + justify-content: center; + width: 150px; + align-items: center; + height: 100px; + align-self: center; +} + @keyframes jumping { 0% { transform: scale(1) translateY(0px) rotateX(0deg); diff --git a/components/content-loading/loading.wxss b/components/content-loading/loading.wxss index 09b5f42..a00a816 100644 --- a/components/content-loading/loading.wxss +++ b/components/content-loading/loading.wxss @@ -17,6 +17,7 @@ .loading { position: relative; width: 50px; + border-radius: 25px; } .loading:before, @@ -25,6 +26,7 @@ width: 20px; height: 20px; content: ""; + border-radius: 20px; animation: jumping 0.5s infinite alternate; background: rgba(0, 0, 0, 0); } diff --git a/components/mp-html/index.js b/components/mp-html/index.js new file mode 100644 index 0000000..d2cfa0a --- /dev/null +++ b/components/mp-html/index.js @@ -0,0 +1,152 @@ +"use strict"; + +function e(e, t, n) { + return t in e ? Object.defineProperty(e, t, { + value: n, + enumerable: !0, + configurable: !0, + writable: !0 + }) : e[t] = n, e +} +/*! + * mp-html v2.5.0 + * https://github.com/jin-yufeng/mp-html + * + * Released under the MIT license + * Author: Jin Yufeng + */ +var t = require("./parser"), + n = []; +Component({ + data: { + nodes: [] + }, + properties: { + containerStyle: String, + content: { + type: String, + value: "", + observer: function (e) { + this.setContent(e) + } + }, + copyLink: { + type: Boolean, + value: !0 + }, + domain: String, + errorImg: String, + lazyLoad: Boolean, + loadingImg: String, + pauseVideo: { + type: Boolean, + value: !0 + }, + previewImg: { + type: null, + value: !0 + }, + scrollTable: Boolean, + selectable: null, + setTitle: { + type: Boolean, + value: !0 + }, + showImgMenu: { + type: Boolean, + value: !0 + }, + tagStyle: Object, + useAnchor: null + }, + created: function () { + this.plugins = []; + for (var e = n.length; e--;) this.plugins.push(new n[e](this)) + }, + detached: function () { + this._hook("onDetached") + }, + methods: { + in: function (e, t, n) { + e && t && n && (this._in = { + page: e, + selector: t, + scrollTop: n + }) + }, + navigateTo: function (t, n) { + var i = this; + return new Promise(function (o, r) { + if (!i.data.useAnchor) return void r(Error("Anchor is disabled")); + var a = wx.createSelectorQuery().in(i._in ? i._in.page : i).select((i._in ? i._in.selector : "._root") + (t ? "".concat(">>>", "#").concat(t) : "")).boundingClientRect(); + i._in ? a.select(i._in.selector).scrollOffset().select(i._in.selector).boundingClientRect() : a.selectViewport().scrollOffset(), a.exec(function (t) { + if (!t[0]) return void r(Error("Label not found")); + var a = t[1].scrollTop + t[0].top - (t[2] ? t[2].top : 0) + (n || parseInt(i.data.useAnchor) || 0); + i._in ? i._in.page.setData(e({}, i._in.scrollTop, a)) : wx.pageScrollTo({ + scrollTop: a, + duration: 300 + }), o() + }) + }) + }, + getText: function (e) { + var t = ""; + return function e(n) { + for (var i = 0; i < n.length; i++) { + var o = n[i]; + if ("text" === o.type) t += o.text.replace(/&/g, "&"); + else if ("br" === o.name) t += "\n"; + else { + var r = "p" === o.name || "div" === o.name || "tr" === o.name || "li" === o.name || "h" === o.name[0] && o.name[1] > "0" && o.name[1] < "7"; + r && t && "\n" !== t[t.length - 1] && (t += "\n"), o.children && e(o.children), r && "\n" !== t[t.length - 1] ? t += "\n" : "td" !== o.name && "th" !== o.name || (t += "\t") + } + } + }(e || this.data.nodes), t + }, + getRect: function () { + var e = this; + return new Promise(function (t, n) { + wx.createSelectorQuery().in(e).select("._root").boundingClientRect().exec(function (e) { + return e[0] ? t(e[0]) : n(Error("Root label not found")) + }) + }) + }, + pauseMedia: function () { + for (var e = (this._videos || []).length; e--;) this._videos[e].pause() + }, + setPlaybackRate: function (e) { + this.playbackRate = e; + for (var t = (this._videos || []).length; t--;) this._videos[t].playbackRate(e) + }, + setContent: function (e, n) { + var i = this; + this.imgList && n || (this.imgList = []), this._videos = []; + var o = {}, + r = new t(this).parse(e); + if (n) + for (var a = this.data.nodes.length, s = r.length; s--;) o["nodes[".concat(a + s, "]")] = r[s]; + else o.nodes = r; + if (this.setData(o, function () { + i._hook("onLoad"), i.triggerEvent("load") + }), this.data.lazyLoad || this.imgList._unloadimgs < this.imgList.length / 2) { + var l = 0, + c = function e(t) { + t && t.height || (t = {}), t.height === l ? i.triggerEvent("ready", t) : (l = t.height, setTimeout(function () { + i.getRect().then(e).catch(e) + }, 350)) + }; + this.getRect().then(c).catch(c) + } else this.imgList._unloadimgs || this.getRect().then(function (e) { + i.triggerEvent("ready", e) + }).catch(function () { + i.triggerEvent("ready", {}) + }) + }, + _hook: function (e) { + for (var t = n.length; t--;) this.plugins[t][e] && this.plugins[t][e]() + }, + _add: function (e) { + e.detail.root = this + } + } +}); \ No newline at end of file diff --git a/components/mp-html/index.json b/components/mp-html/index.json new file mode 100644 index 0000000..36b626e --- /dev/null +++ b/components/mp-html/index.json @@ -0,0 +1 @@ +{"component":true,"usingComponents":{"node":"./node/node"}} \ No newline at end of file diff --git a/components/mp-html/index.wxml b/components/mp-html/index.wxml new file mode 100644 index 0000000..9b84cb1 --- /dev/null +++ b/components/mp-html/index.wxml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/components/mp-html/index.wxss b/components/mp-html/index.wxss new file mode 100644 index 0000000..d1fbe4d --- /dev/null +++ b/components/mp-html/index.wxss @@ -0,0 +1,11 @@ +._root { + padding: 1px 0; + overflow-x: auto; + overflow-y: hidden; + -webkit-overflow-scrolling: touch +} + +._select { + -webkit-user-select: text; + user-select: text +} \ No newline at end of file diff --git a/components/mp-html/node/node.js b/components/mp-html/node/node.js new file mode 100644 index 0000000..e97ca31 --- /dev/null +++ b/components/mp-html/node/node.js @@ -0,0 +1,147 @@ +"use strict"; + +function t(t, e) { + var r = Object.keys(t); + if (Object.getOwnPropertySymbols) { + var i = Object.getOwnPropertySymbols(t); + e && (i = i.filter(function (e) { + return Object.getOwnPropertyDescriptor(t, e).enumerable + })), r.push.apply(r, i) + } + return r +} + +function e(e) { + for (var i = 1; i < arguments.length; i++) { + var o = null != arguments[i] ? arguments[i] : {}; + i % 2 ? t(Object(o), !0).forEach(function (t) { + r(e, t, o[t]) + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : t(Object(o)).forEach(function (t) { + Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(o, t)) + }) + } + return e +} + +function r(t, e, r) { + return e in t ? Object.defineProperty(t, e, { + value: r, + enumerable: !0, + configurable: !0, + writable: !0 + }) : t[e] = r, t +} +Component({ + data: { + ctrl: {}, + // isiOS: wx.getSystemInfoSync().system.includes("iOS") + isiOS: wx.getDeviceInfo().system.includes("iOS") + }, + properties: { + childs: Array, + opts: Array + }, + options: { + addGlobalClass: !0 + }, + attached: function () { + this.triggerEvent("add", this, { + bubbles: !0, + composed: !0 + }) + }, + methods: { + noop: function () {}, + getNode: function (t) { + try { + for (var e = t.split("_"), r = this.data.childs[e[0]], i = 1; i < e.length; i++) r = r.children[e[i]]; + return r + } catch (t) { + return { + text: "", + attrs: {}, + children: [] + } + } + }, + play: function (t) { + var r = t.target.dataset.i, + i = this.getNode(r); + if (this.root.triggerEvent("play", { + source: i.name, + attrs: e(e({}, i.attrs), {}, { + src: i.src[this.data.ctrl[r] || 0] + }) + }), this.root.data.pauseVideo) { + for (var o = !1, s = t.target.id, a = this.root._videos.length; a--;) this.root._videos[a].id === s ? o = !0 : this.root._videos[a].pause(); + if (!o) { + var n = wx.createVideoContext(s, this); + n.id = s, this.root.playbackRate && n.playbackRate(this.root.playbackRate), this.root._videos.push(n) + } + } + }, + imgTap: function (t) { + var 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)) { + var r = this.root.imgList[e.i]; + wx.previewImage({ + showmenu: this.root.data.showImgMenu, + current: r, + urls: this.root.imgList + }) + } + }, + imgLoad: function (t) { + var e, i = t.target.dataset.i, + o = this.getNode(i); + o.w ? (this.data.opts[1] && !this.data.ctrl[i] || -1 === this.data.ctrl[i]) && (e = 1) : e = t.detail.width, e && this.setData(r({}, "ctrl." + i, e)), this.checkReady() + }, + checkReady: function () { + var t = this; + this.root.data.lazyLoad || (this.root.imgList._unloadimgs -= 1, this.root.imgList._unloadimgs || setTimeout(function () { + t.root.getRect().then(function (e) { + t.root.triggerEvent("ready", e) + }).catch(function () { + t.root.triggerEvent("ready", {}) + }) + }, 350)) + }, + linkTap: function (t) { + var e = t.currentTarget ? this.getNode(t.currentTarget.dataset.i) : {}, + r = e.attrs || t, + i = r.href; + this.root.triggerEvent("linktap", Object.assign({ + innerText: this.root.getText(e.children || []) + }, r)), i && ("#" === i[0] ? this.root.navigateTo(i.substring(1)).catch(function () {}) : i.split("?")[0].includes("://") ? this.root.data.copyLink && wx.setClipboardData({ + data: i, + success: function () { + return wx.showToast({ + title: "链接已复制" + }) + } + }) : wx.navigateTo({ + url: i, + fail: function () { + wx.switchTab({ + url: i, + fail: function () {} + }) + } + })) + }, + mediaError: function (t) { + var e = t.target.dataset.i, + i = this.getNode(e); + if ("video" === i.name || "audio" === i.name) { + var o = (this.data.ctrl[e] || 0) + 1; + if (o > i.src.length && (o = 0), o < i.src.length) return this.setData(r({}, "ctrl." + e, o)) + } else "img" === i.name && (this.data.opts[2] && this.setData(r({}, "ctrl." + e, -1)), this.checkReady()); + this.root && this.root.triggerEvent("error", { + source: i.name, + attrs: i.attrs, + errMsg: t.detail.errMsg + }) + } + } +}); \ No newline at end of file diff --git a/components/mp-html/node/node.json b/components/mp-html/node/node.json new file mode 100644 index 0000000..36f7ff7 --- /dev/null +++ b/components/mp-html/node/node.json @@ -0,0 +1 @@ +{"component":true,"usingComponents":{"node":"./node"}} \ No newline at end of file diff --git a/components/mp-html/node/node.wxml b/components/mp-html/node/node.wxml new file mode 100644 index 0000000..8548380 --- /dev/null +++ b/components/mp-html/node/node.wxml @@ -0,0 +1,34 @@ + + var e = { abbr: !0, b: !0, big: !0, code: !0, del: !0, em: !0, i: !0, ins: !0, label: !0, q: !0, small: !0, span: !0, strong: !0, sub: !0, sup: !0 }; module.exports = function (n, i) { return e[n] || -1 !== (i || "").indexOf("inline") }; + +