Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
28a38994
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
28a38994
编写于
10月 15, 2024
作者:
辛宝Otto
🥊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 坐标 tap 使用 getBoundingCentRect 获取位置
上级
8f4087c5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
30 addition
and
17 deletion
+30
-17
pages/component/global-events/global-events.test.js
pages/component/global-events/global-events.test.js
+10
-14
pages/component/global-events/global-events.uvue
pages/component/global-events/global-events.uvue
+20
-3
未找到文件。
pages/component/global-events/global-events.test.js
浏览文件 @
28a38994
...
@@ -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
(
5
00
)
await
page
.
waitFor
(
2
00
)
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', () => {
}
}
})
})
})
})
pages/component/global-events/global-events.uvue
浏览文件 @
28a38994
...
@@ -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>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录