Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
9facd19c
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6067
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9facd19c
编写于
12月 18, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
element-get-attribute补充自定义组件测试
上级
953ba4f9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
150 addition
and
12 deletion
+150
-12
pages/API/element-get-attribute/child.uvue
pages/API/element-get-attribute/child.uvue
+21
-0
pages/API/element-get-attribute/element-get-attribute.test.js
...s/API/element-get-attribute/element-get-attribute.test.js
+21
-1
pages/API/element-get-attribute/element-get-attribute.uvue
pages/API/element-get-attribute/element-get-attribute.uvue
+108
-11
未找到文件。
pages/API/element-get-attribute/child.uvue
0 → 100644
浏览文件 @
9facd19c
<template>
<view class="child-view">
<text class="child-text">我是子组件child</text>
</view>
</template>
<script>
export default {
data() {
return {}
},
}
</script>
<style>
.child-view {
margin-top: 15px;
height: 100px;
background-color: dodgerblue;
}
</style>
pages/API/element-get-attribute/element-get-attribute.test.js
浏览文件 @
9facd19c
...
...
@@ -20,15 +20,35 @@ describe('test element-get-attribute', () => {
if
(
isWeb
||
isMP
){
await
page
.
callMethod
(
'
getAttributeStyle
'
)
console
.
log
(
'
attrStyle:
'
,
await
page
.
data
(
'
attrStyle
'
))
const
attrStyle
=
isMP
?
'
background-color:#FFF000;
'
:
'
padding: 0.625rem;
background-color: rgb(255, 240, 0);
'
const
attrStyle
=
isMP
?
'
background-color:#FFF000;
'
:
'
background-color: rgb(255, 240, 0);
'
expect
(
await
page
.
data
(
'
attrStyle
'
)).
toEqual
(
attrStyle
);
}
});
it
(
'
check getPropertyValue
'
,
async
()
=>
{
await
page
.
callMethod
(
'
getPropertyValue
'
)
await
page
.
waitFor
(
1000
)
const
propertyValue
=
isWeb
?
'
rgb(255, 240, 0)
'
:
'
#FFF000
'
console
.
log
(
'
propertyValue:
'
,
propertyValue
,
await
page
.
data
(
'
propertyValue
'
));
expect
(
await
page
.
data
(
'
propertyValue
'
)).
toEqual
(
propertyValue
);
});
it
(
'
getBoundingClientRectSync
'
,
async
()
=>
{
await
page
.
callMethod
(
"
getBoundingClientRectAsyncChild
"
);
await
page
.
waitFor
(
100
)
const
rectInfo
=
await
page
.
data
(
"
rectInfo
"
)
const
systemInfo
=
await
program
.
systemInfo
();
const
width
=
systemInfo
.
screenWidth
console
.
log
(
'
width:
'
,
width
);
console
.
log
(
'
rectInfo:
'
,
rectInfo
);
expect
(
Math
.
round
(
rectInfo
.
x
)).
toBe
(
15
)
expect
(
Math
.
round
(
rectInfo
.
y
)
>
242
).
toBe
(
true
)
expect
(
width
-
15
*
2
-
Math
.
round
(
rectInfo
.
width
)
>=
0
).
toBe
(
true
)
expect
(
Math
.
round
(
rectInfo
.
height
)).
toBe
(
100
)
expect
(
Math
.
round
(
rectInfo
.
left
)).
toBe
(
15
)
expect
(
Math
.
round
(
rectInfo
.
top
)
>
242
).
toBe
(
true
)
expect
(
width
-
15
-
Math
.
round
(
rectInfo
.
right
)
>=
0
).
toBe
(
true
)
expect
(
Math
.
round
(
rectInfo
.
bottom
)
>
342
).
toBe
(
true
)
})
if
(
isApp
||
isMP
){
it
(
'
check scrollTo
'
,
async
()
=>
{
await
page
.
callMethod
(
'
scrollTo
'
)
...
...
pages/API/element-get-attribute/element-get-attribute.uvue
浏览文件 @
9facd19c
<template>
<view>
<view id="box" ref="box"
style="padding: 20rpx;"
>
<view
style="padding: 15px;"
>
<view id="box" ref="box">
<text class="uni-title-text">元素的id:{{ attrId }}</text>
<!-- #ifndef APP -->
<text class="uni-title-text">元素的style:{{ attrStyle }}</text>
...
...
@@ -15,6 +15,43 @@
<button @click="getAttributeStyle">getAttribute获取元素的style</button>
<!-- #endif -->
<button @click="getPropertyValue">getPropertyValue获取背景色值</button>
<child id="child" ref="child"></child>
<button @click="getBoundingClientRectAsyncChild">获取自定义组件child元素信息</button>
<view class="rect-info" v-if="rectInfo">
<view class="node-info-item">
<text class="node-info-item-k">x: </text>
<text class="node-info-item-v">{{rectInfo.x}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">y: </text>
<text class="node-info-item-v">{{rectInfo.y}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">width: </text>
<text class="node-info-item-v">{{rectInfo.width}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">height: </text>
<text class="node-info-item-v">{{rectInfo.height}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">left: </text>
<text class="node-info-item-v">{{rectInfo.left}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">top: </text>
<text class="node-info-item-v">{{rectInfo.top}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">right: </text>
<text class="node-info-item-v">{{rectInfo.right}}</text>
</view>
<view class="node-info-item">
<text class="node-info-item-k">bottom: </text>
<text class="node-info-item-v">{{rectInfo.bottom}}</text>
</view>
</view>
<scroll-view ref="scrollView" class="scroll-view_H" direction="horizontal">
<view class="scroll-view-item_H uni-bg-red"><text class="text">A</text></view>
<view class="scroll-view-item_H uni-bg-green"><text class="text">B</text></view>
...
...
@@ -26,14 +63,38 @@
</view>
</template>
<script lang="uts">
import child from './child.uvue'
type DomRectType = {
x : number,
y : number,
left : number,
top : number,
right : number,
bottom : number,
width : number,
height : number,
}
export default {
components: {
child
},
data() {
return {
boxTarget: null as null | UniElement,
scrollViewTarget: null as null | UniElement,
attrId: "",
attrStyle:"",
propertyValue:""
propertyValue:"",
rectInfo: {
x: 0,
y: 0,
width: 0,
height: 0,
left: 0,
top: 0,
right: 0,
bottom: 0,
} as DomRectType,
}
},
onReady() {
...
...
@@ -41,15 +102,21 @@
this.scrollViewTarget = this.$refs['scrollView'] as UniElement;
},
methods: {
scrollTo() {
// #ifdef MP-WEIXIN
this.scrollViewTarget!.scrollTo({
left: 200
getBoundingClientRectAsyncChild(){
const childEl = uni.getElementById('child')!
childEl.getBoundingClientRectAsync()!.then((rect : DOMRect) => {
console.log('rect: ',rect);
this.rectInfo = {
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
left: rect.left,
top: rect.top,
right: rect.right,
bottom: rect.bottom,
} as DomRectType;;
})
// #endif
// #ifndef MP-WEIXIN
this.scrollViewTarget!.scrollTo(200,0)
// #endif
},
getAttributeId() {
this.attrId = this.boxTarget!.getAttribute('id') ?? ""
...
...
@@ -62,6 +129,16 @@
},
getAttributeStyle() {
this.attrStyle = this.boxTarget!.getAttribute('style')?? ""
},
scrollTo() {
// #ifdef MP-WEIXIN
this.scrollViewTarget!.scrollTo({
left: 200
})
// #endif
// #ifndef MP-WEIXIN
this.scrollViewTarget!.scrollTo(200,0)
// #endif
}
}
}
...
...
@@ -82,4 +159,24 @@
font-size: 18px;
color: #ffffff;
}
.rect-info {
margin-top: 15px;
padding: 20rpx;
flex-direction: column;
}
.node-info-item {
flex-direction: row;
}
.node-info-item-k {
width: 72px;
line-height: 2;
}
.node-info-item-v {
font-weight: bold;
line-height: 2;
}
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录