|
| 1 | +var date = new Date(); |
| 2 | + |
| 3 | +var data_pool; /* dcmlib data pool */ |
| 4 | + |
| 5 | +var TouchMode = { |
| 6 | + cancel: 0, |
| 7 | + press: 1, /* 长按 */ |
| 8 | + move: 2, /* 移动 */ |
| 9 | +} |
| 10 | + |
| 11 | +var app = { |
| 12 | + data: { |
| 13 | + /* 全局设定 */ |
| 14 | + mainPage: 0, |
| 15 | + clockIndex: 2, |
| 16 | + date: new Date(), |
| 17 | + stepCount: 489, |
| 18 | + bpmCount: 100, |
| 19 | + isSaveMode: false, |
| 20 | + language: "中文", |
| 21 | + version: "1.0.2", |
| 22 | + flag: 1, |
| 23 | + }, |
| 24 | + |
| 25 | + page: "pages/main/main", |
| 26 | + /* app 加载完成触发该函数 */ |
| 27 | + onLaunch: function () { |
| 28 | + |
| 29 | + }, |
| 30 | + |
| 31 | + /* app 退出触发该函数 */ |
| 32 | + onExit: function () { |
| 33 | + }, |
| 34 | + |
| 35 | +}; |
| 36 | + |
| 37 | +PageTouchInit = function (page) { |
| 38 | + page.touchStartY = 0; /* panel中触摸的Y坐标 */ |
| 39 | + page.touchStartPosition = 0; /* page中开始触摸的坐标 */ |
| 40 | + page.touchEndPosition = 0; /* page中结束触摸的坐标 */ |
| 41 | + page.touchStatus = TouchMode.cancel; |
| 42 | + page.touchTimer = 0; |
| 43 | + page.navigateEnable = true; |
| 44 | +} |
| 45 | + |
| 46 | +PageTouchUninit = function (page) { |
| 47 | + var that = page; |
| 48 | + if (that.touchTimer != 0) { |
| 49 | + clearInterval(that.touchTimer); |
| 50 | + that.touchTimer = 0; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +PageTouchEvent = function (page, event, longPress, R2L, L2R, T2D, D2T) { |
| 55 | + var that = page; |
| 56 | + var touchItem = event.touchs[0]; |
| 57 | + |
| 58 | + if (touchItem.type == "touchstart") { |
| 59 | + // console.log(" >>> touchStart") |
| 60 | + /* 长按操作 */ |
| 61 | + that.touchStatus = TouchMode.press; |
| 62 | + that.touchStartPosition = { x: touchItem.x, y: touchItem.y }; |
| 63 | + // console.log("that.touchTimer: ", that.touchTimer); |
| 64 | + if (that.touchTimer != 0) { |
| 65 | + clearInterval(that.touchTimer); |
| 66 | + that.touchTimer = 0; |
| 67 | + } |
| 68 | + |
| 69 | + that.touchTimer = setTimeout(function () { |
| 70 | + // console.log(">> long press"); |
| 71 | + clearInterval(that.touchTimer); |
| 72 | + that.touchTimer = 0; |
| 73 | + if (that.touchStatus == TouchMode.press) { |
| 74 | + if (typeof (longPress) == "function") { |
| 75 | + longPress(); |
| 76 | + } |
| 77 | + } |
| 78 | + }, 1000); |
| 79 | + |
| 80 | + } else if (touchItem.type == "touchmove") { |
| 81 | + // console.log(" >>> touch move") |
| 82 | + that.touchStatus = TouchMode.move; |
| 83 | + that.touchEndPosition = { x: touchItem.x, y: touchItem.y }; |
| 84 | + } else if (touchItem.type == "touchend") { |
| 85 | + console.log(" >>> touch end") |
| 86 | + if (that.touchStatus == TouchMode.move) { |
| 87 | + var d_ValueX = that.touchEndPosition.x - that.touchStartPosition.x |
| 88 | + var d_ValueY = that.touchEndPosition.y - that.touchStartPosition.y |
| 89 | + // console.log(" x : " + d_ValueX); |
| 90 | + // console.log(" y : " + d_ValueY); |
| 91 | + // console.log(" that.navigateEnable : " + that.navigateEnable); |
| 92 | + if (d_ValueY > 50 && that.navigateEnable == true) { |
| 93 | + console.log("slide down") |
| 94 | + if (typeof (T2D) == "function") { |
| 95 | + T2D(); |
| 96 | + return; |
| 97 | + } |
| 98 | + } else if (d_ValueY < -50 && that.navigateEnable == true) { |
| 99 | + console.log("slide up") |
| 100 | + if (typeof (D2T) == "function") { |
| 101 | + D2T(); |
| 102 | + return; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + if (d_ValueX > 50 && that.navigateEnable == true) { |
| 107 | + console.log("slide right") |
| 108 | + if (typeof (L2R) == "function") { |
| 109 | + L2R(); |
| 110 | + return; |
| 111 | + } |
| 112 | + } else if (d_ValueX < -50 && that.navigateEnable == true) { |
| 113 | + console.log("slide left") |
| 114 | + if (typeof (R2L) == "function") { |
| 115 | + R2L(); |
| 116 | + return; |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + that.touchStatus = TouchMode.cancel; |
| 121 | + if (that.touchTimer != 0) { |
| 122 | + clearInterval(that.touchTimer); |
| 123 | + that.touchTimer = 0; |
| 124 | + } |
| 125 | + } else if (touchItem.type == "touchcancel") { |
| 126 | + if (that.touchTimer != 0) { |
| 127 | + clearInterval(that.touchTimer); |
| 128 | + that.touchTimer = 0; |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +App(app); |
| 134 | + |
| 135 | +app = 0; |
0 commit comments