Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
a4741c42
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看板
提交
a4741c42
编写于
9月 12, 2023
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
notes-info: 补充 selectAll 示例,增加自动化测试
上级
851ba940
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
112 addition
and
40 deletion
+112
-40
pages/API/nodes-info/nodes-info.test.js
pages/API/nodes-info/nodes-info.test.js
+42
-0
pages/API/nodes-info/nodes-info.uvue
pages/API/nodes-info/nodes-info.uvue
+70
-40
未找到文件。
pages/API/nodes-info/nodes-info.test.js
0 → 100644
浏览文件 @
a4741c42
const
PAGE_PATH
=
'
/pages/API/nodes-info/nodes-info
'
describe
(
'
nodes-info
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
get-node-info
'
,
async
()
=>
{
const
btnGetNodeInfo
=
await
page
.
$
(
'
.btn-get-node-info
'
)
await
btnGetNodeInfo
.
tap
()
await
page
.
waitFor
(
50
)
const
data
=
await
page
.
data
()
const
nodeInfo
=
data
.
nodeInfoList
[
0
]
expect
(
nodeInfo
.
left
>
15
).
toBe
(
true
)
expect
(
nodeInfo
.
width
==
150
).
toBe
(
true
)
expect
(
nodeInfo
.
height
==
100
).
toBe
(
true
)
})
it
(
'
get-all-node-info
'
,
async
()
=>
{
const
btnGetAllNodeInfo
=
await
page
.
$
(
'
.btn-get-all-node-info
'
)
await
btnGetAllNodeInfo
.
tap
()
await
page
.
waitFor
(
50
)
const
data
=
await
page
.
data
()
const
nodeInfo1
=
data
.
nodeInfoList
[
0
]
expect
(
nodeInfo1
.
left
>
15
).
toBe
(
true
)
expect
(
nodeInfo1
.
top
>
220
).
toBe
(
true
)
expect
(
nodeInfo1
.
width
==
150
).
toBe
(
true
)
expect
(
nodeInfo1
.
height
==
100
).
toBe
(
true
)
const
nodeInfo2
=
data
.
nodeInfoList
[
1
]
expect
(
nodeInfo2
.
left
>
200
).
toBe
(
true
)
expect
(
nodeInfo2
.
top
>
220
).
toBe
(
true
)
expect
(
nodeInfo2
.
width
==
150
).
toBe
(
true
)
expect
(
nodeInfo2
.
height
==
100
).
toBe
(
true
)
})
})
\ No newline at end of file
pages/API/nodes-info/nodes-info.uvue
浏览文件 @
a4741c42
<template>
<template>
<view>
<view
class="uni-padding-wrap"
>
<page-head :title="title"></page-head>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button>
<button @click="getNodeInfo">getNodeInfo</button>
<button class="btn btn-get-all-node-info" @click="getAllNodeInfo">getAllNodeInfo</button>
<view class="rect-1-2">
<view class="rect rect1"></view>
<view class="rect rect2"></view>
</view>
</view>
<view class="rect" :style="{left: left, width: width, height: height}"></view>
<view class="rect-info-1-2">
<view class="rect-info">
<view class="rect-info" v-for="(nodeInfo, index) in nodeInfoList" :key="index">
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">left: </text>
<text class="node-info-item-k">left: </text>
<text class="node-info-item-v">{{nodeInfo.left}}</text>
<text class="node-info-item-v">{{nodeInfo.left}}</text>
</view>
</view>
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">top: </text>
<text class="node-info-item-k">top: </text>
<text class="node-info-item-v">{{nodeInfo.top}}</text>
<text class="node-info-item-v">{{nodeInfo.top}}</text>
</view>
</view>
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">right: </text>
<text class="node-info-item-k">right: </text>
<text class="node-info-item-v">{{nodeInfo.right}}</text>
<text class="node-info-item-v">{{nodeInfo.right}}</text>
</view>
</view>
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">bottom: </text>
<text class="node-info-item-k">bottom: </text>
<text class="node-info-item-v">{{nodeInfo.bottom}}</text>
<text class="node-info-item-v">{{nodeInfo.bottom}}</text>
</view>
</view>
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">width: </text>
<text class="node-info-item-k">width: </text>
<text class="node-info-item-v">{{nodeInfo.width}}</text>
<text class="node-info-item-v">{{nodeInfo.width}}</text>
</view>
</view>
<view class="node-info-item">
<view class="node-info-item">
<text class="node-info-item-k">height: </text>
<text class="node-info-item-k">height: </text>
<text class="node-info-item-v">{{nodeInfo.height}}</text>
<text class="node-info-item-v">{{nodeInfo.height}}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
...
@@ -39,16 +43,20 @@
...
@@ -39,16 +43,20 @@
data() {
data() {
return {
return {
title: 'createSelectorQuery',
title: 'createSelectorQuery',
nodeInfo: { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 } as NodeInfo,
nodeInfoList: [] as NodeInfo[],
left: 16,
width: 150,
height: 100,
}
}
},
},
methods: {
methods: {
getNodeInfo() {
getNodeInfo() {
uni.createSelectorQuery().select('.rect').boundingClientRect().exec((ret) => {
uni.createSelectorQuery().select('.rect1').boundingClientRect().exec((ret) => {
this.nodeInfo = ret[0] as NodeInfo
this.nodeInfoList.length = 0
this.nodeInfoList.push(ret[0] as NodeInfo)
})
},
getAllNodeInfo() {
uni.createSelectorQuery().selectAll('.rect').boundingClientRect().exec((ret) => {
this.nodeInfoList.length = 0
this.nodeInfoList.push(...(ret[0] as NodeInfo[]))
})
})
}
}
}
}
...
@@ -56,15 +64,37 @@
...
@@ -56,15 +64,37 @@
</script>
</script>
<style>
<style>
.btn {
margin-top: 15px;
}
.rect-1-2 {
flex-direction: row;
margin-top: 15px;
}
.rect {
.rect {
width: 150px;
height: 100px;
}
.rect1 {
background-color: dodgerblue;
background-color: dodgerblue;
margin-top: 50px;
}
.rect2 {
margin-left: auto;
background-color: seagreen;
}
.rect-info-1-2 {
flex-direction: row;
margin-top: 15px;
}
}
.rect-info {
.rect-info {
display: flex
;
flex: 1
;
flex-direction: column;
flex-direction: column;
padding: 15px;
}
}
.node-info-item {
.node-info-item {
...
@@ -72,12 +102,12 @@
...
@@ -72,12 +102,12 @@
}
}
.node-info-item-k {
.node-info-item-k {
width:
100
px;
width:
72
px;
line-height: 2
4px
;
line-height: 2;
}
}
.node-info-item-v {
.node-info-item-v {
font-weight: bold;
font-weight: bold;
line-height: 2
4px
;
line-height: 2;
}
}
</style>
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录