app-renderjs.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. var __renderjsModules={};
  2. __renderjsModules["0db65775"] = (() => {
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __hasOwnProp = Object.prototype.hasOwnProperty;
  7. var __export = (target, all) => {
  8. for (var name in all)
  9. __defProp(target, name, { get: all[name], enumerable: true });
  10. };
  11. var __copyProps = (to, from, except, desc) => {
  12. if (from && typeof from === "object" || typeof from === "function") {
  13. for (let key of __getOwnPropNames(from))
  14. if (!__hasOwnProp.call(to, key) && key !== except)
  15. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  16. }
  17. return to;
  18. };
  19. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  20. // <stdin>
  21. var stdin_exports = {};
  22. __export(stdin_exports, {
  23. default: () => stdin_default
  24. });
  25. // node_modules/.pnpm/@dcloudio+uni-ui@1.4.23/node_modules/@dcloudio/uni-ui/lib/uni-swipe-action-item/render.js
  26. var MIN_DISTANCE = 10;
  27. var render_default = {
  28. showWatch(newVal, oldVal, ownerInstance, instance, self) {
  29. var state = self.state;
  30. var $el = ownerInstance.$el || ownerInstance.$vm && ownerInstance.$vm.$el;
  31. if (!$el)
  32. return;
  33. this.getDom(instance, ownerInstance, self);
  34. if (newVal && newVal !== "none") {
  35. this.openState(newVal, instance, ownerInstance, self);
  36. return;
  37. }
  38. if (state.left) {
  39. this.openState("none", instance, ownerInstance, self);
  40. }
  41. this.resetTouchStatus(instance, self);
  42. },
  43. /**
  44. * 开始触摸操作
  45. * @param {Object} e
  46. * @param {Object} ins
  47. */
  48. touchstart(e, ownerInstance, self) {
  49. let instance = e.instance;
  50. let disabled = instance.getDataset().disabled;
  51. let state = self.state;
  52. this.getDom(instance, ownerInstance, self);
  53. disabled = this.getDisabledType(disabled);
  54. if (disabled)
  55. return;
  56. instance.requestAnimationFrame(function() {
  57. instance.removeClass("ani");
  58. ownerInstance.callMethod("closeSwipe");
  59. });
  60. state.x = state.left || 0;
  61. this.stopTouchStart(e, ownerInstance, self);
  62. },
  63. /**
  64. * 开始滑动操作
  65. * @param {Object} e
  66. * @param {Object} ownerInstance
  67. */
  68. touchmove(e, ownerInstance, self) {
  69. let instance = e.instance;
  70. if (!instance)
  71. return;
  72. let disabled = instance.getDataset().disabled;
  73. let state = self.state;
  74. disabled = this.getDisabledType(disabled);
  75. if (disabled)
  76. return;
  77. this.stopTouchMove(e, self);
  78. if (state.direction !== "horizontal") {
  79. return;
  80. }
  81. if (e.preventDefault) {
  82. e.preventDefault();
  83. }
  84. let x = state.x + state.deltaX;
  85. this.move(x, instance, ownerInstance, self);
  86. },
  87. /**
  88. * 结束触摸操作
  89. * @param {Object} e
  90. * @param {Object} ownerInstance
  91. */
  92. touchend(e, ownerInstance, self) {
  93. let instance = e.instance;
  94. let disabled = instance.getDataset().disabled;
  95. let state = self.state;
  96. disabled = this.getDisabledType(disabled);
  97. if (disabled)
  98. return;
  99. this.moveDirection(state.left, instance, ownerInstance, self);
  100. },
  101. /**
  102. * 设置移动距离
  103. * @param {Object} value
  104. * @param {Object} instance
  105. * @param {Object} ownerInstance
  106. */
  107. move(value, instance, ownerInstance, self) {
  108. value = value || 0;
  109. let state = self.state;
  110. let leftWidth = state.leftWidth;
  111. let rightWidth = state.rightWidth;
  112. state.left = this.range(value, -rightWidth, leftWidth);
  113. instance.requestAnimationFrame(function() {
  114. instance.setStyle({
  115. transform: "translateX(" + state.left + "px)",
  116. "-webkit-transform": "translateX(" + state.left + "px)"
  117. });
  118. });
  119. },
  120. /**
  121. * 获取元素信息
  122. * @param {Object} instance
  123. * @param {Object} ownerInstance
  124. */
  125. getDom(instance, ownerInstance, self) {
  126. var state = self.state;
  127. var $el = ownerInstance.$el || ownerInstance.$vm && ownerInstance.$vm.$el;
  128. var leftDom = $el.querySelector(".button-group--left");
  129. var rightDom = $el.querySelector(".button-group--right");
  130. state.leftWidth = leftDom.offsetWidth || 0;
  131. state.rightWidth = rightDom.offsetWidth || 0;
  132. state.threshold = instance.getDataset().threshold;
  133. },
  134. getDisabledType(value) {
  135. return (typeof value === "string" ? JSON.parse(value) : value) || false;
  136. },
  137. /**
  138. * 获取范围
  139. * @param {Object} num
  140. * @param {Object} min
  141. * @param {Object} max
  142. */
  143. range(num, min, max) {
  144. return Math.min(Math.max(num, min), max);
  145. },
  146. /**
  147. * 移动方向判断
  148. * @param {Object} left
  149. * @param {Object} value
  150. * @param {Object} ownerInstance
  151. * @param {Object} ins
  152. */
  153. moveDirection(left, ins, ownerInstance, self) {
  154. var state = self.state;
  155. var threshold = state.threshold;
  156. var position = state.position;
  157. var isopen = state.isopen || "none";
  158. var leftWidth = state.leftWidth;
  159. var rightWidth = state.rightWidth;
  160. if (state.deltaX === 0) {
  161. this.openState("none", ins, ownerInstance, self);
  162. return;
  163. }
  164. if (isopen === "none" && rightWidth > 0 && -left > threshold || isopen !== "none" && rightWidth > 0 && rightWidth + left < threshold) {
  165. this.openState("right", ins, ownerInstance, self);
  166. } else if (isopen === "none" && leftWidth > 0 && left > threshold || isopen !== "none" && leftWidth > 0 && leftWidth - left < threshold) {
  167. this.openState("left", ins, ownerInstance, self);
  168. } else {
  169. this.openState("none", ins, ownerInstance, self);
  170. }
  171. },
  172. /**
  173. * 开启状态
  174. * @param {Boolean} type
  175. * @param {Object} ins
  176. * @param {Object} ownerInstance
  177. */
  178. openState(type, ins, ownerInstance, self) {
  179. let state = self.state;
  180. let leftWidth = state.leftWidth;
  181. let rightWidth = state.rightWidth;
  182. let left = "";
  183. state.isopen = state.isopen ? state.isopen : "none";
  184. switch (type) {
  185. case "left":
  186. left = leftWidth;
  187. break;
  188. case "right":
  189. left = -rightWidth;
  190. break;
  191. default:
  192. left = 0;
  193. }
  194. if (state.isopen !== type) {
  195. state.throttle = true;
  196. ownerInstance.callMethod("change", {
  197. open: type
  198. });
  199. }
  200. state.isopen = type;
  201. ins.requestAnimationFrame(() => {
  202. ins.addClass("ani");
  203. this.move(left, ins, ownerInstance, self);
  204. });
  205. },
  206. getDirection(x, y) {
  207. if (x > y && x > MIN_DISTANCE) {
  208. return "horizontal";
  209. }
  210. if (y > x && y > MIN_DISTANCE) {
  211. return "vertical";
  212. }
  213. return "";
  214. },
  215. /**
  216. * 重置滑动状态
  217. * @param {Object} event
  218. */
  219. resetTouchStatus(instance, self) {
  220. let state = self.state;
  221. state.direction = "";
  222. state.deltaX = 0;
  223. state.deltaY = 0;
  224. state.offsetX = 0;
  225. state.offsetY = 0;
  226. },
  227. /**
  228. * 设置滑动开始位置
  229. * @param {Object} event
  230. */
  231. stopTouchStart(event, ownerInstance, self) {
  232. let instance = event.instance;
  233. let state = self.state;
  234. this.resetTouchStatus(instance, self);
  235. var touch = event.touches[0];
  236. state.startX = touch.clientX;
  237. state.startY = touch.clientY;
  238. },
  239. /**
  240. * 滑动中,是否禁止打开
  241. * @param {Object} event
  242. */
  243. stopTouchMove(event, self) {
  244. let instance = event.instance;
  245. let state = self.state;
  246. let touch = event.touches[0];
  247. state.deltaX = touch.clientX - state.startX;
  248. state.deltaY = touch.clientY - state.startY;
  249. state.offsetY = Math.abs(state.deltaY);
  250. state.offsetX = Math.abs(state.deltaX);
  251. state.direction = state.direction || this.getDirection(state.offsetX, state.offsetY);
  252. }
  253. };
  254. // <stdin>
  255. var stdin_default = {
  256. mounted(e, ins, owner) {
  257. this.state = {};
  258. },
  259. methods: {
  260. showWatch(newVal, oldVal, ownerInstance, instance) {
  261. render_default.showWatch(newVal, oldVal, ownerInstance, instance, this);
  262. },
  263. touchstart(e, ownerInstance) {
  264. render_default.touchstart(e, ownerInstance, this);
  265. },
  266. touchmove(e, ownerInstance) {
  267. render_default.touchmove(e, ownerInstance, this);
  268. },
  269. touchend(e, ownerInstance) {
  270. render_default.touchend(e, ownerInstance, this);
  271. }
  272. }
  273. };
  274. return __toCommonJS(stdin_exports);
  275. })();