From d59a599d86fc84547b4f25adca0a41bb180c2437 Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Wed, 11 Sep 2024 19:22:58 +0800
Subject: [PATCH] =?UTF-8?q?feat(getCurrentPages):=20=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E9=92=88=E5=AF=B9=20UniPage=20=E7=A4=BA=E4=BE=8B=E5=8F=8A?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/API/get-app/get-app.uvue | 4 +-
.../get-current-pages.test.js | 29 +++++-
.../get-current-pages/get-current-pages.uvue | 97 +++++++++++++++++--
3 files changed, 118 insertions(+), 12 deletions(-)
diff --git a/pages/API/get-app/get-app.uvue b/pages/API/get-app/get-app.uvue
index 4fc32f47..bd31778c 100644
--- a/pages/API/get-app/get-app.uvue
+++ b/pages/API/get-app/get-app.uvue
@@ -204,7 +204,7 @@
app.emit('fn3', null)
const res = num == 6
- console.log('checkEventBus', res)
+ console.log('check eventBus', res)
return res
},
checkGetAndroidApplication() : boolean {
@@ -216,7 +216,7 @@
// #ifndef APP-ANDROID
const res = androidApplication == null
// #endif
- console.log('checkGetAndroidApplication', res)
+ console.log('check getAndroidApplication', res)
return res
}
},
diff --git a/pages/API/get-current-pages/get-current-pages.test.js b/pages/API/get-current-pages/get-current-pages.test.js
index 7e377cb8..fe811342 100644
--- a/pages/API/get-current-pages/get-current-pages.test.js
+++ b/pages/API/get-current-pages/get-current-pages.test.js
@@ -1,5 +1,5 @@
const HOME_PAGE_PATH = '/pages/tabBar/component'
-const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages'
+const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages?test=123'
describe('getCurrentPages', () => {
let page
@@ -25,8 +25,6 @@ describe('getCurrentPages', () => {
expect(data.checked).toBe(true)
})
it('page-style', async () => {
- page = await program.navigateTo(PAGE_PATH)
-
await page.callMethod('getPageStyle')
await page.waitFor(200)
const isEnablePullDownRefresh1 = (await page.data()).currentPageStyle.enablePullDownRefresh
@@ -63,4 +61,29 @@ describe('getCurrentPages', () => {
return 'get-current-pages-test-js-get-current-pages-page-style-after-set-page-style'
}});
})
+ it('$page', async () => {
+ await page.setData({testing: true})
+ const res = await page.callMethod('check$page')
+ expect(res).toBe(true)
+ })
+ it('eventBus', async () => {
+ const res = await page.callMethod('checkEventBus')
+ expect(res).toBe(true)
+ })
+ it('getParentPage', async () => {
+ const res = await page.callMethod('checkGetParentPage')
+ expect(res).toBe(true)
+ })
+ it('getDialogPages', async () => {
+ const res = await page.callMethod('checkGetDialogPages')
+ expect(res).toBe(true)
+ })
+ it('getElementById', async () => {
+ const res = await page.callMethod('checkGetElementById')
+ expect(res).toBe(true)
+ })
+ it('getAndroidView', async () => {
+ const res = await page.callMethod('checkGetAndroidView')
+ expect(res).toBe(true)
+ })
})
diff --git a/pages/API/get-current-pages/get-current-pages.uvue b/pages/API/get-current-pages/get-current-pages.uvue
index 3e66d8f3..67901a7a 100644
--- a/pages/API/get-current-pages/get-current-pages.uvue
+++ b/pages/API/get-current-pages/get-current-pages.uvue
@@ -12,8 +12,16 @@
index: {{ index }}, route: {{ page.route }}
+
+
+
+
+
+
+
@@ -59,7 +67,8 @@
checked: false,
pages: [] as Page[],
PageStyleArray: PageStyleArray as PageStyleItem[],
- currentPageStyle: {} as UTSJSONObject,
+ currentPageStyle: {} as UTSJSONObject,
+ testing: false
}
},
computed: {
@@ -125,12 +134,86 @@
uni.navigateTo({
url: '/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh'
});
- }
- // getCurrentPage(): Page {
- // const pages = getCurrentPages();
- // const currentPage = pages[pages.length - 1];
- // return currentPage;
- // }
+ },
+ getCurrentPage() : UniPage {
+ const pages = getCurrentPages()
+ return pages[pages.length - 1]
+ },
+ check$page() : boolean {
+ const page = this.getCurrentPage()
+ let res = this.$page === page
+ if(this.testing){
+ res = res && page.options.get('test') == '123'
+ }
+ console.log('check $page', res)
+ return res
+ },
+ checkEventBus() : boolean {
+ const page = this.getCurrentPage()
+ let num = 0
+ const fn1 = (args : any | null) => {
+ console.log('fn1 triggred', args)
+ num++
+ }
+ const fn2 = (args : any | null) => {
+ console.log('fn2 triggred', args)
+ num++
+ }
+ const fn3 = (args : any | null) => {
+ console.log('fn3 triggred', args)
+ num++
+ }
+
+ page.on('fn12', fn1)
+ page.on('fn12', fn2)
+ page.once('fn3', fn3)
+
+ page.emit('fn12', { name: 'name' })
+ page.emit('fn12', { age: 20 })
+ page.off('fn12', fn1)
+ page.emit('fn12', null)
+
+ page.emit('fn3', { name: 'name' })
+ page.emit('fn3', { age: 20 })
+ page.emit('fn3', null)
+
+ const res = num == 6
+ console.log('check eventBus', res)
+ return res
+ },
+ checkGetParentPage() : boolean {
+ const page = this.getCurrentPage()
+ const parentPage = page.getParentPage()
+ const res = parentPage == null
+ console.log('check getParentPage', res)
+ return res
+ },
+ checkGetDialogPages() : boolean {
+ const page = this.getCurrentPage()
+ const dialogPages = page.getDialogPages()
+ const res = Array.isArray(dialogPages) && dialogPages.length == 0
+ console.log('check getDialogPages', res)
+ return res
+ },
+ checkGetElementById() : boolean {
+ const page = this.getCurrentPage()
+ const element = page.getElementById('check-get-element-by-id-btn')
+ const res = element != null
+ console.log('check getElementById', res)
+ return res
+ },
+ checkGetAndroidView() : boolean {
+ const page = this.getCurrentPage()
+ const androidView = page.getAndroidView()
+ // #ifdef APP-ANDROID
+ const res = androidView != null
+ // #endif
+ // #ifndef APP-ANDROID
+ const res = androidView == null
+ // #endif
+ console.log('check getAndroidView', res)
+ return res
+ },
},
}
--
GitLab