提交 dc831992 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: getCurrentPages

上级 ba3c10b6
const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages' const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages'
describe('getCurrentPages', () => { describe('getCurrentPages', () => {
let page
it('getCurrentPages', async () => { it('getCurrentPages', async () => {
const page = await program.navigateTo(PAGE_PATH) page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000) await page.waitFor(1000)
await page.callMethod('getCurrentPages') await page.callMethod('_getCurrentPages')
const data = await page.data() const data = await page.data()
expect(data.checked).toBe(true) expect(data.checked).toBe(true)
}) })
it('hideAndShow', async () => {
await page.callMethod('hideAndShow')
await page.waitFor(1000)
const data = await page.data()
expect(data.showTimes).toBe(2)
})
}) })
<template> <template>
<view> <view>
<page-head title="getCurrentPages"></page-head> <page-head title="getCurrentPages"></page-head>
<button @click="getCurrentPages">getCurrentPages</button> <button @click="_getCurrentPages">getCurrentPages</button>
<text>{{result}}</text> <button class="uni-common-mt" @click="hideAndShow">页面隐藏并显示</button>
</view> <view style="padding: 15px 10px">
<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> </template>
<script> <script>
export default { class Page {
data() { constructor(public route : string) {
return { }
checked: false, }
result:"" export default {
data() {
return {
checked: false,
showTimes: 0,
pages: [] as Page[],
}
},
onShow() {
this.showTimes++
},
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++) {
methods: { this.pages.push(new Page(pages[i].route))
getCurrentPages: function () { if (pages[i].route.includes('/tabBar/')) {
const pages = getCurrentPages() this.checked = false
let tmps ="当前页面栈中有" + pages.length.toString() + "个页面。列表如下:\n"
for (let i = 0; i < pages.length; i++) {
tmps = tmps + pages[i].route + "\n"
}
this.result = tmps
// console.log('pages: ',pages.toString());
// TODO 判断条件不对,需要根据自动化测试执行脚本准确验证所有栈内页面
if (pages[0].route.includes('/tabBar/')) {
this.checked = true
}
for (let i = 1; i < pages.length; i++) {
if (pages[i].route.includes('/tabBar/')) {
this.checked = false
}
} }
}, }
}, },
} hideAndShow() {
</script> const pages = getCurrentPages()
\ No newline at end of file const currentPage = pages[pages.length - 1]
const currentPageInstance = currentPage.$getAppPage()
if (currentPageInstance != null) {
currentPageInstance.hide(new Map())
currentPageInstance.show(new Map())
}
}
},
}
</script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册