utils.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. /**
  3. * 把支付宝的e转成对等的微信e
  4. */
  5. function antmoveAction(e) {
  6. var wxEvent = {
  7. currentTarget: e.currentTarget,
  8. target: e.target,
  9. type: e.type.toLowerCase(),
  10. changedTouches: e.changedTouches,
  11. touches: e.touches,
  12. timeStamp: e.timeStamp
  13. };
  14. var eventDetail = e.detail || {};
  15. var pageX = eventDetail.pageX,
  16. pageY = eventDetail.pageY;
  17. if (!wxEvent.changedTouches) {
  18. wxEvent.changedTouches = [e.detail];
  19. }
  20. if (!wxEvent.touches) {
  21. wxEvent.touches = [e.detail];
  22. }
  23. if (typeof pageX !== 'undefined' && typeof pageY !== 'undefined') {
  24. wxEvent.detail = {
  25. x: pageX,
  26. y: pageY
  27. };
  28. } else {
  29. wxEvent.detail = eventDetail;
  30. }
  31. var userFnName = "antmove".concat(wxEvent.type.replace(/^\w/, function ($1) {
  32. return $1.toUpperCase();
  33. }));
  34. var userFn = e.currentTarget.dataset[userFnName];
  35. if (!userFn || !this[userFn]) {
  36. console.warn("does not have a method \"".concat(userFnName, "\" to handle event \"").concat(wxEvent.type, "\""));
  37. return;
  38. }
  39. delete e.currentTarget.dataset[userFnName];
  40. this[userFn](wxEvent);
  41. }
  42. module.exports = {
  43. connectNodes: function connectNodes(node, ast) {
  44. if (!node.$relationNode.$parent) {
  45. return false;
  46. }
  47. var parentNodeId = node.$relationNode.$parent.$id;
  48. var parentNodeRoute = node.$relationNode.$parent.$route;
  49. var refNumbers = node.$self.props.refNumbers && node.$self.props.refNumbers.length || 1;
  50. var parentArray = ast.$refNodes[parentNodeRoute][parentNodeId];
  51. var parent = null;
  52. if (refNumbers > 1) {
  53. parentArray.forEach(function (_parent) {
  54. if (_parent.$children.length < refNumbers && !parent) {
  55. parent = _parent;
  56. return true;
  57. }
  58. });
  59. } else {
  60. parent = parentArray[parentArray.length - 1];
  61. }
  62. if (parent) {
  63. node.setParent(parent);
  64. }
  65. },
  66. setIfWatch: setIfWatch,
  67. antmoveAction: antmoveAction
  68. };
  69. function setIfWatch(res) {
  70. my.setStorageSync({
  71. key: 'ifWatch',
  72. data: res
  73. });
  74. }