general-event.uvue 8.9 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-padding-wrap uni-common-mt container">
DCloud-WZF's avatar
DCloud-WZF 已提交
8 9 10
        <view
          class="target"
          @touchstart="onTouchStart"
DCloud-WZF's avatar
DCloud-WZF 已提交
11
          @touchcancel="onTouchCancel"
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15 16 17
          @touchmove="onTouchMove"
          @touchend="onTouchEnd"
          @tap="onTap"
          @click="onClick"
          @longpress="onLongPress"
        ></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20
        <view v-if="touchStartEvent !== null">
          <text class="title1">touchStart Event: </text>
          <text class="title2">touches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22 23 24
          <template
            v-for="(touch, index) in touchStartEvent!.touches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29 30 31 32
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
33 34
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36 37 38
          <template
            v-for="(touch, index) in touchStartEvent!.changedTouches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
39 40
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43 44 45 46
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48
          </template>
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        <view v-if="touchCancelEvent !== null">
          <text class="title1">touchCancel Event: </text>
          <text class="title2">touches: </text>
          <template
            v-for="(touch, index) in touchCancelEvent!.touches"
            :key="index"
          >
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
          <template
            v-for="(touch, index) in touchCancelEvent!.changedTouches"
            :key="index"
          >
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
          </template>
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
80 81 82
        <view v-if="touchMoveEvent !== null">
          <text class="title1">touchMove Event: </text>
          <text class="title2">touches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
83 84 85 86
          <template
            v-for="(touch, index) in touchMoveEvent!.touches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
87 88
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
89 90 91 92 93 94
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
97 98 99 100
          <template
            v-for="(touch, index) in touchMoveEvent!.changedTouches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
101 102
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
          </template>
        </view>
        <view v-if="longPressEvent !== null">
          <text class="title1">longPress Event: </text>
          <text class="title2">touches: </text>
          <template
            v-if="longPressEvent!.touches.length > 0"
            v-for="(touch, index) in longPressEvent!.touches"
            :key="index"
          >
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
          <template
            v-for="(touch, index) in longPressEvent!.changedTouches"
            :key="index"
          >
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
141 142 143 144 145
          </template>
        </view>
        <view v-if="touchEndEvent !== null">
          <text class="title1">touchEnd Event: </text>
          <text class="title2">touches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
146 147 148 149 150
          <template
            v-if="touchEndEvent!.touches.length > 0"
            v-for="(touch, index) in touchEndEvent!.touches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
151 152
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
153 154 155 156 157 158
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
159 160
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
161 162 163 164
          <template
            v-for="(touch, index) in touchEndEvent!.changedTouches"
            :key="index"
          >
DCloud-WZF's avatar
DCloud-WZF 已提交
165 166
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
167 168 169 170 171 172
            <text
              >clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text
            >
            <text
              >screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text
            >
DCloud-WZF's avatar
DCloud-WZF 已提交
173 174
          </template>
        </view>
175 176 177 178 179 180 181 182
        <view v-if="tapEvent !== null">
          <text class="title1">tap Event: </text>
          <text>x: {{ tapEvent!.x }}, y: {{ tapEvent!.y }}</text>
        </view>
        <view v-if="clickEvent !== null">
          <text class="title1">click Event: </text>
          <text>x: {{ clickEvent!.x }}, y: {{ clickEvent!.y }}</text>
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
183 184 185 186 187 188 189 190 191 192 193
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
<script lang="uts">
export default {
  data() {
    return {
      title: 'general-event',
194
      onTouchStartTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
195
      touchStartEvent: null as TouchEvent | null,
DCloud-WZF's avatar
DCloud-WZF 已提交
196
      touchCancelEvent: null as TouchEvent | null,
197
      onTouchMoveTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
198
      touchMoveEvent: null as TouchEvent | null,
199
      onTouchEndTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
200
      longPressEvent: null as TouchEvent | null,
DCloud-WZF's avatar
DCloud-WZF 已提交
201
      touchEndEvent: null as TouchEvent | null,
202 203 204 205 206
      onTapTime: 0,
      tapEvent: null as MouseEvent | null,
      onClickTime: 0,
      clickEvent: null as MouseEvent | null,
      onLongPressTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
207 208 209 210 211
    }
  },
  methods: {
    onTouchStart(e: TouchEvent){
      this.touchStartEvent = e
212
      this.onTouchStartTime = Date.now()
213
      console.log('onTouchStart')
DCloud-WZF's avatar
DCloud-WZF 已提交
214
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
215 216 217 218
    onTouchCancel(e: TouchEvent){
      this.touchCancelEvent = e
      console.log('onTouchCancel')
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
219 220
    onTouchMove(e: TouchEvent){
      this.touchMoveEvent = e
221
      this.onTouchMoveTime = Date.now()
222
      console.log('onTouchMove')
DCloud-WZF's avatar
DCloud-WZF 已提交
223
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
224 225 226 227 228
    onLongPress(e: TouchEvent){
      this.longPressEvent = e
      this.onLongPressTime = Date.now()
      console.log('onLongPress')
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
229 230
    onTouchEnd(e: TouchEvent){
      this.touchEndEvent = e
231
      this.onTouchEndTime = Date.now()
232
      console.log('onTouchEnd')
233 234 235 236
    },
    onTap(e: MouseEvent){
      this.tapEvent = e
      this.onTapTime = Date.now()
237
      console.log('onTap')
238 239 240 241
    },
    onClick(e: MouseEvent){
      this.clickEvent = e
      this.onClickTime = Date.now()
242
      console.log('onClick')
243
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
  },
}
</script>

<style>
.container {
  padding-bottom: 1000px;
}
.target {
  margin: 20px 0 0 50px;
  width: 200px;
  height: 100px;
  background-color: aqua;
}
.title1 {
  margin-top: 15px;
  font-size: 20px;
}
.title2 {
  margin-top: 10px;
  font-size: 18px;
}
.title3 {
  margin-top: 5px;
  font-size: 16px;
}
</style>