wxParse.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. function e(e) {
  2. return e && e.__esModule ? e : {
  3. default: e
  4. };
  5. }
  6. function t(e) {
  7. var t = this, a = e.target.dataset.src, i = e.target.dataset.from;
  8. void 0 !== i && i.length > 0 && wx.previewImage({
  9. current: a,
  10. urls: t.data[i].imageUrls
  11. });
  12. }
  13. function a(e) {
  14. var t = this, a = e.target.dataset.from, r = e.target.dataset.idx;
  15. void 0 !== a && a.length > 0 && i(e, r, t, a);
  16. }
  17. function i(e, t, a, i) {
  18. var d = a.data[i];
  19. if (0 != d.images.length) {
  20. var n = d.images, s = r(e.detail.width, e.detail.height, a, i);
  21. n[t].width = s.imageWidth, n[t].height = s.imageheight, d.images = n;
  22. var o = {};
  23. o[i] = d, a.setData(o);
  24. }
  25. }
  26. function r(e, t, a, i) {
  27. var r = 0, d = 0, n = 0, s = 0, o = {};
  28. return wx.getSystemInfo({
  29. success: function(g) {
  30. var h = a.data[i].view.imagePadding;
  31. r = g.windowWidth - 2 * h, d = g.windowHeight, e > r ? (s = (n = r) * t / e, o.imageWidth = n,
  32. o.imageheight = s) : (o.imageWidth = e, o.imageheight = t);
  33. }
  34. }), o;
  35. }
  36. var d = e(require("./showdown.js")), n = e(require("./html2json.js"));
  37. module.exports = {
  38. wxParse: function() {
  39. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "wxParseData", i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "html", r = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : '<div class="color:red;">数据不能为空</div>', s = arguments[3], o = arguments[4], g = s, h = {};
  40. if ("html" == i) h = n.default.html2json(r, e); else if ("md" == i || "markdown" == i) {
  41. var m = new d.default.Converter().makeHtml(r);
  42. h = n.default.html2json(m, e);
  43. }
  44. h.view = {}, h.view.imagePadding = 0, void 0 !== o && (h.view.imagePadding = o);
  45. var l = {};
  46. l[e] = h, g.setData(l), g.wxParseImgLoad = a, g.wxParseImgTap = t;
  47. },
  48. wxParseTemArray: function(e, t, a, i) {
  49. for (var r = [], d = i.data, n = null, s = 0; s < a; s++) {
  50. var o = d[t + s].nodes;
  51. r.push(o);
  52. }
  53. e = e || "wxParseTemArray", (n = JSON.parse('{"' + e + '":""}'))[e] = r, i.setData(n);
  54. },
  55. emojisInit: function() {
  56. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "/wxParse/emojis/", a = arguments[2];
  57. n.default.emojisInit(e, t, a);
  58. }
  59. };