utils.js 2.0 KB

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