提交 28a38994 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

fix: 坐标 tap 使用 getBoundingCentRect 获取位置

上级 8f4087c5
...@@ -292,25 +292,20 @@ describe('event trigger', () => { ...@@ -292,25 +292,20 @@ describe('event trigger', () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view') await page.waitFor('view')
const el = await page.$('#longpress-target')
const size = await el.size() const [
const position = await el.offset() x,
// console.log('position', position) y
// console.log('size', size); ] = await page.callMethod('jest_getRect')
const x = position.left + size.width / 2.0
const y = position.top + size.height / 2.0 expect(x > 0).toBe(true)
const res = await uni.getWindowInfo(); expect(y > 0).toBe(true)
// console.log('res', res.statusBarHeight);
const baseStatusTextHeight = 44
const baseTop = res.statusBarHeight ?? 0
await program.tap({ await program.tap({
x: x, x: x,
y: y + baseTop + baseStatusTextHeight, y: y
duration: 100
}) })
await page.waitFor(500) await page.waitFor(200)
const clickEventX = await page.$('#click-event-x') const clickEventX = await page.$('#click-event-x')
const StringX = await clickEventX.text() const StringX = await clickEventX.text()
...@@ -324,3 +319,4 @@ describe('event trigger', () => { ...@@ -324,3 +319,4 @@ describe('event trigger', () => {
} }
}) })
}) })
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
<view class="uni-padding-wrap uni-common-mt container"> <view class="uni-padding-wrap uni-common-mt container">
<view class="target" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel" <view class="target" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
@touchmove="onTouchMove" @touchend="onTouchEnd"></view> @touchmove="onTouchMove" @touchend="onTouchEnd"></view>
<view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view> <view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view> <view v-if="touchStartEvent !== null">
<view v-if="touchStartEvent !== null">
<text class="title1">touchStart Event: </text> <text class="title1">touchStart Event: </text>
<text class="title2">touches: </text> <text class="title2">touches: </text>
<template v-for="(touch, index) in touchStartEvent!.touches" :key="index"> <template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
...@@ -441,6 +440,8 @@ ...@@ -441,6 +440,8 @@
touchEndEvent: null as TouchEvent | null, touchEndEvent: null as TouchEvent | null,
tapEvent: null as PointerEvent | null, tapEvent: null as PointerEvent | null,
clickEvent: null as PointerEvent | null, clickEvent: null as PointerEvent | null,
jest_click_x: -1,
jest_click_y: -1,
} }
}, },
methods: { methods: {
...@@ -472,6 +473,22 @@ ...@@ -472,6 +473,22 @@
this.clickEvent = e this.clickEvent = e
console.log('onClick', e) console.log('onClick', e)
}, },
jest_getRect() : number[] {
const rect = uni.getElementById('longpress-target')?.getBoundingClientRect()
if (rect != null) {
let ratio = 1
if (uni.getSystemInfoSync().platform == 'android') {
ratio = uni.getSystemInfoSync().devicePixelRatio
}
this.jest_click_x = rect.x * ratio + 20
this.jest_click_y = rect.bottom * ratio + 20
}
return [
this.jest_click_x,
this.jest_click_y
]
}
}, },
} }
</script> </script>
...@@ -502,4 +519,4 @@ ...@@ -502,4 +519,4 @@
margin-top: 5px; margin-top: 5px;
font-size: 16px; font-size: 16px;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册