general-event.uvue 5.6 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">
8
        <view class="target" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd" @tap="onTap" @click="onClick" @longpress="onLongPress"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10 11
        <view v-if="touchStartEvent !== null">
          <text class="title1">touchStart Event: </text>
          <text class="title2">touches: </text>
12
          <template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
15 16
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
19
          <template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
20 21
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
22 23
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25 26 27 28
          </template>
        </view>
        <view v-if="touchMoveEvent !== null">
          <text class="title1">touchMove Event: </text>
          <text class="title2">touches: </text>
29
          <template v-for="(touch, index) in touchMoveEvent!.touches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
32 33
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
36
          <template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
37 38
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
39 40
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42 43 44 45
          </template>
        </view>
        <view v-if="touchEndEvent !== null">
          <text class="title1">touchEnd Event: </text>
          <text class="title2">touches: </text>
46
          <template v-if="touchEndEvent!.touches.length > 0" v-for="(touch, index) in touchEndEvent!.touches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
49 50
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
51 52
          </template>
          <text class="title2 uni-common-mt">changedTouches: </text>
53
          <template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index">
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55
            <text class="title3">touch[{{ index }}]:</text>
            <text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text>
56 57
            <text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text>
            <text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59
          </template>
        </view>
60 61 62 63 64 65 66 67
        <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 已提交
68 69 70 71 72 73 74 75 76 77 78
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
<script lang="uts">
export default {
  data() {
    return {
      title: 'general-event',
79
      onTouchStartTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
80
      touchStartEvent: null as TouchEvent | null,
81
      onTouchMoveTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
82
      touchMoveEvent: null as TouchEvent | null,
83
      onTouchEndTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
84
      touchEndEvent: null as TouchEvent | null,
85 86 87 88 89
      onTapTime: 0,
      tapEvent: null as MouseEvent | null,
      onClickTime: 0,
      clickEvent: null as MouseEvent | null,
      onLongPressTime: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
90 91 92 93 94
    }
  },
  methods: {
    onTouchStart(e: TouchEvent){
      this.touchStartEvent = e
95 96
      this.onTouchStartTime = Date.now()
      console.warn('onTouchStart', this.onTouchStartTime)
DCloud-WZF's avatar
DCloud-WZF 已提交
97 98 99
    },
    onTouchMove(e: TouchEvent){
      this.touchMoveEvent = e
100 101
      this.onTouchMoveTime = Date.now()
      console.warn('onTouchMove', this.onTouchMoveTime)
DCloud-WZF's avatar
DCloud-WZF 已提交
102 103 104
    },
    onTouchEnd(e: TouchEvent){
      this.touchEndEvent = e
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
      this.onTouchEndTime = Date.now()
      console.warn('onTouchEnd', this.onTouchEndTime)
    },
    onTap(e: MouseEvent){
      this.tapEvent = e
      this.onTapTime = Date.now()
      console.warn('onTap', this.onTapTime)
    },
    onClick(e: MouseEvent){
      this.clickEvent = e
      this.onClickTime = Date.now()
      console.warn('onClick', this.onClickTime)
    },
    onLongPress(){
      this.onLongPressTime = Date.now()
      console.warn('onLongPress', this.onLongPressTime)
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  },
}
</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>