refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,27 @@
|
||||
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
|
||||
|
||||
describe('test longPress', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
if (isWeb || isMP) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch("/pages/component/global-events/event-longpress");
|
||||
await page.waitFor(3000);
|
||||
});
|
||||
|
||||
it('check longPress event', async () => {
|
||||
let eventDomRect = await page.data("data.eventDomRect")
|
||||
let x = eventDomRect.x + eventDomRect.width / 2.0
|
||||
let y = eventDomRect.y + eventDomRect.height / 2.0
|
||||
await program.device.tap(x, y+100, {duration: 1000})
|
||||
let isLongPressTrigger = await page.data("data.isLongPressTrigger")
|
||||
expect(isLongPressTrigger).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<view>
|
||||
<view id="longPressView" style="width: 100%;height: 400px;background-color: aquamarine;" @longpress="onLongPress">
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
type DataType = {
|
||||
isLongPressTrigger : boolean,
|
||||
eventDomRect : DOMRect | null
|
||||
}
|
||||
|
||||
// 使用reactive包装数据,便于自动化测试获取
|
||||
const data = reactive({ isLongPressTrigger: false, eventDomRect: null as DOMRect | null } as DataType)
|
||||
|
||||
onReady(() => {
|
||||
let element = uni.getElementById("longPressView")
|
||||
data.eventDomRect = element?.getBoundingClientRect();
|
||||
})
|
||||
function onLongPress() {
|
||||
data.isLongPressTrigger = true
|
||||
console.log("longPress")
|
||||
}
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,29 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
|
||||
describe('global event transform', () => {
|
||||
if (!isAndroid) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/component/global-events/global-events-transform')
|
||||
await page.waitFor(3000);
|
||||
});
|
||||
|
||||
it('event transform click', async () => {
|
||||
const el = await page.$('#event-transform')
|
||||
await el.tap()
|
||||
await page.waitFor(100)
|
||||
expect(await page.data("data.clickTriger")).toBe(true)
|
||||
});
|
||||
it('event transform longclick', async () => {
|
||||
const el = await page.$('#event-transform')
|
||||
await el.longpress()
|
||||
await page.waitFor(100)
|
||||
expect(await page.data("data.longClickTriger")).toBe(true)
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<view>
|
||||
<view @click="onclick"
|
||||
style="transform: rotate(180deg); background-color: brown;width: 100px; height: 100px; margin: 8px auto;"
|
||||
@longpress="onLongPress" id="event-transform">
|
||||
<text style="text-align: center;line-height: 100px;">旋转180°后</text>
|
||||
</view>
|
||||
</view>
|
||||
<text style="margin:0px auto;">点击上面view触发点击事件</text>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
type DataType = {
|
||||
clickTriger: boolean,
|
||||
longClickTriger: boolean,
|
||||
}
|
||||
|
||||
// 使用reactive包装数据,便于自动化测试获取
|
||||
const data = reactive({
|
||||
clickTriger: false,
|
||||
longClickTriger: false,
|
||||
} as DataType)
|
||||
|
||||
function onclick(event : UniPointerEvent) {
|
||||
data.clickTriger = true
|
||||
uni.showToast({
|
||||
title: "触发了点击事件"
|
||||
})
|
||||
}
|
||||
|
||||
function onLongPress(event : UniTouchEvent) {
|
||||
data.longClickTriger = true
|
||||
uni.showToast({
|
||||
title: "触发了长按事件"
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,322 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isIos = platformInfo.startsWith('ios')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
|
||||
const PAGE_PATH = '/pages/component/global-events/global-events'
|
||||
|
||||
describe('event trigger', () => {
|
||||
if (isMP) {
|
||||
it('skip', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
|
||||
it('跳过横屏模式', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
const tapParams = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
duration: 1000
|
||||
}
|
||||
beforeAll(async () => {
|
||||
page = await program.navigateTo(PAGE_PATH)
|
||||
// await page.waitFor('view')
|
||||
await page.waitFor(1000)
|
||||
const windowInfo = await program.callUniMethod('getWindowInfo');
|
||||
topSafeArea = windowInfo.safeAreaInsets.top;
|
||||
const longPressTargetRect = await page.data('longPressTargetRect')
|
||||
tapParams.x = parseInt(longPressTargetRect.x + longPressTargetRect.width / 2)
|
||||
tapParams.y = parseInt(longPressTargetRect.y + longPressTargetRect.height / 2 + topSafeArea)
|
||||
})
|
||||
|
||||
it('touch', async () => {
|
||||
if (!isAppWebView) {
|
||||
const el = await page.$('#touch-target')
|
||||
await el.touchstart({
|
||||
touches: [{
|
||||
identifier: 1,
|
||||
pageX: 101,
|
||||
pageY: 101,
|
||||
clientX: 101,
|
||||
clientY: 101,
|
||||
screenX: 101,
|
||||
screenY: 101
|
||||
}, ],
|
||||
changedTouches: [{
|
||||
identifier: 1,
|
||||
pageX: 101,
|
||||
pageY: 101,
|
||||
clientX: 101,
|
||||
clientY: 101,
|
||||
screenX: 101,
|
||||
screenY: 101
|
||||
}, ],
|
||||
})
|
||||
await page.waitFor(100)
|
||||
const touchStartTouchTargetIdentifier = '1'
|
||||
const touchStartTouchTargetValue = '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({
|
||||
touches: [{
|
||||
identifier: 1,
|
||||
pageX: 102,
|
||||
pageY: 102,
|
||||
clientX: 102,
|
||||
clientY: 102,
|
||||
screenX: 102,
|
||||
screenY: 102
|
||||
}],
|
||||
changedTouches: [{
|
||||
identifier: 1,
|
||||
pageX: 102,
|
||||
pageY: 102,
|
||||
clientX: 102,
|
||||
clientY: 102,
|
||||
screenX: 102,
|
||||
screenY: 102
|
||||
}, ],
|
||||
})
|
||||
await page.waitFor(100)
|
||||
|
||||
const touchMoveTouchTargetIdentifier = '1'
|
||||
const touchMoveTouchTargetValue = '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({
|
||||
touches: [{
|
||||
identifier: 1,
|
||||
pageX: 103,
|
||||
pageY: 103,
|
||||
clientX: 103,
|
||||
clientY: 103,
|
||||
screenX: 103,
|
||||
screenY: 103
|
||||
}],
|
||||
changedTouches: [{
|
||||
identifier: 1,
|
||||
pageX: 103,
|
||||
pageY: 103,
|
||||
clientX: 103,
|
||||
clientY: 103,
|
||||
screenX: 103,
|
||||
screenY: 103
|
||||
}, ],
|
||||
})
|
||||
await page.waitFor(100)
|
||||
const touchEndTouchTargetIdentifier = '1'
|
||||
const touchEndTouchTargetValue = '103'
|
||||
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 () => {
|
||||
const el = await page.$('#longpress-target')
|
||||
await el.tap()
|
||||
await page.waitFor(100)
|
||||
const targetX = '0'
|
||||
const targetY = '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 () => {
|
||||
if (!isAppWebView) {
|
||||
const el = await page.$('#longpress-target')
|
||||
await el.longpress()
|
||||
await page.waitFor(100)
|
||||
const longPressTouchTargetIdentifier = '1'
|
||||
const longPressTouchTargetValue = '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)
|
||||
|
||||
if (isAndroid || isIos || isHarmony) {
|
||||
await program.tap(tapParams)
|
||||
const longPressTouchIdentifierText = await longPressTouchIdentifier.text()
|
||||
expect(longPressTouchIdentifierText).not.toBe(longPressTouchTargetIdentifier)
|
||||
expect(longPressTouchIdentifierText).toBeTruthy()
|
||||
const longPressTouchPageXText = await longPressTouchPageX.text()
|
||||
expect(longPressTouchPageXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchPageXText).toBeTruthy()
|
||||
const longPressTouchPageYText = await longPressTouchPageY.text()
|
||||
expect(longPressTouchPageYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchPageYText).toBeTruthy()
|
||||
const longPressTouchClientXText = await longPressTouchClientX.text()
|
||||
expect(longPressTouchClientXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchClientXText).toBeTruthy()
|
||||
const longPressTouchClientYText = await longPressTouchClientY.text()
|
||||
expect(longPressTouchClientYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchClientYText).toBeTruthy()
|
||||
const longPressTouchScreenXText = await longPressTouchScreenX.text()
|
||||
expect(longPressTouchScreenXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchScreenXText).toBeTruthy()
|
||||
const longPressTouchScreenYText = await longPressTouchScreenY.text()
|
||||
expect(longPressTouchScreenYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressTouchScreenYText).toBeTruthy()
|
||||
const longPressChangedTouchIdentifierText = await longPressChangedTouchIdentifier.text()
|
||||
expect(longPressChangedTouchIdentifierText).not.toBe(longPressTouchTargetIdentifier)
|
||||
expect(longPressChangedTouchIdentifierText).toBeTruthy()
|
||||
const longPressChangedTouchPageXText = await longPressChangedTouchPageX.text()
|
||||
expect(longPressChangedTouchPageXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchPageXText).toBeTruthy()
|
||||
const longPressChangedTouchPageYText = await longPressChangedTouchPageY.text()
|
||||
expect(longPressChangedTouchPageYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchPageYText).toBeTruthy()
|
||||
const longPressChangedTouchClientXText = await longPressChangedTouchClientX.text()
|
||||
expect(longPressChangedTouchClientXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchClientXText).toBeTruthy()
|
||||
const longPressChangedTouchClientYText = await longPressChangedTouchClientY.text()
|
||||
expect(longPressChangedTouchClientYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchClientYText).toBeTruthy()
|
||||
const longPressChangedTouchScreenXText = await longPressChangedTouchScreenX.text()
|
||||
expect(longPressChangedTouchScreenXText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchScreenXText).toBeTruthy()
|
||||
const longPressChangedTouchScreenYText = await longPressChangedTouchScreenY.text()
|
||||
expect(longPressChangedTouchScreenYText).not.toBe(longPressTouchTargetValue)
|
||||
expect(longPressChangedTouchScreenYText).toBeTruthy()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (isIos || isHarmony) {
|
||||
it('mock tap event', async () => {
|
||||
await page.callMethod('clearAllEvents')
|
||||
|
||||
tapParams.duration = 0
|
||||
await program.tap(tapParams)
|
||||
await page.waitFor(200)
|
||||
|
||||
const clickEventX = await page.$('#click-event-x')
|
||||
const StringX = await clickEventX.text()
|
||||
|
||||
expect(Number(StringX)).toBeGreaterThan(0)
|
||||
const clickEventY = await page.$('#click-event-y')
|
||||
const StringY = await clickEventY.text()
|
||||
expect(Number(StringY)).toBeGreaterThan(0)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,978 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<page-head title="组件全局事件示例"></page-head>
|
||||
<page-intro content="本页演示组件全局事件:触摸区域展示 touchstart/touchmove/touchend/touchcancel,点击区域展示 tap/click/longpress,并显示事件详情与清除;可跳转冒泡、阻止默认、transform 等子示例。"></page-intro>
|
||||
<view class="uni-padding-wrap uni-common-mt container">
|
||||
<view class="section">
|
||||
<text class="section-title">触摸事件区域:touchstart/touchmove/touchend/touchcancel</text>
|
||||
<text class="section-desc">在下方蓝色区域滑动查看触摸事件详情</text>
|
||||
<view class="target touch-area" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
|
||||
@touchmove="onTouchMove" @touchend="onTouchEnd">
|
||||
<text class="target-text">在此区域滑动</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<text class="section-title">点击/长按事件区域:tap/click/longpress</text>
|
||||
<text class="section-desc">点击或长按下方绿色区域查看事件详情</text>
|
||||
<view class="target click-area" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress">
|
||||
<text class="target-text">点击或长按</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section" v-if="touchStartEvent !== null || touchMoveEvent !== null || touchEndEvent !== null || touchCancelEvent !== null || tapEvent !== null || clickEvent !== null || longPressEvent !== null">
|
||||
<view class="clear-btn-wrapper">
|
||||
<button class="clear-btn" @click="clearAllEvents">清除所有事件</button>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="touchStartEvent !== null" class="event-detail">
|
||||
<text class="event-title">touchStart Event(触摸开始事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ touchStartEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ touchStartEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ touchStartEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ touchStartEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="touches-title">event.touches (当前所有触摸点):</text>
|
||||
<template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.touches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier (触摸点标识符):</text>
|
||||
<text class="prop-value" id="touch-start-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="prop-value" id="touch-start-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="prop-value" id="touch-start-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX (相对于可视区域左边):</text>
|
||||
<text class="prop-value" id="touch-start-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY (相对于可视区域顶部):</text>
|
||||
<text class="prop-value" id="touch-start-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-start-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-start-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force (触摸点的压力大小):</text>
|
||||
<text class="prop-value" id="touch-start-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<text class="touches-title">event.changedTouches (变化的触摸点):</text>
|
||||
<template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.changedTouches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force:</text>
|
||||
<text class="prop-value" id="touch-start-changed-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
<view v-if="touchCancelEvent !== null" class="event-detail">
|
||||
<text class="event-title">touchCancel Event(触摸取消事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ touchCancelEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ touchCancelEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ touchCancelEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ touchCancelEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="touches-title">event.touches (当前所有触摸点):</text>
|
||||
<template v-for="(touch, index) in touchCancelEvent!.touches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.touches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier (触摸点标识符):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-identifier">{{
|
||||
touch.identifier
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX (相对于可视区域左边):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY (相对于可视区域顶部):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force (触摸点的压力大小):</text>
|
||||
<text class="prop-value" id="touch-cancel-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<text class="touches-title">event.changedTouches (变化的触摸点):</text>
|
||||
<template v-for="(touch, index) in touchCancelEvent!.changedTouches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.changedTouches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-identifier">{{
|
||||
touch.identifier
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-page-x">{{
|
||||
touch.pageX
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-page-y">{{
|
||||
touch.pageY
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-client-x">{{
|
||||
touch.clientX
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-client-y">{{
|
||||
touch.clientY
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-screen-x">{{
|
||||
touch.screenX
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-screen-y">{{
|
||||
touch.screenY
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force:</text>
|
||||
<text class="prop-value" id="touch-cancel-changed-touch-force">{{
|
||||
touch.force
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
<view v-if="touchMoveEvent !== null" class="event-detail">
|
||||
<text class="event-title">touchMove Event(触摸移动事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ touchMoveEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ touchMoveEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ touchMoveEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ touchMoveEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="touches-title">event.touches (当前所有触摸点):</text>
|
||||
<template v-for="(touch, index) in touchMoveEvent!.touches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.touches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier (触摸点标识符):</text>
|
||||
<text class="prop-value" id="touch-move-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="prop-value" id="touch-move-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="prop-value" id="touch-move-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX (相对于可视区域左边):</text>
|
||||
<text class="prop-value" id="touch-move-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY (相对于可视区域顶部):</text>
|
||||
<text class="prop-value" id="touch-move-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-move-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-move-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force (触摸点的压力大小):</text>
|
||||
<text class="prop-value" id="touch-move-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<text class="touches-title">event.changedTouches (变化的触摸点):</text>
|
||||
<template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.changedTouches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force:</text>
|
||||
<text class="prop-value" id="touch-move-changed-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
<view v-if="touchEndEvent !== null" class="event-detail">
|
||||
<text class="event-title">touchEnd Event(触摸结束事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ touchEndEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ touchEndEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ touchEndEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ touchEndEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="touches-title">event.touches (当前所有触摸点):</text>
|
||||
<template v-for="(touch, index) in touchEndEvent!.touches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.touches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier (触摸点标识符):</text>
|
||||
<text class="prop-value" id="touch-end-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="prop-value" id="touch-end-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="prop-value" id="touch-end-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX (相对于可视区域左边):</text>
|
||||
<text class="prop-value" id="touch-end-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY (相对于可视区域顶部):</text>
|
||||
<text class="prop-value" id="touch-end-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-end-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="prop-value" id="touch-end-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force (触摸点的压力大小):</text>
|
||||
<text class="prop-value" id="touch-end-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<text class="touches-title">event.changedTouches (变化的触摸点):</text>
|
||||
<template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.changedTouches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force:</text>
|
||||
<text class="prop-value" id="touch-end-changed-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
<view v-if="longPressEvent !== null" class="event-detail">
|
||||
<text class="event-title">longPress Event(长按事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ longPressEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ longPressEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ longPressEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ longPressEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="touches-title">event.touches (当前所有触摸点):</text>
|
||||
<template v-for="(touch, index) in longPressEvent!.touches"
|
||||
:key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.touches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier (触摸点标识符):</text>
|
||||
<text class="prop-value" id="long-press-touch-identifier">{{ touch.identifier }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="prop-value" id="long-press-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="prop-value" id="long-press-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX (相对于可视区域左边):</text>
|
||||
<text class="prop-value" id="long-press-touch-client-x">{{ touch.clientX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY (相对于可视区域顶部):</text>
|
||||
<text class="prop-value" id="long-press-touch-client-y">{{ touch.clientY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="prop-value" id="long-press-touch-screen-x">{{ touch.screenX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="prop-value" id="long-press-touch-screen-y">{{ touch.screenY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force (触摸点的压力大小):</text>
|
||||
<text class="prop-value" id="long-press-touch-force">{{ touch.force }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<!-- #ifndef MP-ALIPAY -->
|
||||
<text class="touches-title">event.changedTouches (变化的触摸点):</text>
|
||||
<template v-for="(touch, index) in longPressEvent!.changedTouches" :key="index">
|
||||
<view class="touch-item">
|
||||
<text class="touch-index">event.changedTouches[{{ index }}]:</text>
|
||||
<view class="touch-props">
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .identifier:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-identifier">{{
|
||||
touch.identifier
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageX:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-page-x">{{ touch.pageX }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .pageY:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-page-y">{{ touch.pageY }}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientX:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-client-x">{{
|
||||
touch.clientX
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .clientY:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-client-y">{{
|
||||
touch.clientY
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenX:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-screen-x">{{
|
||||
touch.screenX
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .screenY:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-screen-y">{{
|
||||
touch.screenY
|
||||
}}</text>
|
||||
</view>
|
||||
<view class="prop-row">
|
||||
<text class="prop-label"> .force:</text>
|
||||
<text class="prop-value" id="long-press-changed-touch-force">{{
|
||||
touch.force
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
<view v-if="tapEvent !== null" class="event-detail">
|
||||
<text class="event-title">tap Event(点击事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ tapEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ tapEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ tapEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ tapEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">PointerEvent 位置信息:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.x (同clientX):</text>
|
||||
<text class="info-value" id="tap-event-x">{{ tapEvent!.x }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.y (同clientY):</text>
|
||||
<text class="info-value" id="tap-event-y">{{ tapEvent!.y }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.clientX (相对于可视区域左边):</text>
|
||||
<text class="info-value">{{ tapEvent!.clientX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.clientY (相对于可视区域顶部):</text>
|
||||
<text class="info-value">{{ tapEvent!.clientY }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="info-value">{{ tapEvent!.pageX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="info-value">{{ tapEvent!.pageY }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="info-value">{{ tapEvent!.screenX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="info-value">{{ tapEvent!.screenY }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="clickEvent !== null" class="event-detail">
|
||||
<text class="event-title">click Event(点击事件)</text>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">UniEvent 基础属性:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.type (事件类型):</text>
|
||||
<text class="info-value">{{ clickEvent!.type }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.bubbles (是否冒泡):</text>
|
||||
<text class="info-value">{{ clickEvent!.bubbles }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.cancelable (是否可取消):</text>
|
||||
<text class="info-value">{{ clickEvent!.cancelable }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.timeStamp (时间戳):</text>
|
||||
<text class="info-value">{{ clickEvent!.timeStamp }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="event-base-info">
|
||||
<text class="info-title">PointerEvent 位置信息:</text>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.x (同clientX):</text>
|
||||
<text class="info-value" id="click-event-x">{{ clickEvent!.x }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.y (同clientY):</text>
|
||||
<text class="info-value" id="click-event-y">{{ clickEvent!.y }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.clientX (相对于可视区域左边):</text>
|
||||
<text class="info-value">{{ clickEvent!.clientX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.clientY (相对于可视区域顶部):</text>
|
||||
<text class="info-value">{{ clickEvent!.clientY }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.pageX (相对于页面左边,含滚动):</text>
|
||||
<text class="info-value">{{ clickEvent!.pageX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.pageY (相对于页面顶部,含滚动):</text>
|
||||
<text class="info-value">{{ clickEvent!.pageY }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.screenX (相对于屏幕左边,不含滚动):</text>
|
||||
<text class="info-value">{{ clickEvent!.screenX }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">event.screenY (相对于屏幕顶部,不含滚动):</text>
|
||||
<text class="info-value">{{ clickEvent!.screenY }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
const title = ref('global-events')
|
||||
const touchStartEvent = ref<TouchEvent | null>(null)
|
||||
const touchCancelEvent = ref<TouchEvent | null>(null)
|
||||
const touchMoveEvent = ref<TouchEvent | null>(null)
|
||||
const longPressEvent = ref<TouchEvent | null>(null)
|
||||
const touchEndEvent = ref<TouchEvent | null>(null)
|
||||
const tapEvent = ref<PointerEvent | null>(null)
|
||||
const clickEvent = ref<PointerEvent | null>(null)
|
||||
|
||||
type Rect = {
|
||||
x: number
|
||||
y: number
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
const longPressTargetRect = reactive<Rect>({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 0,
|
||||
height: 0,
|
||||
})
|
||||
// 获取 #longpress-target 位置信息,供自动化测试使用
|
||||
// #ifndef MP
|
||||
onReady(() => {
|
||||
const longpressTarget = uni.getElementById('longpress-target')!
|
||||
const rect = longpressTarget.getBoundingClientRect()
|
||||
longPressTargetRect.x = rect.x
|
||||
longPressTargetRect.y = rect.y
|
||||
longPressTargetRect.width = rect.width
|
||||
longPressTargetRect.height = rect.height
|
||||
})
|
||||
// #endif
|
||||
// #ifdef MP
|
||||
onReady(async () => {
|
||||
const longpressTarget = uni.getElementById('longpress-target')!
|
||||
const rect = await longpressTarget.getBoundingClientRectAsync()!
|
||||
longPressTargetRect.x = rect.x
|
||||
longPressTargetRect.y = rect.y
|
||||
longPressTargetRect.width = rect.width
|
||||
longPressTargetRect.height = rect.height
|
||||
})
|
||||
// #endif
|
||||
|
||||
const onTouchStart = (e : TouchEvent) => {
|
||||
touchStartEvent.value = e
|
||||
console.log('onTouchStart', e)
|
||||
}
|
||||
|
||||
const onTouchCancel = (e : TouchEvent) => {
|
||||
touchCancelEvent.value = e
|
||||
console.log('onTouchCancel')
|
||||
}
|
||||
|
||||
const onTouchMove = (e : TouchEvent) => {
|
||||
touchMoveEvent.value = e
|
||||
console.log('onTouchMove', e)
|
||||
}
|
||||
|
||||
const onLongPress = (e : TouchEvent) => {
|
||||
longPressEvent.value = e
|
||||
console.log('onLongPress', e)
|
||||
}
|
||||
|
||||
const onTouchEnd = (e : TouchEvent) => {
|
||||
touchEndEvent.value = e
|
||||
console.log('onTouchEnd', e)
|
||||
}
|
||||
|
||||
const onTap = (e : PointerEvent) => {
|
||||
tapEvent.value = e
|
||||
// tap 和 longPress 在同一个元素上,tap 触发时清除 longPress 事件
|
||||
longPressEvent.value = null
|
||||
console.log('onTap', e)
|
||||
}
|
||||
|
||||
const onClick = (e : PointerEvent) => {
|
||||
clickEvent.value = e
|
||||
// click 和 longPress 在同一个元素上,click 触发时清除 longPress 事件
|
||||
longPressEvent.value = null
|
||||
console.log('onClick', e)
|
||||
}
|
||||
|
||||
const clearAllEvents = () => {
|
||||
touchStartEvent.value = null
|
||||
touchCancelEvent.value = null
|
||||
touchMoveEvent.value = null
|
||||
longPressEvent.value = null
|
||||
touchEndEvent.value = null
|
||||
tapEvent.value = null
|
||||
clickEvent.value = null
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
clearAllEvents,
|
||||
longPressTargetRect
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.target {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.touch-area {
|
||||
background-color: #409eff;
|
||||
}
|
||||
|
||||
.click-area {
|
||||
background-color: #67c23a;
|
||||
}
|
||||
|
||||
.target-text {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.clear-btn-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
width: 100%;
|
||||
background-color: #f56c6c;
|
||||
color: #fff;
|
||||
padding: 12px 0;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.event-detail {
|
||||
background-color: #f5f7fa;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.event-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.event-base-info {
|
||||
background-color: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.info-title {
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
color: #606266;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
flex: 0 0 120px;
|
||||
max-width: 120px;
|
||||
margin-right: 10px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
flex: 1;
|
||||
min-width: 60px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.touches-title {
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
color: #606266;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.touch-item {
|
||||
background-color: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.touch-index {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: #409eff;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.touch-props {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.prop-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 6px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.prop-label {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
flex: 0 0 120px;
|
||||
max-width: 120px;
|
||||
margin-right: 8px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.prop-value {
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
font-weight: bold;
|
||||
flex: 1;
|
||||
min-width: 60px;
|
||||
text-align: right;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.title1 {
|
||||
margin-top: 15px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.title2 {
|
||||
margin-top: 10px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.title3 {
|
||||
margin-top: 5px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.uni-list-cell {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,68 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
|
||||
const PAGE_PATH = '/pages/component/global-events/touch-events-bubbles'
|
||||
|
||||
describe('touch-events-test', () => {
|
||||
|
||||
if (isAndroid || isWeb || isMP || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
await page.waitFor(2000);
|
||||
})
|
||||
|
||||
it('touch-event-bubbles-test1', async () => {
|
||||
const pageData = await page.data('data')
|
||||
let iconRect = pageData.iconRect
|
||||
if (isHarmony && iconRect.x < 20) {
|
||||
iconRect.x = 144
|
||||
}
|
||||
let x = iconRect.x + 10
|
||||
let y = iconRect.y + 25
|
||||
|
||||
// 滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x: x, y: y},
|
||||
endPoint: {x: x,y: y+15},
|
||||
duration: 200
|
||||
})
|
||||
|
||||
await page.waitFor(1500);
|
||||
await page.callMethod('isPassTest1')
|
||||
const ret = await page.data('data.ret1')
|
||||
expect(ret).toBe(true)
|
||||
})
|
||||
|
||||
it('touch-event-bubbles-test2', async () => {
|
||||
const pageData = await page.data('data')
|
||||
let viewEleRect = pageData.viewEleRect
|
||||
if (isHarmony && viewEleRect.x < 20) {
|
||||
viewEleRect.x = 144
|
||||
}
|
||||
let x = Math.ceil(viewEleRect.x + 10)
|
||||
let y = Math.ceil(viewEleRect.y + 25)
|
||||
|
||||
// 滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x: x, y: y},
|
||||
endPoint: {x: x,y: y+15},
|
||||
duration: 200
|
||||
})
|
||||
|
||||
await page.waitFor(1500);
|
||||
await page.callMethod('isPassTest2')
|
||||
const ret = await page.data('data.ret2')
|
||||
expect(ret).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,157 @@
|
||||
<template>
|
||||
<scroll-view style="flex: 1">
|
||||
<page-head title="事件冒泡测试"></page-head>
|
||||
<view class="container">
|
||||
<view class="view-box" id="view1" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
|
||||
<view class="mid-view" id="view1-2" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
|
||||
<image class="icon" id="view1-3" src="../image/logo.png" @touchstart="onTouchStart" @touchmove="onTouchMove"
|
||||
@touchend="onTouchEnd"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="view-box" id="view2" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
|
||||
<view class="mid-view" id="view2-2" @touchend="onTouchEnd">
|
||||
<view style="background-color: beige;" class="icon" id="view2-3" @touchstart="onTouchStart" @touchend="onTouchEnd"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
|
||||
type DataType = {
|
||||
iconRect: DOMRect | null,
|
||||
viewEleRect: DOMRect | null,
|
||||
ret1: boolean,
|
||||
ret2: boolean,
|
||||
}
|
||||
|
||||
const touchstartValue = ref([] as string[])
|
||||
const touchmoveValue = ref([] as string[])
|
||||
const touchendValue = ref([] as string[])
|
||||
const data = reactive({
|
||||
iconRect: null as DOMRect | null,
|
||||
viewEleRect: null as DOMRect | null,
|
||||
ret1: false,
|
||||
ret2: false,
|
||||
} as DataType)
|
||||
|
||||
function clearValue() {
|
||||
touchstartValue.value = []
|
||||
touchmoveValue.value = []
|
||||
touchendValue.value = []
|
||||
}
|
||||
|
||||
function isPassTest1() {
|
||||
let touchStart = touchstartValue.value.join("")
|
||||
let touchMove = touchmoveValue.value.join("")
|
||||
let touchEnd = touchendValue.value.join("")
|
||||
console.log("touchStart: ", touchStart)
|
||||
console.log("touchMove: ", touchMove)
|
||||
console.log("touchEnd: ", touchEnd)
|
||||
|
||||
let result = touchStart == "view1-3view1-2view1" &&
|
||||
touchMove == "view1-3view1-2view1" &&
|
||||
touchEnd == "view1-3view1-2view1"
|
||||
console.log('isPassTest1', result)
|
||||
data.ret1 = result
|
||||
clearValue()
|
||||
}
|
||||
|
||||
function isPassTest2() {
|
||||
let touchStart = touchstartValue.value.join("")
|
||||
let touchMove = touchmoveValue.value.join("")
|
||||
let touchEnd = touchendValue.value.join("")
|
||||
console.log("touchStart: ", touchStart)
|
||||
console.log("touchMove: ", touchMove)
|
||||
console.log("touchEnd: ", touchEnd)
|
||||
|
||||
let result = touchStart == "view2-3view2" &&
|
||||
touchMove == "view2" &&
|
||||
touchEnd == "view2-3view2-2view2"
|
||||
console.log('isPassTest2', result)
|
||||
data.ret2 = result
|
||||
clearValue()
|
||||
}
|
||||
|
||||
function onTouchStart(e : TouchEvent) {
|
||||
let _id = e.currentTarget!.getAttribute("id") as string
|
||||
if (!touchstartValue.value.includes(_id)) {
|
||||
touchstartValue.value.push(_id)
|
||||
}
|
||||
console.log('onTouchStart', e.currentTarget!.getAttribute("id"))
|
||||
}
|
||||
|
||||
function onTouchMove(e : TouchEvent) {
|
||||
let _id = e.currentTarget!.getAttribute("id") as string
|
||||
if (!touchmoveValue.value.includes(_id)) {
|
||||
touchmoveValue.value.push(_id)
|
||||
}
|
||||
console.log('onTouchMove', e.currentTarget!.getAttribute("id"))
|
||||
}
|
||||
|
||||
function onTouchEnd(e : TouchEvent) {
|
||||
let _id = e.currentTarget!.getAttribute("id") as string
|
||||
if (!touchendValue.value.includes(_id)) {
|
||||
touchendValue.value.push(_id)
|
||||
}
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
// #ifdef APP-IOS || APP-HARMONY
|
||||
let iconEle = uni.getElementById("view1-3")
|
||||
data.iconRect = iconEle?.getBoundingClientRect() ?? null
|
||||
// 加上导航栏及状态栏高度
|
||||
if (data.iconRect != null) {
|
||||
data.iconRect.y += uni.getSystemInfoSync().safeArea.top + 44
|
||||
}
|
||||
|
||||
let viewEle = uni.getElementById("view2-3")
|
||||
data.viewEleRect = viewEle?.getBoundingClientRect() ?? null
|
||||
// 加上导航栏及状态栏高度
|
||||
if (data.viewEleRect != null) {
|
||||
data.viewEleRect.y += uni.getSystemInfoSync().safeArea.top + 44
|
||||
}
|
||||
|
||||
// #endif
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
isPassTest1,
|
||||
isPassTest2
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
width: 100%;
|
||||
height: 80%;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.view-box {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.mid-view {
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: aqua;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
const PAGE_PATH = '/pages/component/global-events/touch-events-case'
|
||||
|
||||
describe('touch-events-test', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
|
||||
if (isWeb || isMP) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
|
||||
it('跳过横屏模式', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
})
|
||||
|
||||
it('touch-event-case1', async () => {
|
||||
let x = 40
|
||||
let y = 150
|
||||
|
||||
// 滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x, y},
|
||||
endPoint: {x: x + 300, y},
|
||||
duration: 300
|
||||
})
|
||||
|
||||
await page.waitFor(1500);
|
||||
const swiperChangeEvent = await page.data('data.swiperChangeEvent')
|
||||
expect(swiperChangeEvent).toBe(true)
|
||||
})
|
||||
|
||||
it('touch-event-case2', async () => {
|
||||
const viewTouchEvent = await page.data('data.viewTouchEvent')
|
||||
const swiperItemTouchEvent = await page.data('data.swiperItemTouchEvent')
|
||||
const swiperTouchEvent = await page.data('data.swiperTouchEvent')
|
||||
let ret = viewTouchEvent && swiperItemTouchEvent && swiperTouchEvent
|
||||
expect(ret).toBe(true)
|
||||
})
|
||||
|
||||
// if (isHarmony && platformInfo.indexOf('14') > -1) {
|
||||
if (isHarmony) {
|
||||
console.log('跳过鸿蒙14的测试,鸿蒙14的swiper组件不支持preventDefault stopPropagation')
|
||||
return
|
||||
}
|
||||
|
||||
it('test swiper preventDefault stopPropagation', async () => {
|
||||
await page.waitFor(1500);
|
||||
await page.callMethod('resetEvent')
|
||||
let x = 25
|
||||
let y = 150
|
||||
|
||||
// 滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x, y},
|
||||
endPoint: {x: x+200,y},
|
||||
duration: 300
|
||||
})
|
||||
|
||||
await page.waitFor(1500);
|
||||
const swiperChangeEvent = await page.data('data.swiperChangeEvent')
|
||||
// harmony 依赖 API 15+
|
||||
console.log("swiperChangeEvent:", swiperChangeEvent)
|
||||
expect(swiperChangeEvent).toBe(false)
|
||||
})
|
||||
|
||||
it('touch-event-case4', async () => {
|
||||
const viewTouchEvent = await page.data('data.viewTouchEvent')
|
||||
const swiperItemTouchEvent = await page.data('data.swiperItemTouchEvent')
|
||||
const swiperTouchEvent = await page.data('data.swiperTouchEvent')
|
||||
let ret = viewTouchEvent && !swiperItemTouchEvent && !swiperTouchEvent
|
||||
expect(ret).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<view>
|
||||
<swiper ref="header" class="h-300" indicator-dots="true" circular="true" @change="swiperChange" @touchstart="swiperTouchStart" @touchmove="swiperTouchMove" @touchend="swiperTouchEnd">
|
||||
<swiper-item v-for="i in 3" :item-id="i + ''" @touchstart="swiperItemTouchStart" @touchmove="swiperItemTouchMove" @touchend="swiperItemTouchEnd">
|
||||
<view class="h-300 header-tiem" @touchstart="viewTouchStart" @touchmove="viewTouchMove" @touchend="viewTouchEnd">
|
||||
<text>{{ i }}</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view class="content">
|
||||
<boolean-data :defaultValue="false" title="stopPropagation" @change="changeStopPropagation"></boolean-data>
|
||||
<boolean-data :defaultValue="false" title="preventDefault" @change="changePreventDefault"></boolean-data>
|
||||
<text style="padding: 10px;">{{ touchResult }}</text>
|
||||
<view class="uni-padding-wrap uni-common-mt" style="bottom: 20px;">
|
||||
<navigator url="/pages/component/global-events/touch-events-preventDefault" hover-class="none">
|
||||
<button type="default" class="button">
|
||||
测试 preventDefault
|
||||
</button>
|
||||
</navigator>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
|
||||
type DataType = {
|
||||
swiperChangeEvent: boolean,
|
||||
viewTouchEvent: boolean,
|
||||
swiperItemTouchEvent: boolean,
|
||||
swiperTouchEvent: boolean,
|
||||
}
|
||||
|
||||
const stopPropagation = ref(false)
|
||||
const preventDefault = ref(false)
|
||||
const touchResult = ref("")
|
||||
const data = reactive({
|
||||
swiperChangeEvent: false,
|
||||
viewTouchEvent: false,
|
||||
swiperItemTouchEvent: false,
|
||||
swiperTouchEvent: false,
|
||||
} as DataType)
|
||||
|
||||
function changeStopPropagation(value: boolean) {
|
||||
stopPropagation.value = value
|
||||
}
|
||||
|
||||
function changePreventDefault(value: boolean) {
|
||||
preventDefault.value = value
|
||||
}
|
||||
|
||||
function swiperChange(e: UniSwiperChangeEvent) {
|
||||
console.log("swiperChange", e.detail.current)
|
||||
data.swiperChangeEvent = true
|
||||
}
|
||||
|
||||
function viewTouchStart(e: UniTouchEvent) {
|
||||
console.log("viewTouchStart")
|
||||
touchResult.value = "viewTouchStart"
|
||||
data.viewTouchEvent = true
|
||||
if (stopPropagation.value) e.stopPropagation()
|
||||
if (preventDefault.value) e.preventDefault()
|
||||
}
|
||||
|
||||
function viewTouchMove(e: UniTouchEvent) {
|
||||
console.log("viewTouchMove")
|
||||
touchResult.value = "viewTouchMove"
|
||||
data.viewTouchEvent = true
|
||||
if (stopPropagation.value) e.stopPropagation()
|
||||
if (preventDefault.value) e.preventDefault()
|
||||
}
|
||||
|
||||
function viewTouchEnd(e: UniTouchEvent) {
|
||||
console.log("viewTouchEnd")
|
||||
touchResult.value = "viewTouchEnd"
|
||||
if (stopPropagation.value) e.stopPropagation()
|
||||
}
|
||||
|
||||
function swiperItemTouchStart(e: UniTouchEvent) {
|
||||
console.log("swiperItemTouchStart")
|
||||
touchResult.value += " -> swiperItemTouchStart"
|
||||
data.swiperItemTouchEvent = true
|
||||
}
|
||||
|
||||
function swiperItemTouchMove(e: UniTouchEvent) {
|
||||
console.log("swiperItemTouchMove")
|
||||
touchResult.value += " -> swiperItemTouchMove"
|
||||
}
|
||||
|
||||
function swiperItemTouchEnd(e: UniTouchEvent) {
|
||||
console.log("swiperItemTouchEnd")
|
||||
touchResult.value += " -> swiperItemTouchEnd"
|
||||
}
|
||||
|
||||
function swiperTouchStart(e: UniTouchEvent) {
|
||||
console.log("swiperTouchStart")
|
||||
touchResult.value += " -> swiperTouchStart"
|
||||
data.swiperTouchEvent = true
|
||||
}
|
||||
|
||||
function swiperTouchMove(e: UniTouchEvent) {
|
||||
console.log("swiperTouchMove")
|
||||
touchResult.value += " -> swiperTouchMove"
|
||||
}
|
||||
|
||||
function swiperTouchEnd(e: UniTouchEvent) {
|
||||
console.log("swiperTouchEnd")
|
||||
touchResult.value += " -> swiperTouchEnd"
|
||||
}
|
||||
|
||||
function resetEvent() {
|
||||
data.swiperChangeEvent = false
|
||||
data.viewTouchEvent = false
|
||||
data.swiperItemTouchEvent = false
|
||||
data.swiperTouchEvent = false
|
||||
stopPropagation.value = true
|
||||
preventDefault.value = true
|
||||
}
|
||||
|
||||
function isPassTest1() {
|
||||
console.log("swiperChangeEvent:", data.swiperChangeEvent)
|
||||
return data.swiperChangeEvent == false
|
||||
}
|
||||
|
||||
function isPassTest2() {
|
||||
console.log("viewTouchEvent:", data.viewTouchEvent)
|
||||
console.log("swiperItemTouchEvent:", data.swiperItemTouchEvent)
|
||||
console.log("swiperTouchEvent:", data.swiperTouchEvent)
|
||||
return data.viewTouchEvent == true && data.swiperItemTouchEvent == true && data.swiperTouchEvent == true
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
resetEvent
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.h-300{
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.header-tiem {
|
||||
background-color: #89ff8d;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,98 @@
|
||||
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
|
||||
|
||||
describe('test preventDefault click', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
|
||||
|
||||
// TODO: dom1 harmony 暂不支持 touch 事件中 preventDefault 阻止 click
|
||||
if (isWeb || isMP || (isHarmony && !isDom2)) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch("/pages/component/global-events/touch-events-preventDefault-click");
|
||||
await page.waitFor(3000);
|
||||
});
|
||||
|
||||
// 都没有拦截的情况下
|
||||
it('preventDefault with click', async () => {
|
||||
await page.setData({
|
||||
data: {
|
||||
isParentPreventDefault: false,
|
||||
isPreventDefault: false,
|
||||
isParentClickTrigger: false,
|
||||
isClickTrigger: false,
|
||||
}
|
||||
})
|
||||
var eventDomRect = await page.data("data.eventDomRect")
|
||||
await page.waitFor(300);
|
||||
let x = eventDomRect.x + eventDomRect.width / 2.0
|
||||
let y = eventDomRect.y + eventDomRect.height / 2.0
|
||||
await program.tap({
|
||||
x: x,
|
||||
y: y,
|
||||
duration: 100
|
||||
})
|
||||
await page.waitFor(200);
|
||||
const isClickTrigger = await page.data("data.isClickTrigger");
|
||||
expect(isClickTrigger).toEqual(true);
|
||||
const isParentClickTrigger = await page.data("data.isParentClickTrigger");
|
||||
expect(isParentClickTrigger).toEqual(true);
|
||||
});
|
||||
// 子调用preventDefault
|
||||
it('child preventDefault without click', async () => {
|
||||
await page.setData({
|
||||
data: {
|
||||
isParentPreventDefault: false,
|
||||
isPreventDefault: true,
|
||||
isParentClickTrigger: false,
|
||||
isClickTrigger: false,
|
||||
}
|
||||
})
|
||||
var eventDomRect = await page.data("data.eventDomRect")
|
||||
await page.waitFor(300);
|
||||
let x = eventDomRect.x + eventDomRect.width / 2.0
|
||||
let y = eventDomRect.y + eventDomRect.height / 2.0
|
||||
await program.tap({
|
||||
x: x,
|
||||
y: y,
|
||||
duration: 100
|
||||
})
|
||||
await page.waitFor(200);
|
||||
const isClickTrigger = await page.data("data.isClickTrigger");
|
||||
expect(isClickTrigger).toEqual(false);
|
||||
const isParentClickTrigger = await page.data("data.isParentClickTrigger");
|
||||
expect(isParentClickTrigger).toEqual(false);
|
||||
});
|
||||
// 父调用preventDefault
|
||||
it('child preventDefault without click', async () => {
|
||||
await page.setData({
|
||||
data: {
|
||||
isParentPreventDefault: true,
|
||||
isPreventDefault: false,
|
||||
isParentClickTrigger: false,
|
||||
isClickTrigger: false,
|
||||
}
|
||||
})
|
||||
var eventDomRect = await page.data("data.eventDomRect")
|
||||
await page.waitFor(300);
|
||||
let x = eventDomRect.x + eventDomRect.width / 2.0
|
||||
let y = eventDomRect.y + eventDomRect.height / 2.0
|
||||
await program.tap({
|
||||
x: x,
|
||||
y: y,
|
||||
duration: 100
|
||||
})
|
||||
await page.waitFor(200);
|
||||
const isClickTrigger = await page.data("data.isClickTrigger");
|
||||
expect(isClickTrigger).toEqual(false);
|
||||
const isParentClickTrigger = await page.data("data.isParentClickTrigger");
|
||||
expect(isParentClickTrigger).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<view>
|
||||
<view @touchend="onParentTouchEnd" @click="onParentClick"
|
||||
style="padding-bottom: 100px; background-color: darkgrey;">
|
||||
<view id="eventClick" @touchend="onTouchEnd" style="width:100%;height: 300px; background-color: yellow;"
|
||||
@click="onClick">
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
type DataType = {
|
||||
isParentPreventDefault : boolean,
|
||||
isPreventDefault : boolean,
|
||||
isParentClickTrigger : boolean,
|
||||
isClickTrigger : boolean,
|
||||
eventDomRect : DOMRect | null
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
isParentPreventDefault: false,
|
||||
isPreventDefault: false,
|
||||
isParentClickTrigger: false,
|
||||
isClickTrigger: false,
|
||||
eventDomRect: null as DOMRect | null,
|
||||
} as DataType)
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
|
||||
onReady(() => {
|
||||
var element = uni.getElementById("eventClick")
|
||||
data.eventDomRect = element?.getBoundingClientRect()
|
||||
})
|
||||
const onTouchEnd = (e : UniTouchEvent) => {
|
||||
if (data.isPreventDefault) {
|
||||
console.log("执行了preventDefault,不再触发点击事件")
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
const onParentTouchEnd = (e : UniTouchEvent) => {
|
||||
if (data.isParentPreventDefault) {
|
||||
console.log("执行了父的preventDefault,不再触发点击事件")
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
const onClick = () => {
|
||||
console.log("触发了点击事件")
|
||||
data.isClickTrigger = true
|
||||
}
|
||||
|
||||
const onParentClick = () => {
|
||||
console.log("触发了父的点击事件")
|
||||
data.isParentClickTrigger = true
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,53 @@
|
||||
const PAGE_PATH = '/pages/component/global-events/touch-events-preventDefault'
|
||||
|
||||
describe('touch-events-test', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
|
||||
if (isWeb || isMP) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
|
||||
it('跳过横屏模式', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor(500);
|
||||
})
|
||||
|
||||
|
||||
it('touch-event-list-preventdefault', async () => {
|
||||
|
||||
let x = 25
|
||||
let y = 350
|
||||
|
||||
// 横向滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x: x, y: y},
|
||||
endPoint: {x: x+200,y: y},
|
||||
duration: 300
|
||||
})
|
||||
|
||||
// 竖向滑动事件
|
||||
await program.swipe({
|
||||
startPoint: {x: x, y: y},
|
||||
endPoint: {x: x, y: 100},
|
||||
duration: 300
|
||||
})
|
||||
|
||||
await page.waitFor(500);
|
||||
const scrollTop = await page.data('scrollTop')
|
||||
console.log("scrollTop:", scrollTop.value)
|
||||
expect(scrollTop.value).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,78 @@
|
||||
<template>
|
||||
<view style="flex: 1;">
|
||||
<page-head title="横向滑动时阻止默认事件,即阻止页面滚动"></page-head>
|
||||
<view class="uni-padding-wrap uni-common-mt" style="height: 40px; align-items: center;">
|
||||
<text>手势方向:{{direction}}</text>
|
||||
</view>
|
||||
<scroll-view style="flex: 1;" @scroll="onScroll">
|
||||
<view v-for="item in 120" :key="item" class="box" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend">
|
||||
{{item}}
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const scrollTop = reactive({
|
||||
value: 0
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
scrollTop
|
||||
})
|
||||
|
||||
function getDirection(x : number, y : number) {
|
||||
if (x > y && x > 10) {
|
||||
return 'horizontal';
|
||||
}
|
||||
if (y > x && y > 10) {
|
||||
return 'vertical';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
const startX = ref(0)
|
||||
const startY = ref(0)
|
||||
const direction = ref("")
|
||||
|
||||
function touchstart(e : UniTouchEvent) {
|
||||
direction.value = ""
|
||||
startX.value = e.touches[0].clientX
|
||||
startY.value = e.touches[0].clientY
|
||||
}
|
||||
|
||||
function touchend(e : UniTouchEvent) {
|
||||
console.log('>>>>> touchend')
|
||||
direction.value = ""
|
||||
}
|
||||
|
||||
function touchmove(e : UniTouchEvent) {
|
||||
|
||||
const deltaX = e.touches[0].clientX - startX.value
|
||||
const deltaY = e.touches[0].clientY - startY.value
|
||||
if (direction.value == "") {
|
||||
direction.value = getDirection(Math.abs(deltaX), Math.abs(deltaY))
|
||||
}
|
||||
|
||||
//只有横向滑动时才阻止默认事件,即阻止页面滚动
|
||||
if (direction.value != 'horizontal') {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (e.cancelable) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
function onScroll(e: UniScrollEvent) {
|
||||
console.log('>>>>> onScroll', e.detail.scrollTop)
|
||||
scrollTop["value"] = e.detail.scrollTop
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.box {
|
||||
border-bottom: 1px solid #c6d1c3;
|
||||
padding: 16px 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,55 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
|
||||
const PAGE_PATH = '/pages/component/global-events/touch-events'
|
||||
|
||||
describe('touch-events-test', () => {
|
||||
if (isAndroid || isMP || isWeb || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
await page.waitFor(isWeb ? 5000 : 1000);
|
||||
})
|
||||
|
||||
it('screenshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true,
|
||||
});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
});
|
||||
|
||||
// iPad 没点到
|
||||
it('touchStart-tagName-touchCount', async () => {
|
||||
const pageData = await page.data('data')
|
||||
let iconRect = pageData.iconRect
|
||||
let x = iconRect.x + iconRect.width / 2.0
|
||||
let y = iconRect.y + iconRect.height / 2.0
|
||||
|
||||
// 点击图片
|
||||
await program.tap({
|
||||
x: x,
|
||||
y: y,
|
||||
duration: 100
|
||||
})
|
||||
|
||||
await page.waitFor(1500);
|
||||
const touchTargets = await page.data('data.touchTargets')
|
||||
const touchTargetsCount = await page.data('data.touchTargetsCount')
|
||||
|
||||
console.log('touchTargets', touchTargets)
|
||||
console.log('touchTargetsCount', touchTargetsCount)
|
||||
|
||||
expect(touchTargets).toBe("IMAGEIMAGEIMAGEVIEW")
|
||||
expect(touchTargetsCount).toBe(2)
|
||||
})
|
||||
|
||||
})
|
||||
@@ -0,0 +1,173 @@
|
||||
<template>
|
||||
<scroll-view style="flex: 1">
|
||||
<page-head title="拖拽图标测试相关事件"></page-head>
|
||||
<view class="uni-padding-wrap uni-common-mt" style="bottom: 20px;">
|
||||
<navigator url="/pages/component/global-events/touch-events-case" hover-class="none">
|
||||
<button type="default">
|
||||
stopPropagation / preventDefault
|
||||
</button>
|
||||
</navigator>
|
||||
</view>
|
||||
<view class="container">
|
||||
<view class="view-box" @touchstart="onViewTouchStart">
|
||||
<image class="icon" id="icon" src="../image/logo.png" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
|
||||
@touchmove="onTouchMove" @touchend="onTouchEnd"></image>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<view v-if="touchEvent !== null">
|
||||
<text class="title1">touches: </text>
|
||||
<template v-for="(touch, index) in touchEvent!.touches" :key="index">
|
||||
<text class="title2">touch[{{ index }}]:</text>
|
||||
<text>identifier: {{touch.identifier}}</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>
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type DataType = {
|
||||
touchTargets: string,
|
||||
touchTargetsCount: number,
|
||||
iconRect: DOMRect | null,
|
||||
}
|
||||
|
||||
const move = ref(false)
|
||||
const posX = ref(0)
|
||||
const posY = ref(0)
|
||||
const lastX = ref(0)
|
||||
const lastY = ref(0)
|
||||
const dragTouchId = ref(-1)
|
||||
const touchEvent = ref(null as TouchEvent | null)
|
||||
const icon = ref(null as UniElement | null)
|
||||
const data = reactive({
|
||||
touchTargets: "",
|
||||
touchTargetsCount: 0,
|
||||
iconRect: null as DOMRect | null,
|
||||
} as DataType)
|
||||
|
||||
function onViewTouchStart(e : TouchEvent) {
|
||||
data.touchTargets += e.target!.tagName + e.currentTarget!.tagName
|
||||
data.touchTargetsCount++
|
||||
}
|
||||
|
||||
function findTouchByIdentifier(touches : Touch[], identifier : number) : Touch | null {
|
||||
for (let i = 0; i < touches.length; i++) {
|
||||
const touch = touches[i]
|
||||
if (touch.identifier == identifier) {
|
||||
return touch
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function onTouchStart(e : TouchEvent) {
|
||||
data.touchTargetsCount++
|
||||
data.touchTargets += e.target!.tagName + e.currentTarget!.tagName
|
||||
|
||||
touchEvent.value = e
|
||||
if (!move.value) {
|
||||
const startTouch = e.changedTouches.length > 0 ? e.changedTouches[0] : e.touches[0]
|
||||
if (startTouch == null) {
|
||||
return
|
||||
}
|
||||
move.value = true
|
||||
dragTouchId.value = startTouch.identifier
|
||||
posX.value = startTouch.screenX
|
||||
posY.value = startTouch.screenY
|
||||
lastX.value = startTouch.screenX
|
||||
lastY.value = startTouch.screenY
|
||||
}
|
||||
}
|
||||
|
||||
function onTouchMove(e : TouchEvent) {
|
||||
e.preventDefault()
|
||||
touchEvent.value = e
|
||||
let p = findTouchByIdentifier(e.changedTouches, dragTouchId.value)
|
||||
if (p == null) {
|
||||
p = findTouchByIdentifier(e.touches, dragTouchId.value)
|
||||
}
|
||||
if (p == null) {
|
||||
return
|
||||
}
|
||||
if (p.screenX == lastX.value && p.screenY == lastY.value) {
|
||||
return
|
||||
}
|
||||
let x = p.screenX - posX.value
|
||||
let y = p.screenY - posY.value
|
||||
lastX.value = p.screenX
|
||||
lastY.value = p.screenY
|
||||
icon.value?.style?.setProperty('transform', 'translate(' + x + 'px,' + y + 'px)')
|
||||
}
|
||||
|
||||
function resetIcon() {
|
||||
move.value = false;
|
||||
posX.value = 0;
|
||||
posY.value = 0;
|
||||
lastX.value = 0;
|
||||
lastY.value = 0;
|
||||
dragTouchId.value = -1;
|
||||
icon.value?.style?.setProperty('transform', 'translate(0px,0px)')
|
||||
}
|
||||
|
||||
function onTouchEnd(e : TouchEvent) {
|
||||
if (findTouchByIdentifier(e.changedTouches, dragTouchId.value) != null) {
|
||||
resetIcon()
|
||||
touchEvent.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function onTouchCancel(event : TouchEvent) {
|
||||
resetIcon()
|
||||
touchEvent.value = null
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
icon.value = uni.getElementById("icon")
|
||||
// #ifdef APP-IOS || APP-HARMONY
|
||||
data.iconRect = icon.value?.getBoundingClientRect() ?? null
|
||||
// 加上导航栏及状态栏高度
|
||||
if (data.iconRect != null) {
|
||||
data.iconRect.y += uni.getSystemInfoSync().safeArea.top + 44
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.view-box {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.title1 {
|
||||
margin-top: 10px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.title2 {
|
||||
margin-top: 5px;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,29 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
|
||||
describe('transition event', () => {
|
||||
if (isMP) {
|
||||
it('skip', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/component/global-events/transition-events')
|
||||
await page.waitFor(3000);
|
||||
});
|
||||
|
||||
it('transitionend', async () => {
|
||||
await page.callMethod('switchBtn')
|
||||
await page.waitFor(3000)
|
||||
expect(await page.data("data.onTransitionEndTriggr")).toBe(true)
|
||||
await page.callMethod('switchBtn')
|
||||
await page.waitFor(200)
|
||||
expect(await page.data("data.onTransitionEndTriggr")).toBe(false)
|
||||
await page.callMethod('switchBtn')
|
||||
await page.waitFor(3000)
|
||||
expect(await page.data("data.onTransitionEndTriggr")).toBe(true)
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view style="flex:1;" v-if="isShow">
|
||||
<!-- #endif -->
|
||||
<image class="transition-transform" id="transition-transform" @transitionend="onEnd" src="/static/test-image/logo.png"></image>
|
||||
<text class="adjust">对图片设置transform进行旋转,在旋转完成的transitionend事件后,继续旋转</text>
|
||||
<button class="adjust" @click="switchBtn">{{buttonValue}}</button>
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
type DataType = {
|
||||
onTransitionEndTriggr: boolean,
|
||||
}
|
||||
|
||||
let times = 0
|
||||
let element: UniElement | null = null
|
||||
let isStart = false
|
||||
const buttonValue = ref("开启图片旋转")
|
||||
const data = reactive({
|
||||
onTransitionEndTriggr: false,
|
||||
} as DataType)
|
||||
const isShow = ref(false)
|
||||
|
||||
function switchBtn() {
|
||||
if (!isStart) {
|
||||
if (element == null) {
|
||||
element = uni.getElementById('transition-transform')
|
||||
}
|
||||
buttonValue.value = "关闭图片旋转"
|
||||
times = times + 1
|
||||
element!.style.setProperty('transition-duration', '2000ms')
|
||||
element!.style.setProperty('transform', 'rotate(' + times * 360 + 'deg)')
|
||||
isStart = true
|
||||
} else {
|
||||
isStart = false
|
||||
times = 0
|
||||
data.onTransitionEndTriggr = false
|
||||
buttonValue.value = "开启图片旋转"
|
||||
element!.style.setProperty('transition-duration', '0ms')
|
||||
element!.style.setProperty('transform', 'rotate(0deg)')
|
||||
}
|
||||
}
|
||||
|
||||
function onEnd() {
|
||||
console.log('transform transitionend')
|
||||
if (isStart) {
|
||||
times = times + 1
|
||||
element!.style.setProperty('transform', 'rotate(' + times * 360 + 'deg)')
|
||||
data.onTransitionEndTriggr = true
|
||||
}
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
// onReady中动态修改isShow是为了验证非蒸气模式下在安卓手机上子线程中创建节点可能会崩溃的问题,不具备代码参考性。
|
||||
// #ifdef APP-ANDROID && !VUE3-VAPOR
|
||||
class ThreadRunnable extends Runnable {
|
||||
override run() {
|
||||
isShow.value = true
|
||||
}
|
||||
}
|
||||
new Thread(new ThreadRunnable()).start()
|
||||
// #endif
|
||||
// #ifndef APP-ANDROID && !VUE3-VAPOR
|
||||
isShow.value = true
|
||||
// #endif
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
switchBtn
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.adjust {
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.transition-transform {
|
||||
width: 192px;
|
||||
height: 192px;
|
||||
margin: 16px auto;
|
||||
/* border-radius: 50%; */
|
||||
transition-property: transform;
|
||||
transition-timing-function: linear;
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户