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

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

上级 8f4087c5
......@@ -292,25 +292,20 @@ describe('event trigger', () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
const el = await page.$('#longpress-target')
const size = await el.size()
const position = await el.offset()
// console.log('position', position)
// console.log('size', size);
const x = position.left + size.width / 2.0
const y = position.top + size.height / 2.0
const res = await uni.getWindowInfo();
// console.log('res', res.statusBarHeight);
const baseStatusTextHeight = 44
const baseTop = res.statusBarHeight ?? 0
const [
x,
y
] = await page.callMethod('jest_getRect')
expect(x > 0).toBe(true)
expect(y > 0).toBe(true)
await program.tap({
x: x,
y: y + baseTop + baseStatusTextHeight,
duration: 100
y: y
})
await page.waitFor(500)
await page.waitFor(200)
const clickEventX = await page.$('#click-event-x')
const StringX = await clickEventX.text()
......@@ -324,3 +319,4 @@ describe('event trigger', () => {
}
})
})
......@@ -6,8 +6,7 @@
<view class="uni-padding-wrap uni-common-mt container">
<view class="target" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
@touchmove="onTouchMove" @touchend="onTouchEnd"></view>
<view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view>
<view v-if="touchStartEvent !== null">
<view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view> <view v-if="touchStartEvent !== null">
<text class="title1">touchStart Event: </text>
<text class="title2">touches: </text>
<template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
......@@ -441,6 +440,8 @@
touchEndEvent: null as TouchEvent | null,
tapEvent: null as PointerEvent | null,
clickEvent: null as PointerEvent | null,
jest_click_x: -1,
jest_click_y: -1,
}
},
methods: {
......@@ -472,6 +473,22 @@
this.clickEvent = 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>
......@@ -502,4 +519,4 @@
margin-top: 5px;
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.
先完成此消息的编辑!
想要评论请 注册