提交 62c13a62 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(general event): 优化示例及测试

上级 0cf8c2ee
const PAGE_PATH = '/pages/component/general-event/general-event' const PAGE_PATH = '/pages/component/general-event/general-event'
describe('event trigger sequence', () => { describe('event trigger sequence', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
let page let page
let el
beforeAll(async () => { beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH) page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view') await page.waitFor('view')
el = await page.$('.target')
}) })
it('touch', async () => { it('touch', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
const el = await page.$('#touch-target')
await el.touchstart({ await el.touchstart({
touches: [{ touches: [{
identifier: 1, identifier: 1,
pageX: 100, pageX: 101,
pageY: 100, pageY: 101,
clientX: 101,
clientY: 101,
screenX: 101,
screenY: 101
}, ], }, ],
changedTouches: [{ changedTouches: [{
identifier: 1, identifier: 1,
pageX: 100, pageX: 101,
pageY: 100, pageY: 101,
clientX: 101,
clientY: 101,
screenX: 101,
screenY: 101
}, ], }, ],
}) })
const touchStartTouchTargetIdentifier = isAndroid ? '1.0' : '1'
const touchStartTouchTargetValue = isAndroid ? '101.0' : '101'
const touchStartTouchIdentifier = await page.$('#touch-start-touch-identifier')
expect(await touchStartTouchIdentifier.text()).toBe(touchStartTouchTargetIdentifier)
const touchStartTouchPageX = await page.$('#touch-start-touch-page-x')
expect(await touchStartTouchPageX.text()).toBe(touchStartTouchTargetValue)
const touchStartTouchPageY = await page.$('#touch-start-touch-page-y')
expect(await touchStartTouchPageY.text()).toBe(touchStartTouchTargetValue)
const touchStartTouchClientX = await page.$('#touch-start-touch-client-x')
expect(await touchStartTouchClientX.text()).toBe(touchStartTouchTargetValue)
const touchStartTouchClientY = await page.$('#touch-start-touch-client-y')
expect(await touchStartTouchClientY.text()).toBe(touchStartTouchTargetValue)
const touchStartTouchScreenX = await page.$('#touch-start-touch-screen-x')
expect(await touchStartTouchScreenX.text()).toBe(touchStartTouchTargetValue)
const touchStartTouchScreenY = await page.$('#touch-start-touch-screen-y')
expect(await touchStartTouchScreenY.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchIdentifier = await page.$('#touch-start-changed-touch-identifier')
expect(await touchStartChangedTouchIdentifier.text()).toBe(touchStartTouchTargetIdentifier)
const touchStartChangedTouchPageX = await page.$('#touch-start-changed-touch-page-x')
expect(await touchStartChangedTouchPageX.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchPageY = await page.$('#touch-start-changed-touch-page-y')
expect(await touchStartChangedTouchPageY.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchClientX = await page.$('#touch-start-changed-touch-client-x')
expect(await touchStartChangedTouchClientX.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchClientY = await page.$('#touch-start-changed-touch-client-y')
expect(await touchStartChangedTouchClientY.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchScreenX = await page.$('#touch-start-changed-touch-screen-x')
expect(await touchStartChangedTouchScreenX.text()).toBe(touchStartTouchTargetValue)
const touchStartChangedTouchScreenY = await page.$('#touch-start-changed-touch-screen-y')
expect(await touchStartChangedTouchScreenY.text()).toBe(touchStartTouchTargetValue)
await el.touchmove({ await el.touchmove({
touches: [{ touches: [{
identifier: 1, identifier: 1,
pageX: 100, pageX: 102,
pageY: 100, pageY: 102,
}, ], clientX: 102,
clientY: 102,
screenX: 102,
screenY: 102
}],
changedTouches: [{ changedTouches: [{
identifier: 1, identifier: 1,
pageX: 101, pageX: 102,
pageY: 101, pageY: 102,
clientX: 102,
clientY: 102,
screenX: 102,
screenY: 102
}, ], }, ],
}) })
const touchMoveTouchTargetIdentifier = isAndroid ? '1.0' : '1'
const touchMoveTouchTargetValue = isAndroid ? '102.0' : '102'
const touchMoveTouchIdentifier = await page.$('#touch-move-touch-identifier')
expect(await touchMoveTouchIdentifier.text()).toBe(touchMoveTouchTargetIdentifier)
const touchMoveTouchPageX = await page.$('#touch-move-touch-page-x')
expect(await touchMoveTouchPageX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveTouchPageY = await page.$('#touch-move-touch-page-y')
expect(await touchMoveTouchPageY.text()).toBe(touchMoveTouchTargetValue)
const touchMoveTouchClientX = await page.$('#touch-move-touch-client-x')
expect(await touchMoveTouchClientX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveTouchClientY = await page.$('#touch-move-touch-client-y')
expect(await touchMoveTouchClientY.text()).toBe(touchMoveTouchTargetValue)
const touchMoveTouchScreenX = await page.$('#touch-move-touch-screen-x')
expect(await touchMoveTouchScreenX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveTouchScreenY = await page.$('#touch-move-touch-screen-y')
expect(await touchMoveTouchScreenY.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchIdentifier = await page.$('#touch-move-changed-touch-identifier')
expect(await touchMoveChangedTouchIdentifier.text()).toBe(touchMoveTouchTargetIdentifier)
const touchMoveChangedTouchPageX = await page.$('#touch-move-changed-touch-page-x')
expect(await touchMoveChangedTouchPageX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchPageY = await page.$('#touch-move-changed-touch-page-y')
expect(await touchMoveChangedTouchPageY.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchClientX = await page.$('#touch-move-changed-touch-client-x')
expect(await touchMoveChangedTouchClientX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchClientY = await page.$('#touch-move-changed-touch-client-y')
expect(await touchMoveChangedTouchClientY.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchScreenX = await page.$('#touch-move-changed-touch-screen-x')
expect(await touchMoveChangedTouchScreenX.text()).toBe(touchMoveTouchTargetValue)
const touchMoveChangedTouchScreenY = await page.$('#touch-move-changed-touch-screen-y')
expect(await touchMoveChangedTouchScreenY.text()).toBe(touchMoveTouchTargetValue)
await el.touchend({ await el.touchend({
touches: [], touches: [{
identifier: 1,
pageX: 103,
pageY: 103,
clientX: 103,
clientY: 103,
screenX: 103,
screenY: 103
}],
changedTouches: [{ changedTouches: [{
identifier: 1, identifier: 1,
pageX: 101, pageX: 103,
pageY: 101, pageY: 103,
clientX: 103,
clientY: 103,
screenX: 103,
screenY: 103
}, ], }, ],
}) })
const data = await page.data() const touchEndTouchTargetIdentifier = isAndroid ? '1.0' : '1'
expect(data.onTouchStartTime).toBeLessThanOrEqual(data.onTouchMoveTime); const touchEndTouchTargetValue = isAndroid ? '103.0' : '103'
expect(data.onTouchMoveTime).toBeLessThanOrEqual(data.onTouchEndTime); const touchEndTouchIdentifier = await page.$('#touch-end-touch-identifier')
expect(await touchEndTouchIdentifier.text()).toBe(touchEndTouchTargetIdentifier)
const touchEndTouchPageX = await page.$('#touch-end-touch-page-x')
expect(await touchEndTouchPageX.text()).toBe(touchEndTouchTargetValue)
const touchEndTouchPageY = await page.$('#touch-end-touch-page-y')
expect(await touchEndTouchPageY.text()).toBe(touchEndTouchTargetValue)
const touchEndTouchClientX = await page.$('#touch-end-touch-client-x')
expect(await touchEndTouchClientX.text()).toBe(touchEndTouchTargetValue)
const touchEndTouchClientY = await page.$('#touch-end-touch-client-y')
expect(await touchEndTouchClientY.text()).toBe(touchEndTouchTargetValue)
const touchEndTouchScreenX = await page.$('#touch-end-touch-screen-x')
expect(await touchEndTouchScreenX.text()).toBe(touchEndTouchTargetValue)
const touchEndTouchScreenY = await page.$('#touch-end-touch-screen-y')
expect(await touchEndTouchScreenY.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchIdentifier = await page.$('#touch-end-changed-touch-identifier')
expect(await touchEndChangedTouchIdentifier.text()).toBe(touchEndTouchTargetIdentifier)
const touchEndChangedTouchPageX = await page.$('#touch-end-changed-touch-page-x')
expect(await touchEndChangedTouchPageX.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchPageY = await page.$('#touch-end-changed-touch-page-y')
expect(await touchEndChangedTouchPageY.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchClientX = await page.$('#touch-end-changed-touch-client-x')
expect(await touchEndChangedTouchClientX.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchClientY = await page.$('#touch-end-changed-touch-client-y')
expect(await touchEndChangedTouchClientY.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchScreenX = await page.$('#touch-end-changed-touch-screen-x')
expect(await touchEndChangedTouchScreenX.text()).toBe(touchEndTouchTargetValue)
const touchEndChangedTouchScreenY = await page.$('#touch-end-changed-touch-screen-y')
expect(await touchEndChangedTouchScreenY.text()).toBe(touchEndTouchTargetValue)
} }
}) })
it('click', async () => { it('click', async () => {
const el = await page.$('#longpress-target')
await el.tap() await el.tap()
const data = await page.data() const targetX = isAndroid ? '0.0' : '0'
expect(data.onTapTime).toBeLessThanOrEqual(data.onClickTime) const targetY = isAndroid ? '0.0' : '0'
const tapEventX = await page.$('#tap-event-x')
expect(await tapEventX.text()).toBe(targetX)
const tapEventY = await page.$('#tap-event-y')
expect(await tapEventY.text()).toBe(targetY)
const clickEventX = await page.$('#click-event-x')
expect(await clickEventX.text()).toBe(targetX)
const clickEventY = await page.$('#click-event-y')
expect(await clickEventY.text()).toBe(targetY)
}) })
it('longPress', async () => { it('longPress', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
const el = await page.$('#longpress-target')
await el.longpress() await el.longpress()
const data = await page.data() const longPressTouchTargetIdentifier = isAndroid ? '1.0' : '1'
expect(data.onLongPressTime).toBeGreaterThan(0) const longPressTouchTargetValue = isAndroid ? '0.0' : '0'
const longPressTouchIdentifier = await page.$('#long-press-touch-identifier')
expect(await longPressTouchIdentifier.text()).toBe(longPressTouchTargetIdentifier)
const longPressTouchPageX = await page.$('#long-press-touch-page-x')
expect(await longPressTouchPageX.text()).toBe(longPressTouchTargetValue)
const longPressTouchPageY = await page.$('#long-press-touch-page-y')
expect(await longPressTouchPageY.text()).toBe(longPressTouchTargetValue)
const longPressTouchClientX = await page.$('#long-press-touch-client-x')
expect(await longPressTouchClientX.text()).toBe(longPressTouchTargetValue)
const longPressTouchClientY = await page.$('#long-press-touch-client-y')
expect(await longPressTouchClientY.text()).toBe(longPressTouchTargetValue)
const longPressTouchScreenX = await page.$('#long-press-touch-screen-x')
expect(await longPressTouchScreenX.text()).toBe(longPressTouchTargetValue)
const longPressTouchScreenY = await page.$('#long-press-touch-screen-y')
expect(await longPressTouchScreenY.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchIdentifier = await page.$('#long-press-changed-touch-identifier')
expect(await longPressChangedTouchIdentifier.text()).toBe(longPressTouchTargetIdentifier)
const longPressChangedTouchPageX = await page.$('#long-press-changed-touch-page-x')
expect(await longPressChangedTouchPageX.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchPageY = await page.$('#long-press-changed-touch-page-y')
expect(await longPressChangedTouchPageY.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchClientX = await page.$('#long-press-changed-touch-client-x')
expect(await longPressChangedTouchClientX.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchClientY = await page.$('#long-press-changed-touch-client-y')
expect(await longPressChangedTouchClientY.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchScreenX = await page.$('#long-press-changed-touch-screen-x')
expect(await longPressChangedTouchScreenX.text()).toBe(longPressTouchTargetValue)
const longPressChangedTouchScreenY = await page.$('#long-press-changed-touch-screen-y')
expect(await longPressChangedTouchScreenY.text()).toBe(longPressTouchTargetValue)
} }
}) })
}) })
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<!-- #endif --> <!-- #endif -->
<page-head title="触摸方块测试相关事件"></page-head> <page-head title="触摸方块测试相关事件"></page-head>
<view class="uni-padding-wrap uni-common-mt container"> <view class="uni-padding-wrap uni-common-mt container">
<view class="target" @touchstart="onTouchStart" @touchcancel="onTouchCancel" @touchmove="onTouchMove" <view class="target" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
@touchend="onTouchEnd" @tap="onTap" @click="onClick" @longpress="onLongPress"></view> @touchmove="onTouchMove" @touchend="onTouchEnd"></view>
<view v-if="touchStartEvent !== null"> <view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view>
<text class="title1">touchStart Event: </text> <view v-if="touchStartEvent !== null">
<text class="title2">touches: </text> <text class="title1">touchStart Event: </text>
<template v-for="(touch, index) in touchStartEvent!.touches" :key="index"> <text class="title2">touches: </text>
<text class="title3">touch[{{ index }}]:</text> <template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
<text>identifier: {{touch.identifier}}</text> <text class="title3">touch[{{ index }}]:</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <view class="uni-list-cell">
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <text>identifier: </text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text id="touch-start-touch-identifier">{{touch.identifier}}</text>
</template> </view>
<text class="title2 uni-common-mt">changedTouches: </text> <view class="uni-list-cell">
<template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index"> <text>pageX: </text>
<text class="title3">touch[{{ index }}]:</text> <text id="touch-start-touch-page-x">{{ touch.pageX }}</text>
<text>identifier: {{touch.identifier}}</text> </view>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <view class="uni-list-cell">
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <text>pageY: </text>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text id="touch-start-touch-page-y">{{ touch.pageY }}</text>
</template> </view>
</view> <view class="uni-list-cell">
<view v-if="touchCancelEvent !== null"> <text>clientX: </text>
<text class="title1">touchCancel Event: </text> <text id="touch-start-touch-client-x">{{ touch.clientX }}</text>
<text class="title2">touches: </text> </view>
<template v-for="(touch, index) in touchCancelEvent!.touches" :key="index"> <view class="uni-list-cell">
<text class="title3">touch[{{ index }}]:</text> <text>clientY: </text>
<text>identifier: {{touch.identifier}}</text> <text id="touch-start-touch-client-y">{{ touch.clientY }}</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> </view>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <view class="uni-list-cell">
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text>screenX: </text>
</template> <text id="touch-start-touch-screen-x">{{ touch.screenX }}</text>
<text class="title2 uni-common-mt">changedTouches: </text> </view>
<template v-for="(touch, index) in touchCancelEvent!.changedTouches" :key="index"> <view class="uni-list-cell">
<text class="title3">touch[{{ index }}]:</text> <text>screenY: </text>
<text>identifier: {{touch.identifier}}</text> <text id="touch-start-touch-screen-y">{{ touch.screenY }}</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> </view>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> </template>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text class="title2 uni-common-mt">changedTouches: </text>
</template> <template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index">
</view> <text class="title3">touch[{{ index }}]:</text>
<view v-if="touchMoveEvent !== null"> <view class="uni-list-cell">
<text class="title1">touchMove Event: </text> <text>identifier: </text>
<text class="title2">touches: </text> <text id="touch-start-changed-touch-identifier">{{touch.identifier}}</text>
<template v-for="(touch, index) in touchMoveEvent!.touches" :key="index"> </view>
<text class="title3">touch[{{ index }}]:</text> <view class="uni-list-cell">
<text>identifier: {{touch.identifier}}</text> <text>pageX: </text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <text id="touch-start-changed-touch-page-x">{{ touch.pageX }}</text>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> </view>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <view class="uni-list-cell">
</template> <text>pageY: </text>
<text class="title2 uni-common-mt">changedTouches: </text> <text id="touch-start-changed-touch-page-y">{{ touch.pageY }}</text>
<template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index"> </view>
<text class="title3">touch[{{ index }}]:</text> <view class="uni-list-cell">
<text>identifier: {{touch.identifier}}</text> <text>clientX: </text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <text id="touch-start-changed-touch-client-x">{{ touch.clientX }}</text>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> </view>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <view class="uni-list-cell">
</template> <text>clientY: </text>
</view> <text id="touch-start-changed-touch-client-y">{{ touch.clientY }}</text>
<view v-if="longPressEvent !== null"> </view>
<text class="title1">longPress Event: </text> <view class="uni-list-cell">
<text class="title2">touches: </text> <text>screenX: </text>
<template v-if="longPressEvent!.touches.length > 0" v-for="(touch, index) in longPressEvent!.touches" <text id="touch-start-changed-touch-screen-x">{{ touch.screenX }}</text>
:key="index"> </view>
<text class="title3">touch[{{ index }}]:</text> <view class="uni-list-cell">
<text>identifier: {{touch.identifier}}</text> <text>screenY: </text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <text id="touch-start-changed-touch-screen-y">{{ touch.screenY }}</text>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> </view>
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> </template>
</template> </view>
<text class="title2 uni-common-mt">changedTouches: </text> <view v-if="touchCancelEvent !== null">
<template v-for="(touch, index) in longPressEvent!.changedTouches" :key="index"> <text class="title1">touchCancel Event: </text>
<text class="title3">touch[{{ index }}]:</text> <text class="title2">touches: </text>
<text>identifier: {{touch.identifier}}</text> <template v-for="(touch, index) in touchCancelEvent!.touches" :key="index">
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> <text class="title3">touch[{{ index }}]:</text>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <view class="uni-list-cell">
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text>identifier: </text>
</template> <text id="touch-cancel-touch-identifier">{{touch.identifier}}</text>
</view> </view>
<view v-if="touchEndEvent !== null"> <view class="uni-list-cell">
<text class="title1">touchEnd Event: </text> <text>pageX: </text>
<text class="title2">touches: </text> <text id="touch-cancel-touch-page-x">{{ touch.pageX }}</text>
<template v-if="touchEndEvent!.touches.length > 0" v-for="(touch, index) in touchEndEvent!.touches" </view>
:key="index"> <view class="uni-list-cell">
<text class="title3">touch[{{ index }}]:</text> <text>pageY: </text>
<text>identifier: {{touch.identifier}}</text> <text id="touch-cancel-touch-page-y">{{ touch.pageY }}</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> </view>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <view class="uni-list-cell">
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text>clientX: </text>
</template> <text id="touch-cancel-touch-client-x">{{ touch.clientX }}</text>
<text class="title2 uni-common-mt">changedTouches: </text> </view>
<template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index"> <view class="uni-list-cell">
<text class="title3">touch[{{ index }}]:</text> <text>clientY: </text>
<text>identifier: {{touch.identifier}}</text> <text id="touch-cancel-touch-client-y">{{ touch.clientY }}</text>
<text>pageX: {{ touch.pageX }}, pageY: {{ touch.pageY }}</text> </view>
<text>clientX: {{ touch.clientX }}, clientY: {{ touch.clientY }}</text> <view class="uni-list-cell">
<text>screenX: {{ touch.screenX }}, screenY: {{ touch.screenY }}</text> <text>screenX: </text>
</template> <text id="touch-cancel-touch-screen-x">{{ touch.screenX }}</text>
</view> </view>
<view v-if="tapEvent !== null"> <view class="uni-list-cell">
<text class="title1">tap Event: </text> <text>screenY: </text>
<text>x: {{ tapEvent!.x }}, y: {{ tapEvent!.y }}</text> <text id="touch-cancel-touch-screen-y">{{ touch.screenY }}</text>
</view> </view>
<view v-if="clickEvent !== null"> </template>
<text class="title1">click Event: </text> <text class="title2 uni-common-mt">changedTouches: </text>
<text>x: {{ clickEvent!.x }}, y: {{ clickEvent!.y }}</text> <template v-for="(touch, index) in touchCancelEvent!.changedTouches" :key="index">
</view> <text class="title3">touch[{{ index }}]:</text>
</view> <view class="uni-list-cell">
<!-- #ifdef APP --> <text>identifier: </text>
</scroll-view> <text id="touch-cancel-changed-touch-identifier">{{touch.identifier}}</text>
<!-- #endif --> </view>
</template> <view class="uni-list-cell">
<script lang="uts"> <text>pageX: </text>
export default { <text id="touch-cancel-changed-touch-page-x">{{ touch.pageX }}</text>
data() { </view>
return { <view class="uni-list-cell">
title: 'general-event', <text>pageY: </text>
onTouchStartTime: 0, <text id="touch-cancel-changed-touch-page-y">{{ touch.pageY }}</text>
touchStartEvent: null as TouchEvent | null, </view>
touchCancelEvent: null as TouchEvent | null, <view class="uni-list-cell">
onTouchMoveTime: 0, <text>clientX: </text>
touchMoveEvent: null as TouchEvent | null, <text id="touch-cancel-changed-touch-client-x">{{ touch.clientX }}</text>
onTouchEndTime: 0, </view>
longPressEvent: null as TouchEvent | null, <view class="uni-list-cell">
touchEndEvent: null as TouchEvent | null, <text>clientY: </text>
onTapTime: 0, <text id="touch-cancel-changed-touch-client-y">{{ touch.clientY }}</text>
tapEvent: null as PointerEvent | null, </view>
onClickTime: 0, <view class="uni-list-cell">
clickEvent: null as PointerEvent | null, <text>screenX: </text>
onLongPressTime: 0, <text id="touch-cancel-changed-touch-screen-x">{{ touch.screenX }}</text>
} </view>
}, <view class="uni-list-cell">
methods: { <text>screenY: </text>
onTouchStart(e : TouchEvent) { <text id="touch-cancel-changed-touch-screen-y">{{ touch.screenY }}</text>
this.touchStartEvent = e </view>
this.onTouchStartTime = Date.now() </template>
console.log('onTouchStart') </view>
}, <view v-if="touchMoveEvent !== null">
onTouchCancel(e : TouchEvent) { <text class="title1">touchMove Event: </text>
this.touchCancelEvent = e <text class="title2">touches: </text>
console.log('onTouchCancel') <template v-for="(touch, index) in touchMoveEvent!.touches" :key="index">
}, <text class="title3">touch[{{ index }}]:</text>
onTouchMove(e : TouchEvent) { <view class="uni-list-cell">
this.touchMoveEvent = e <text>identifier: </text>
this.onTouchMoveTime = Date.now() <text id="touch-move-touch-identifier">{{touch.identifier}}</text>
console.log('onTouchMove') </view>
}, <view class="uni-list-cell">
onLongPress(e : TouchEvent) { <text>pageX: </text>
this.longPressEvent = e <text id="touch-move-touch-page-x">{{ touch.pageX }}</text>
this.onLongPressTime = Date.now() </view>
console.log('onLongPress') <view class="uni-list-cell">
}, <text>pageY: </text>
onTouchEnd(e : TouchEvent) { <text id="touch-move-touch-page-y">{{ touch.pageY }}</text>
this.touchEndEvent = e </view>
this.onTouchEndTime = Date.now() <view class="uni-list-cell">
console.log('onTouchEnd') <text>clientX: </text>
}, <text id="touch-move-touch-client-x">{{ touch.clientX }}</text>
onTap(e : PointerEvent) { </view>
this.tapEvent = e <view class="uni-list-cell">
this.onTapTime = Date.now() <text>clientY: </text>
console.log('onTap') <text id="touch-move-touch-client-y">{{ touch.clientY }}</text>
}, </view>
onClick(e : PointerEvent) { <view class="uni-list-cell">
this.clickEvent = e <text>screenX: </text>
this.onClickTime = Date.now() <text id="touch-move-touch-screen-x">{{ touch.screenX }}</text>
console.log('onClick') </view>
}, <view class="uni-list-cell">
}, <text>screenY: </text>
} <text id="touch-move-touch-screen-y">{{ touch.screenY }}</text>
</script> </view>
</template>
<style> <text class="title2 uni-common-mt">changedTouches: </text>
.container { <template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index">
padding-bottom: 10px; <text class="title3">touch[{{ index }}]:</text>
} <view class="uni-list-cell">
<text>identifier: </text>
.target { <text id="touch-move-changed-touch-identifier">{{touch.identifier}}</text>
margin: 20px 0 0 50px; </view>
width: 200px; <view class="uni-list-cell">
height: 100px; <text>pageX: </text>
background-color: aqua; <text id="touch-move-changed-touch-page-x">{{ touch.pageX }}</text>
} </view>
<view class="uni-list-cell">
.title1 { <text>pageY: </text>
margin-top: 15px; <text id="touch-move-changed-touch-page-y">{{ touch.pageY }}</text>
font-size: 20px; </view>
} <view class="uni-list-cell">
<text>clientX: </text>
.title2 { <text id="touch-move-changed-touch-client-x">{{ touch.clientX }}</text>
margin-top: 10px; </view>
font-size: 18px; <view class="uni-list-cell">
} <text>clientY: </text>
<text id="touch-move-changed-touch-client-y">{{ touch.clientY }}</text>
.title3 { </view>
margin-top: 5px; <view class="uni-list-cell">
font-size: 16px; <text>screenX: </text>
} <text id="touch-move-changed-touch-screen-x">{{ touch.screenX }}</text>
</view>
<view class="uni-list-cell">
<text>screenY: </text>
<text id="touch-move-changed-touch-screen-y">{{ touch.screenY }}</text>
</view>
</template>
</view>
<view v-if="touchEndEvent !== null">
<text class="title1">touchEnd Event: </text>
<text class="title2">touches: </text>
<template v-if="touchEndEvent!.touches.length > 0" v-for="(touch, index) in touchEndEvent!.touches"
:key="index">
<text class="title3">touch[{{ index }}]:</text>
<view class="uni-list-cell">
<text>identifier: </text>
<text id="touch-end-touch-identifier">{{touch.identifier}}</text>
</view>
<view class="uni-list-cell">
<text>pageX: </text>
<text id="touch-end-touch-page-x">{{ touch.pageX }}</text>
</view>
<view class="uni-list-cell">
<text>pageY: </text>
<text id="touch-end-touch-page-y">{{ touch.pageY }}</text>
</view>
<view class="uni-list-cell">
<text>clientX: </text>
<text id="touch-end-touch-client-x">{{ touch.clientX }}</text>
</view>
<view class="uni-list-cell">
<text>clientY: </text>
<text id="touch-end-touch-client-y">{{ touch.clientY }}</text>
</view>
<view class="uni-list-cell">
<text>screenX: </text>
<text id="touch-end-touch-screen-x">{{ touch.screenX }}</text>
</view>
<view class="uni-list-cell">
<text>screenY: </text>
<text id="touch-end-touch-screen-y">{{ touch.screenY }}</text>
</view>
</template>
<text class="title2 uni-common-mt">changedTouches: </text>
<template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index">
<text class="title3">touch[{{ index }}]:</text>
<view class="uni-list-cell">
<text>identifier: </text>
<text id="touch-end-changed-touch-identifier">{{touch.identifier}}</text>
</view>
<view class="uni-list-cell">
<text>pageX: </text>
<text id="touch-end-changed-touch-page-x">{{ touch.pageX }}</text>
</view>
<view class="uni-list-cell">
<text>pageY: </text>
<text id="touch-end-changed-touch-page-y">{{ touch.pageY }}</text>
</view>
<view class="uni-list-cell">
<text>clientX: </text>
<text id="touch-end-changed-touch-client-x">{{ touch.clientX }}</text>
</view>
<view class="uni-list-cell">
<text>clientY: </text>
<text id="touch-end-changed-touch-client-y">{{ touch.clientY }}</text>
</view>
<view class="uni-list-cell">
<text>screenX: </text>
<text id="touch-end-changed-touch-screen-x">{{ touch.screenX }}</text>
</view>
<view class="uni-list-cell">
<text>screenY: </text>
<text id="touch-end-changed-touch-screen-y">{{ touch.screenY }}</text>
</view>
</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>
<view class="uni-list-cell">
<text>identifier: </text>
<text id="long-press-touch-identifier">{{touch.identifier}}</text>
</view>
<view class="uni-list-cell">
<text>pageX: </text>
<text id="long-press-touch-page-x">{{ touch.pageX }}</text>
</view>
<view class="uni-list-cell">
<text>pageY: </text>
<text id="long-press-touch-page-y">{{ touch.pageY }}</text>
</view>
<view class="uni-list-cell">
<text>clientX: </text>
<text id="long-press-touch-client-x">{{ touch.clientX }}</text>
</view>
<view class="uni-list-cell">
<text>clientY: </text>
<text id="long-press-touch-client-y">{{ touch.clientY }}</text>
</view>
<view class="uni-list-cell">
<text>screenX: </text>
<text id="long-press-touch-screen-x">{{ touch.screenX }}</text>
</view>
<view class="uni-list-cell">
<text>screenY: </text>
<text id="long-press-touch-screen-y">{{ touch.screenY }}</text>
</view>
</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>
<view class="uni-list-cell">
<text>identifier: </text>
<text id="long-press-changed-touch-identifier">{{touch.identifier}}</text>
</view>
<view class="uni-list-cell">
<text>pageX: </text>
<text id="long-press-changed-touch-page-x">{{ touch.pageX }}</text>
</view>
<view class="uni-list-cell">
<text>pageY: </text>
<text id="long-press-changed-touch-page-y">{{ touch.pageY }}</text>
</view>
<view class="uni-list-cell">
<text>clientX: </text>
<text id="long-press-changed-touch-client-x">{{ touch.clientX }}</text>
</view>
<view class="uni-list-cell">
<text>clientY: </text>
<text id="long-press-changed-touch-client-y">{{ touch.clientY }}</text>
</view>
<view class="uni-list-cell">
<text>screenX: </text>
<text id="long-press-changed-touch-screen-x">{{ touch.screenX }}</text>
</view>
<view class="uni-list-cell">
<text>screenY: </text>
<text id="long-press-changed-touch-screen-y">{{ touch.screenY }}</text>
</view>
</template>
</view>
<view v-if="tapEvent !== null">
<text class="title1">tap Event: </text>
<view class="uni-list-cell">
<text>x: </text>
<text id="tap-event-x">{{ tapEvent!.x }}</text>
</view>
<view class="uni-list-cell">
<text>y: </text>
<text id="tap-event-y">{{ tapEvent!.y }}</text>
</view>
</view>
<view v-if="clickEvent !== null">
<text class="title1">click Event: </text>
<view class="uni-list-cell">
<text>x: </text>
<text id="click-event-x">{{ clickEvent!.x }}</text>
</view>
<view class="uni-list-cell">
<text>y: </text>
<text id="click-event-y">{{ clickEvent!.y }}</text>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="uts">
export default {
data() {
return {
title: 'general-event',
touchStartEvent: null as TouchEvent | null,
touchCancelEvent: null as TouchEvent | null,
touchMoveEvent: null as TouchEvent | null,
longPressEvent: null as TouchEvent | null,
touchEndEvent: null as TouchEvent | null,
tapEvent: null as PointerEvent | null,
clickEvent: null as PointerEvent | null,
}
},
methods: {
onTouchStart(e : TouchEvent) {
this.touchStartEvent = e
console.log('onTouchStart', e)
},
onTouchCancel(e : TouchEvent) {
this.touchCancelEvent = e
console.log('onTouchCancel')
},
onTouchMove(e : TouchEvent) {
this.touchMoveEvent = e
console.log('onTouchMove', e)
},
onLongPress(e : TouchEvent) {
this.longPressEvent = e
console.log('onLongPress', e)
},
onTouchEnd(e : TouchEvent) {
this.touchEndEvent = e
console.log('onTouchEnd', e)
},
onTap(e : PointerEvent) {
this.tapEvent = e
console.log('onTap', e)
},
onClick(e : PointerEvent) {
this.clickEvent = e
console.log('onClick', e)
},
},
}
</script>
<style>
.container {
padding-bottom: 10px;
}
.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> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册