Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
d71e2508
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6072
Star
94
Fork
167
代码
文件
提交
分支
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看板
提交
d71e2508
编写于
4月 20, 2024
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(pageStyle): 新增示例及自动化测试
上级
15b9ab2c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
153 addition
and
71 deletion
+153
-71
pages.json
pages.json
+2
-1
pages/API/get-current-pages/get-current-pages.test.js
pages/API/get-current-pages/get-current-pages.test.js
+52
-26
pages/API/get-current-pages/get-current-pages.uvue
pages/API/get-current-pages/get-current-pages.uvue
+99
-44
未找到文件。
pages.json
浏览文件 @
d71e2508
...
...
@@ -361,7 +361,8 @@
{
"path"
:
"pages/API/get-current-pages/get-current-pages"
,
"style"
:
{
"navigationBarTitleText"
:
"getCurrentPages"
"navigationBarTitleText"
:
"getCurrentPages"
,
"enablePullDownRefresh"
:
true
}
},
{
...
...
pages/API/get-current-pages/get-current-pages.test.js
浏览文件 @
d71e2508
const
HOME_PAGE_PATH
=
'
/pages/tabBar/component
'
const
PAGE_PATH
=
'
/pages/API/get-current-pages/get-current-pages
'
describe
(
'
getCurrentPages
'
,
()
=>
{
let
page
it
(
'
getCurrentPages
'
,
async
()
=>
{
// web 端等待应用首页加载完成
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
const
waitTime
=
process
.
env
.
uniTestPlatformInfo
.
includes
(
'
safari
'
)
?
5000
:
1000
await
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
resolve
()
},
waitTime
)
})
}
page
=
await
program
.
switchTab
(
HOME_PAGE_PATH
)
await
page
.
waitFor
(
1000
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
_getCurrentPages
'
)
await
page
.
waitFor
(
200
)
const
data
=
await
page
.
data
()
expect
(
data
.
checked
).
toBe
(
true
)
})
const
HOME_PAGE_PATH
=
'
/pages/tabBar/component
'
const
PAGE_PATH
=
'
/pages/API/get-current-pages/get-current-pages
'
describe
(
'
getCurrentPages
'
,
()
=>
{
let
page
it
(
'
getCurrentPages
'
,
async
()
=>
{
// web 端等待应用首页加载完成
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
const
waitTime
=
process
.
env
.
uniTestPlatformInfo
.
includes
(
'
safari
'
)
?
5000
:
1000
await
new
Promise
((
resolve
)
=>
{
setTimeout
(()
=>
{
resolve
()
},
waitTime
)
})
}
page
=
await
program
.
switchTab
(
HOME_PAGE_PATH
)
await
page
.
waitFor
(
1000
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
await
page
.
callMethod
(
'
_getCurrentPages
'
)
await
page
.
waitFor
(
200
)
const
data
=
await
page
.
data
()
expect
(
data
.
checked
).
toBe
(
true
)
})
it
(
'
getPageStyle
'
,
async
()
=>
{
await
changeData
(
page
)
const
btn
=
await
page
.
$
(
'
.btn-get-page-style
'
)
await
btn
.
tap
()
await
page
.
waitFor
(
100
)
const
{
currentPageStyle
}
=
await
page
.
data
()
expect
(
currentPageStyle
[
'
enablePullDownRefresh
'
]).
toBe
(
true
)
})
it
(
'
setPageStyle
'
,
async
()
=>
{
await
changeData
(
page
)
const
btn
=
await
page
.
$
(
'
.btn-set-page-style-0
'
)
await
btn
.
tap
()
await
page
.
waitFor
(
100
)
const
{
currentPageStyle
}
=
await
page
.
data
()
expect
(
currentPageStyle
[
'
enablePullDownRefresh
'
]).
toBe
(
false
)
})
})
pages/API/get-current-pages/get-current-pages.uvue
浏览文件 @
d71e2508
<template>
<page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
</template>
</view>
</view>
</template>
<script>
class Page {
constructor(public route : string) {
}
}
export default {
data() {
return {
checked: false,
pages: [] as Page[],
}
},
methods: {
_getCurrentPages: function () {
this.pages.length = 0
const pages = getCurrentPages()
this.pages.push(new Page(pages[0].route))
if (this.pages[0].route.includes('/tabBar/')) {
this.checked = true
}
for (let i = 1; i < pages.length; i++) {
this.pages.push(new Page(pages[i].route))
if (pages[i].route.includes('/tabBar/')) {
this.checked = false
}
}
},
},
}
</script>
<template>
<page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
</template>
</view>
<button class="btn btn-get-page-style" type="primary" @click="getPageStyle">getPageStyle</button>
<button class="btn btn-set-page-style-1" type="default" @click="setPageStyle(true)">setPageStyle(true)</button>
<button class="btn btn-set-page-style-0" type="default" @click="setPageStyle(false)">setPageStyle(false)</button>
<textarea class="textarea" :value="pageStyleText" :maxlength="-1" :auto-height="true"></textarea>
<text class="tips">
当前版本仅支持设置属性 enablePullDownRefresh
</text>
</view>
</template>
<script>
class Page {
constructor(public route : string) {
}
}
export default {
data() {
return {
checked: false,
pages: [] as Page[],
currentPageStyle: {} as UTSJSONObject
}
},
computed: {
pageStyleText() : string {
return JSON.stringify(this.currentPageStyle)
}
},
onPullDownRefresh() {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 3000)
},
methods: {
_getCurrentPages: function () {
this.pages.length = 0
const pages = getCurrentPages()
this.pages.push(new Page(pages[0].route))
if (this.pages[0].route.includes('/tabBar/')) {
this.checked = true
}
for (let i = 1; i < pages.length; i++) {
this.pages.push(new Page(pages[i].route))
if (pages[i].route.includes('/tabBar/')) {
this.checked = false
}
}
},
getPageStyle() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
this.currentPageStyle = currentPage.$getPageStyle();
},
setPageStyle(epr : boolean) {
// 目前仅支持 enablePullDownRefresh
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
currentPage.$setPageStyle({
enablePullDownRefresh: epr
});
},
// getCurrentPage(): Page {
// const pages = getCurrentPages();
// const currentPage = pages[pages.length - 1];
// return currentPage;
// }
},
}
</script>
<style>
.btn {
margin-top: 10px;
}
.textarea {
margin-top: 5px;
padding: 5px;
background-color: #fff;
}
.tips {
font-size: 12px;
margin-top: 10px;
opacity: .8;
}
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录