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