app-wxs.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. if (!wxsProp)
  56. return;
  57. me.optDown = wxsProp.optDown;
  58. me.scrollTop = wxsProp.scrollTop;
  59. me.bodyHeight = wxsProp.bodyHeight;
  60. me.isDownScrolling = wxsProp.isDownScrolling;
  61. me.isUpScrolling = wxsProp.isUpScrolling;
  62. me.isUpBoth = wxsProp.isUpBoth;
  63. me.isScrollBody = wxsProp.isScrollBody;
  64. me.startTop = wxsProp.scrollTop;
  65. }
  66. function callObserver(callProp, oldValue, ins) {
  67. if (me.disabled())
  68. return;
  69. if (callProp.callType) {
  70. if (callProp.callType === "showLoading") {
  71. me.showLoading(ins);
  72. } else if (callProp.callType === "endDownScroll") {
  73. me.endDownScroll(ins);
  74. } else if (callProp.callType === "clearTransform") {
  75. me.clearTransform(ins);
  76. }
  77. }
  78. }
  79. function touchstartEvent(e, ins) {
  80. me.downHight = 0;
  81. me.startPoint = me.getPoint(e);
  82. me.startTop = me.getScrollTop();
  83. me.startAngle = 0;
  84. me.lastPoint = me.startPoint;
  85. me.maxTouchmoveY = me.getBodyHeight() - me.optDown.bottomOffset;
  86. me.inTouchend = false;
  87. me.callMethod(ins, { type: "setWxsProp" });
  88. }
  89. function touchmoveEvent(e, ins) {
  90. var isPrevent = true;
  91. if (me.disabled())
  92. return isPrevent;
  93. var scrollTop = me.getScrollTop();
  94. var curPoint = me.getPoint(e);
  95. var moveY = curPoint.y - me.startPoint.y;
  96. if (moveY > 0 && (me.isScrollBody && scrollTop <= 0 || !me.isScrollBody && (scrollTop <= 0 || scrollTop <= me.optDown.startTop && scrollTop === me.startTop))) {
  97. if (!me.inTouchend && !me.isDownScrolling && !me.optDown.isLock && (!me.isUpScrolling || me.isUpScrolling && me.isUpBoth)) {
  98. if (!me.startAngle)
  99. me.startAngle = me.getAngle(me.lastPoint, curPoint);
  100. if (me.startAngle < me.optDown.minAngle)
  101. return isPrevent;
  102. if (me.maxTouchmoveY > 0 && curPoint.y >= me.maxTouchmoveY) {
  103. me.inTouchend = true;
  104. touchendEvent(e, ins);
  105. return isPrevent;
  106. }
  107. isPrevent = false;
  108. var diff = curPoint.y - me.lastPoint.y;
  109. if (me.downHight < me.optDown.offset) {
  110. if (me.movetype !== 1) {
  111. me.movetype = 1;
  112. me.callMethod(ins, { type: "setLoadType", downLoadType: 1 });
  113. me.isMoveDown = true;
  114. }
  115. me.downHight += diff * me.optDown.inOffsetRate;
  116. } else {
  117. if (me.movetype !== 2) {
  118. me.movetype = 2;
  119. me.callMethod(ins, { type: "setLoadType", downLoadType: 2 });
  120. me.isMoveDown = true;
  121. }
  122. if (diff > 0) {
  123. me.downHight += diff * me.optDown.outOffsetRate;
  124. } else {
  125. me.downHight += diff;
  126. }
  127. }
  128. me.downHight = Math.round(me.downHight);
  129. var rate = me.downHight / me.optDown.offset;
  130. me.onMoving(ins, rate, me.downHight);
  131. }
  132. }
  133. me.lastPoint = curPoint;
  134. return isPrevent;
  135. }
  136. function touchendEvent(e, ins) {
  137. if (me.isMoveDown) {
  138. if (me.downHight >= me.optDown.offset) {
  139. me.downHight = me.optDown.offset;
  140. me.callMethod(ins, { type: "triggerDownScroll" });
  141. } else {
  142. me.downHight = 0;
  143. me.callMethod(ins, { type: "endDownScroll" });
  144. }
  145. me.movetype = 0;
  146. me.isMoveDown = false;
  147. } else if (!me.isScrollBody && me.getScrollTop() === me.startTop) {
  148. var isScrollUp = me.getPoint(e).y - me.startPoint.y < 0;
  149. if (isScrollUp) {
  150. var angle = me.getAngle(me.getPoint(e), me.startPoint);
  151. if (angle > 80) {
  152. me.callMethod(ins, { type: "triggerUpScroll" });
  153. }
  154. }
  155. }
  156. me.callMethod(ins, { type: "setWxsProp" });
  157. }
  158. me.disabled = function() {
  159. return !me.optDown || !me.optDown.use || me.optDown.native;
  160. };
  161. me.getPoint = function(e) {
  162. if (!e) {
  163. return { x: 0, y: 0 };
  164. }
  165. if (e.touches && e.touches[0]) {
  166. return { x: e.touches[0].pageX, y: e.touches[0].pageY };
  167. } else if (e.changedTouches && e.changedTouches[0]) {
  168. return { x: e.changedTouches[0].pageX, y: e.changedTouches[0].pageY };
  169. } else {
  170. return { x: e.clientX, y: e.clientY };
  171. }
  172. };
  173. me.getAngle = function(p1, p2) {
  174. var x = Math.abs(p1.x - p2.x);
  175. var y = Math.abs(p1.y - p2.y);
  176. var z = Math.sqrt(x * x + y * y);
  177. var angle = 0;
  178. if (z !== 0) {
  179. angle = Math.asin(y / z) / Math.PI * 180;
  180. }
  181. return angle;
  182. };
  183. me.getScrollTop = function() {
  184. return me.scrollTop || 0;
  185. };
  186. me.getBodyHeight = function() {
  187. return me.bodyHeight || 0;
  188. };
  189. me.callMethod = function(ins, param) {
  190. if (ins)
  191. ins.callMethod("wxsCall", param);
  192. };
  193. module.exports = {
  194. propObserver,
  195. callObserver,
  196. touchstartEvent,
  197. touchmoveEvent,
  198. touchendEvent
  199. };
  200. }
  201. });
  202. return require_stdin();
  203. })();
  204. __wxsModules.f1d6d7d8 = (() => {
  205. var __getOwnPropNames = Object.getOwnPropertyNames;
  206. var __commonJS = (cb, mod) => function __require() {
  207. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  208. };
  209. // <stdin>
  210. var require_stdin = __commonJS({
  211. "<stdin>"(exports, module) {
  212. function touchstart(event, ownerInstance) {
  213. var instance = event.instance;
  214. var state = instance.getState();
  215. if (state.disabled)
  216. return;
  217. var touches = event.touches;
  218. if (touches && touches.length > 1)
  219. return;
  220. state.moving = true;
  221. state.startX = touches[0].pageX;
  222. state.startY = touches[0].pageY;
  223. ownerInstance.callMethod("closeOther");
  224. }
  225. function touchmove(event, ownerInstance) {
  226. var instance = event.instance;
  227. var state = instance.getState();
  228. if (state.disabled || !state.moving)
  229. return;
  230. var touches = event.touches;
  231. var pageX = touches[0].pageX;
  232. var pageY = touches[0].pageY;
  233. var moveX = pageX - state.startX;
  234. var moveY = pageY - state.startY;
  235. var buttonsWidth = state.buttonsWidth;
  236. if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > state.threshold) {
  237. event.preventDefault && event.preventDefault();
  238. event.stopPropagation && event.stopPropagation();
  239. }
  240. if (Math.abs(moveX) < Math.abs(moveY))
  241. return;
  242. if (state.status === "open") {
  243. if (moveX < 0)
  244. moveX = 0;
  245. if (moveX > buttonsWidth)
  246. moveX = buttonsWidth;
  247. moveSwipeAction(-buttonsWidth + moveX, instance, ownerInstance);
  248. } else {
  249. if (moveX > 0)
  250. moveX = 0;
  251. if (Math.abs(moveX) > buttonsWidth)
  252. moveX = -buttonsWidth;
  253. moveSwipeAction(moveX, instance, ownerInstance);
  254. }
  255. }
  256. function touchend(event, ownerInstance) {
  257. var instance = event.instance;
  258. var state = instance.getState();
  259. if (!state.moving || state.disabled)
  260. return;
  261. var touches = event.changedTouches ? event.changedTouches[0] : {};
  262. var pageX = touches.pageX;
  263. var pageY = touches.pageY;
  264. var moveX = pageX - state.startX;
  265. if (state.status === "open") {
  266. if (moveX < 0)
  267. return;
  268. if (moveX === 0) {
  269. return closeSwipeAction(instance, ownerInstance);
  270. }
  271. if (Math.abs(moveX) < state.threshold) {
  272. openSwipeAction(instance, ownerInstance);
  273. } else {
  274. closeSwipeAction(instance, ownerInstance);
  275. }
  276. } else {
  277. if (moveX > 0)
  278. return;
  279. if (Math.abs(moveX) < state.threshold) {
  280. closeSwipeAction(instance, ownerInstance);
  281. } else {
  282. openSwipeAction(instance, ownerInstance);
  283. }
  284. }
  285. }
  286. function getDuration(value) {
  287. if (value.toString().indexOf("s") >= 0)
  288. return value;
  289. return value > 30 ? value + "ms" : value + "s";
  290. }
  291. function moveSwipeAction(moveX, instance, ownerInstance) {
  292. var state = instance.getState();
  293. var buttons = ownerInstance.selectAllComponents(".u-swipe-action-item__right__button");
  294. instance.requestAnimationFrame(function() {
  295. instance.setStyle({
  296. // 设置translateX的值
  297. "transition": "none",
  298. transform: "translateX(" + moveX + "px)",
  299. "-webkit-transform": "translateX(" + moveX + "px)"
  300. });
  301. });
  302. }
  303. function openSwipeAction(instance, ownerInstance) {
  304. var state = instance.getState();
  305. var buttons = ownerInstance.selectAllComponents(".u-swipe-action-item__right__button");
  306. var duration = getDuration(state.duration);
  307. var buttonsWidth = -state.buttonsWidth;
  308. instance.requestAnimationFrame(function() {
  309. instance.setStyle({
  310. "transition": "transform " + duration,
  311. "transform": "translateX(" + buttonsWidth + "px)",
  312. "-webkit-transform": "translateX(" + buttonsWidth + "px)"
  313. });
  314. });
  315. setStatus("open", instance, ownerInstance);
  316. }
  317. function setStatus(status, instance, ownerInstance) {
  318. var state = instance.getState();
  319. state.status = status;
  320. ownerInstance.callMethod("setState", status);
  321. }
  322. function closeSwipeAction(instance, ownerInstance) {
  323. var state = instance.getState();
  324. var buttons = ownerInstance.selectAllComponents(".u-swipe-action-item__right__button");
  325. var len = buttons.length;
  326. var duration = getDuration(state.duration);
  327. instance.requestAnimationFrame(function() {
  328. instance.setStyle({
  329. "transition": "transform " + duration,
  330. "transform": "translateX(0px)",
  331. "-webkit-transform": "translateX(0px)"
  332. });
  333. for (var i = len - 1; i >= 0; i--) {
  334. buttons[i].setStyle({
  335. "transition": "transform " + duration,
  336. "transform": "translateX(0px)",
  337. "-webkit-transform": "translateX(0px)"
  338. });
  339. }
  340. });
  341. setStatus("close", instance, ownerInstance);
  342. }
  343. function statusChange(newValue, oldValue, ownerInstance, instance) {
  344. var state = instance.getState();
  345. if (state.disabled)
  346. return;
  347. if (newValue === "close" && state.status === "open") {
  348. closeSwipeAction(instance, ownerInstance);
  349. } else if (newValue === "open" && state.status === "close") {
  350. openSwipeAction(instance, ownerInstance);
  351. }
  352. }
  353. function sizeChange(newValue, oldValue, ownerInstance, instance) {
  354. var state = instance.getState();
  355. state.disabled = newValue.disabled;
  356. state.duration = newValue.duration;
  357. state.show = newValue.show;
  358. state.threshold = newValue.threshold;
  359. state.buttons = newValue.buttons;
  360. if (state.buttons) {
  361. var len = state.buttons.length;
  362. var buttonsWidth = 0;
  363. var buttons = newValue.buttons;
  364. for (var i = 0; i < len; i++) {
  365. buttonsWidth += buttons[i].width;
  366. }
  367. }
  368. state.buttonsWidth = buttonsWidth;
  369. }
  370. module.exports = {
  371. touchstart,
  372. touchmove,
  373. touchend,
  374. sizeChange,
  375. statusChange
  376. };
  377. }
  378. });
  379. return require_stdin();
  380. })();