app-wxs.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. var __wxsModules={};
  2. __wxsModules["30f4e25a"] = (() => {
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __commonJS = (cb, mod) => function __require() {
  5. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  6. };
  7. // <stdin>
  8. var require_stdin = __commonJS({
  9. "<stdin>"(exports, module) {
  10. var me = {};
  11. me.onMoving = function(ins, rate, downHight) {
  12. ins.requestAnimationFrame(function() {
  13. ins.selectComponent(".mescroll-wxs-content").setStyle({
  14. "will-change": "transform",
  15. // 可解决下拉过程中, image和swiper脱离文档流的问题
  16. "transform": "translateY(" + downHight + "px)",
  17. "transition": ""
  18. });
  19. var progress = ins.selectComponent(".mescroll-wxs-progress");
  20. progress && progress.setStyle({ transform: "rotate(" + 360 * rate + "deg)" });
  21. });
  22. };
  23. me.showLoading = function(ins) {
  24. me.downHight = me.optDown.offset;
  25. ins.requestAnimationFrame(function() {
  26. ins.selectComponent(".mescroll-wxs-content").setStyle({
  27. "will-change": "auto",
  28. "transform": "translateY(" + me.downHight + "px)",
  29. "transition": "transform 300ms"
  30. });
  31. });
  32. };
  33. me.endDownScroll = function(ins) {
  34. me.downHight = 0;
  35. me.isDownScrolling = false;
  36. ins.requestAnimationFrame(function() {
  37. ins.selectComponent(".mescroll-wxs-content").setStyle({
  38. "will-change": "auto",
  39. "transform": "translateY(0)",
  40. // 不可以写空串,否则scroll-view渲染不完整 (延时350ms会调clearTransform置空)
  41. "transition": "transform 300ms"
  42. });
  43. });
  44. };
  45. me.clearTransform = function(ins) {
  46. ins.requestAnimationFrame(function() {
  47. ins.selectComponent(".mescroll-wxs-content").setStyle({
  48. "will-change": "",
  49. "transform": "",
  50. "transition": ""
  51. });
  52. });
  53. };
  54. function propObserver(wxsProp) {
  55. me.optDown = wxsProp.optDown;
  56. me.scrollTop = wxsProp.scrollTop;
  57. me.bodyHeight = wxsProp.bodyHeight;
  58. me.isDownScrolling = wxsProp.isDownScrolling;
  59. me.isUpScrolling = wxsProp.isUpScrolling;
  60. me.isUpBoth = wxsProp.isUpBoth;
  61. me.isScrollBody = wxsProp.isScrollBody;
  62. me.startTop = wxsProp.scrollTop;
  63. }
  64. function callObserver(callProp, oldValue, ins) {
  65. if (me.disabled())
  66. return;
  67. if (callProp.callType) {
  68. if (callProp.callType === "showLoading") {
  69. me.showLoading(ins);
  70. } else if (callProp.callType === "endDownScroll") {
  71. me.endDownScroll(ins);
  72. } else if (callProp.callType === "clearTransform") {
  73. me.clearTransform(ins);
  74. }
  75. }
  76. }
  77. function touchstartEvent(e, ins) {
  78. me.downHight = 0;
  79. me.startPoint = me.getPoint(e);
  80. me.startTop = me.getScrollTop();
  81. me.startAngle = 0;
  82. me.lastPoint = me.startPoint;
  83. me.maxTouchmoveY = me.getBodyHeight() - me.optDown.bottomOffset;
  84. me.inTouchend = false;
  85. me.callMethod(ins, { type: "setWxsProp" });
  86. }
  87. function touchmoveEvent(e, ins) {
  88. var isPrevent = true;
  89. if (me.disabled())
  90. return isPrevent;
  91. var scrollTop = me.getScrollTop();
  92. var curPoint = me.getPoint(e);
  93. var moveY = curPoint.y - me.startPoint.y;
  94. if (moveY > 0 && (me.isScrollBody && scrollTop <= 0 || !me.isScrollBody && (scrollTop <= 0 || scrollTop <= me.optDown.startTop && scrollTop === me.startTop))) {
  95. if (!me.inTouchend && !me.isDownScrolling && !me.optDown.isLock && (!me.isUpScrolling || me.isUpScrolling && me.isUpBoth)) {
  96. if (!me.startAngle)
  97. me.startAngle = me.getAngle(me.lastPoint, curPoint);
  98. if (me.startAngle < me.optDown.minAngle)
  99. return isPrevent;
  100. if (me.maxTouchmoveY > 0 && curPoint.y >= me.maxTouchmoveY) {
  101. me.inTouchend = true;
  102. touchendEvent(e, ins);
  103. return isPrevent;
  104. }
  105. isPrevent = false;
  106. var diff = curPoint.y - me.lastPoint.y;
  107. if (me.downHight < me.optDown.offset) {
  108. if (me.movetype !== 1) {
  109. me.movetype = 1;
  110. me.callMethod(ins, { type: "setLoadType", downLoadType: 1 });
  111. me.isMoveDown = true;
  112. }
  113. me.downHight += diff * me.optDown.inOffsetRate;
  114. } else {
  115. if (me.movetype !== 2) {
  116. me.movetype = 2;
  117. me.callMethod(ins, { type: "setLoadType", downLoadType: 2 });
  118. me.isMoveDown = true;
  119. }
  120. if (diff > 0) {
  121. me.downHight += diff * me.optDown.outOffsetRate;
  122. } else {
  123. me.downHight += diff;
  124. }
  125. }
  126. me.downHight = Math.round(me.downHight);
  127. var rate = me.downHight / me.optDown.offset;
  128. me.onMoving(ins, rate, me.downHight);
  129. }
  130. }
  131. me.lastPoint = curPoint;
  132. return isPrevent;
  133. }
  134. function touchendEvent(e, ins) {
  135. if (me.isMoveDown) {
  136. if (me.downHight >= me.optDown.offset) {
  137. me.downHight = me.optDown.offset;
  138. me.callMethod(ins, { type: "triggerDownScroll" });
  139. } else {
  140. me.downHight = 0;
  141. me.callMethod(ins, { type: "endDownScroll" });
  142. }
  143. me.movetype = 0;
  144. me.isMoveDown = false;
  145. } else if (!me.isScrollBody && me.getScrollTop() === me.startTop) {
  146. var isScrollUp = me.getPoint(e).y - me.startPoint.y < 0;
  147. if (isScrollUp) {
  148. var angle = me.getAngle(me.getPoint(e), me.startPoint);
  149. if (angle > 80) {
  150. me.callMethod(ins, { type: "triggerUpScroll" });
  151. }
  152. }
  153. }
  154. me.callMethod(ins, { type: "setWxsProp" });
  155. }
  156. me.disabled = function() {
  157. return !me.optDown || !me.optDown.use || me.optDown.native;
  158. };
  159. me.getPoint = function(e) {
  160. if (!e) {
  161. return { x: 0, y: 0 };
  162. }
  163. if (e.touches && e.touches[0]) {
  164. return { x: e.touches[0].pageX, y: e.touches[0].pageY };
  165. } else if (e.changedTouches && e.changedTouches[0]) {
  166. return { x: e.changedTouches[0].pageX, y: e.changedTouches[0].pageY };
  167. } else {
  168. return { x: e.clientX, y: e.clientY };
  169. }
  170. };
  171. me.getAngle = function(p1, p2) {
  172. var x = Math.abs(p1.x - p2.x);
  173. var y = Math.abs(p1.y - p2.y);
  174. var z = Math.sqrt(x * x + y * y);
  175. var angle = 0;
  176. if (z !== 0) {
  177. angle = Math.asin(y / z) / Math.PI * 180;
  178. }
  179. return angle;
  180. };
  181. me.getScrollTop = function() {
  182. return me.scrollTop || 0;
  183. };
  184. me.getBodyHeight = function() {
  185. return me.bodyHeight || 0;
  186. };
  187. me.callMethod = function(ins, param) {
  188. if (ins)
  189. ins.callMethod("wxsCall", param);
  190. };
  191. module.exports = {
  192. propObserver,
  193. callObserver,
  194. touchstartEvent,
  195. touchmoveEvent,
  196. touchendEvent
  197. };
  198. }
  199. });
  200. return require_stdin();
  201. })();
  202. __wxsModules["174adfb2"] = (() => {
  203. var __getOwnPropNames = Object.getOwnPropertyNames;
  204. var __commonJS = (cb, mod) => function __require() {
  205. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  206. };
  207. // <stdin>
  208. var require_stdin = __commonJS({
  209. "<stdin>"(exports, module) {
  210. var inlineTags = {
  211. abbr: true,
  212. b: true,
  213. big: true,
  214. code: true,
  215. del: true,
  216. em: true,
  217. i: true,
  218. ins: true,
  219. label: true,
  220. q: true,
  221. small: true,
  222. span: true,
  223. strong: true,
  224. sub: true,
  225. sup: true
  226. };
  227. module.exports = {
  228. isInline: function(tagName, style) {
  229. return inlineTags[tagName] || (style || "").indexOf("display:inline") !== -1;
  230. }
  231. };
  232. }
  233. });
  234. return require_stdin();
  235. })();