app-wxs.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. var __wxsModules={};
  2. __wxsModules["105aa6f4"] = (() => {
  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 MIN_DISTANCE = 10;
  11. var IS_HTML5 = false;
  12. if (typeof window === "object")
  13. IS_HTML5 = true;
  14. function showWatch(newVal, oldVal, ownerInstance, instance) {
  15. var state = instance.getState();
  16. getDom(instance, ownerInstance);
  17. if (newVal && newVal !== "none") {
  18. openState(newVal, instance, ownerInstance);
  19. return;
  20. }
  21. if (state.left) {
  22. openState("none", instance, ownerInstance);
  23. }
  24. resetTouchStatus(instance);
  25. }
  26. function touchstart(e, ownerInstance) {
  27. var instance = e.instance;
  28. var disabled = instance.getDataset().disabled;
  29. var state = instance.getState();
  30. getDom(instance, ownerInstance);
  31. disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
  32. if (disabled)
  33. return;
  34. instance.requestAnimationFrame(function() {
  35. instance.removeClass("ani");
  36. ownerInstance.callMethod("closeSwipe");
  37. });
  38. state.x = state.left || 0;
  39. stopTouchStart(e, ownerInstance);
  40. }
  41. function touchmove(e, ownerInstance) {
  42. var instance = e.instance;
  43. var disabled = instance.getDataset().disabled;
  44. var state = instance.getState();
  45. disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
  46. if (disabled)
  47. return;
  48. stopTouchMove(e);
  49. if (state.direction !== "horizontal") {
  50. return;
  51. }
  52. if (e.preventDefault) {
  53. e.preventDefault();
  54. }
  55. move(state.x + state.deltaX, instance, ownerInstance);
  56. }
  57. function touchend(e, ownerInstance) {
  58. var instance = e.instance;
  59. var disabled = instance.getDataset().disabled;
  60. var state = instance.getState();
  61. disabled = (typeof disabled === "string" ? JSON.parse(disabled) : disabled) || false;
  62. if (disabled)
  63. return;
  64. moveDirection(state.left, instance, ownerInstance);
  65. }
  66. function move(value, instance, ownerInstance) {
  67. value = value || 0;
  68. var state = instance.getState();
  69. var leftWidth = state.leftWidth;
  70. var rightWidth = state.rightWidth;
  71. state.left = range(value, -rightWidth, leftWidth);
  72. instance.requestAnimationFrame(function() {
  73. instance.setStyle({
  74. transform: "translateX(" + state.left + "px)",
  75. "-webkit-transform": "translateX(" + state.left + "px)"
  76. });
  77. });
  78. }
  79. function getDom(instance, ownerInstance) {
  80. var state = instance.getState();
  81. var leftDom = ownerInstance.selectComponent(".button-group--left");
  82. var rightDom = ownerInstance.selectComponent(".button-group--right");
  83. var leftStyles = {
  84. width: 0
  85. };
  86. var rightStyles = {
  87. width: 0
  88. };
  89. leftStyles = leftDom.getBoundingClientRect();
  90. rightStyles = rightDom.getBoundingClientRect();
  91. state.leftWidth = leftStyles.width || 0;
  92. state.rightWidth = rightStyles.width || 0;
  93. state.threshold = instance.getDataset().threshold;
  94. }
  95. function range(num, min, max) {
  96. return Math.min(Math.max(num, min), max);
  97. }
  98. function moveDirection(left, ins, ownerInstance) {
  99. var state = ins.getState();
  100. var threshold = state.threshold;
  101. var position = state.position;
  102. var isopen = state.isopen || "none";
  103. var leftWidth = state.leftWidth;
  104. var rightWidth = state.rightWidth;
  105. if (state.deltaX === 0) {
  106. openState("none", ins, ownerInstance);
  107. return;
  108. }
  109. if (isopen === "none" && rightWidth > 0 && -left > threshold || isopen !== "none" && rightWidth > 0 && rightWidth + left < threshold) {
  110. openState("right", ins, ownerInstance);
  111. } else if (isopen === "none" && leftWidth > 0 && left > threshold || isopen !== "none" && leftWidth > 0 && leftWidth - left < threshold) {
  112. openState("left", ins, ownerInstance);
  113. } else {
  114. openState("none", ins, ownerInstance);
  115. }
  116. }
  117. function openState(type, ins, ownerInstance) {
  118. var state = ins.getState();
  119. var leftWidth = state.leftWidth;
  120. var rightWidth = state.rightWidth;
  121. var left = "";
  122. state.isopen = state.isopen ? state.isopen : "none";
  123. switch (type) {
  124. case "left":
  125. left = leftWidth;
  126. break;
  127. case "right":
  128. left = -rightWidth;
  129. break;
  130. default:
  131. left = 0;
  132. }
  133. if (state.isopen !== type) {
  134. state.throttle = true;
  135. ownerInstance.callMethod("change", {
  136. open: type
  137. });
  138. }
  139. state.isopen = type;
  140. ins.requestAnimationFrame(function() {
  141. ins.addClass("ani");
  142. move(left, ins, ownerInstance);
  143. });
  144. }
  145. function getDirection(x, y) {
  146. if (x > y && x > MIN_DISTANCE) {
  147. return "horizontal";
  148. }
  149. if (y > x && y > MIN_DISTANCE) {
  150. return "vertical";
  151. }
  152. return "";
  153. }
  154. function resetTouchStatus(instance) {
  155. var state = instance.getState();
  156. state.direction = "";
  157. state.deltaX = 0;
  158. state.deltaY = 0;
  159. state.offsetX = 0;
  160. state.offsetY = 0;
  161. }
  162. function stopTouchStart(event) {
  163. var instance = event.instance;
  164. var state = instance.getState();
  165. resetTouchStatus(instance);
  166. var touch = event.touches[0];
  167. if (IS_HTML5 && isPC()) {
  168. touch = event;
  169. }
  170. state.startX = touch.clientX;
  171. state.startY = touch.clientY;
  172. }
  173. function stopTouchMove(event) {
  174. var instance = event.instance;
  175. var state = instance.getState();
  176. var touch = event.touches[0];
  177. if (IS_HTML5 && isPC()) {
  178. touch = event;
  179. }
  180. state.deltaX = touch.clientX - state.startX;
  181. state.deltaY = touch.clientY - state.startY;
  182. state.offsetY = Math.abs(state.deltaY);
  183. state.offsetX = Math.abs(state.deltaX);
  184. state.direction = state.direction || getDirection(state.offsetX, state.offsetY);
  185. }
  186. function isPC() {
  187. var userAgentInfo = navigator.userAgent;
  188. var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
  189. var flag = true;
  190. for (var v = 0; v < Agents.length - 1; v++) {
  191. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  192. flag = false;
  193. break;
  194. }
  195. }
  196. return flag;
  197. }
  198. var movable = false;
  199. function mousedown(e, ins) {
  200. if (!IS_HTML5)
  201. return;
  202. if (!isPC())
  203. return;
  204. touchstart(e, ins);
  205. movable = true;
  206. }
  207. function mousemove(e, ins) {
  208. if (!IS_HTML5)
  209. return;
  210. if (!isPC())
  211. return;
  212. if (!movable)
  213. return;
  214. touchmove(e, ins);
  215. }
  216. function mouseup(e, ins) {
  217. if (!IS_HTML5)
  218. return;
  219. if (!isPC())
  220. return;
  221. touchend(e, ins);
  222. movable = false;
  223. }
  224. function mouseleave(e, ins) {
  225. if (!IS_HTML5)
  226. return;
  227. if (!isPC())
  228. return;
  229. movable = false;
  230. }
  231. module.exports = {
  232. showWatch,
  233. touchstart,
  234. touchmove,
  235. touchend,
  236. mousedown,
  237. mousemove,
  238. mouseup,
  239. mouseleave
  240. };
  241. }
  242. });
  243. return require_stdin();
  244. })();