From 95d70664366385871126c798b615a7efce0e7ef7 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 10 Sep 2024 21:22:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=EF=BC=8C=E5=85=BC=E5=AE=B9=20UniPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/dialog-page/dialog-1.uvue | 6 +-- pages/API/dialog-page/dialog-2.uvue | 4 +- .../get-current-pages/get-current-pages.uvue | 6 +-- ...-page-style-disable-pull-down-refresh.uvue | 6 +-- .../set-page-backgroundColorContent.uvue | 6 +-- .../uni-stat/utssdk/common/utils/pageInfo.uts | 46 +++++++++---------- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/pages/API/dialog-page/dialog-1.uvue b/pages/API/dialog-page/dialog-1.uvue index d62e6bc6..12d9d747 100644 --- a/pages/API/dialog-page/dialog-1.uvue +++ b/pages/API/dialog-page/dialog-1.uvue @@ -43,10 +43,10 @@ // 自动化测试 setLifeCycleNum(state.lifeCycleNum + 1) const currentPages = getCurrentPages() - const parentPage = this.getParentPage()! + const parentPage = this.$page.getParentPage()! const grandParentPage = parentPage.getParentPage() const dialogPages = parentPage.getDialogPages() - const dialogPage = this.$dialogPage! + const dialogPage = this.$page as UniDialogPage if ( currentPages.length == 1 && grandParentPage == null && @@ -126,7 +126,7 @@ }, closeThisDialog() { uni.closeDialogPage({ - dialogPage: this.$dialogPage, + dialogPage: this.$page as UniDialogPage, success(res) { console.log('closeThisDialog success', res) // 自动化测试 diff --git a/pages/API/dialog-page/dialog-2.uvue b/pages/API/dialog-page/dialog-2.uvue index f13ae08e..ca71940c 100644 --- a/pages/API/dialog-page/dialog-2.uvue +++ b/pages/API/dialog-page/dialog-2.uvue @@ -93,7 +93,7 @@ }, closeThisDialog() { uni.closeDialogPage({ - dialogPage: this.$dialogPage, + dialogPage: this.$page as UniDialogPage, success(res) { console.log('closeThisDialog success', res) // 自动化测试 @@ -138,4 +138,4 @@ .mt-10 { margin-top: 10px; } - + diff --git a/pages/API/get-current-pages/get-current-pages.uvue b/pages/API/get-current-pages/get-current-pages.uvue index 69d8114f..3e66d8f3 100644 --- a/pages/API/get-current-pages/get-current-pages.uvue +++ b/pages/API/get-current-pages/get-current-pages.uvue @@ -112,14 +112,14 @@ getPageStyle() : UTSJSONObject { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - this.currentPageStyle = currentPage.$getPageStyle() + this.currentPageStyle = currentPage.getPageStyle() return this.currentPageStyle; }, setPageStyle(style : UTSJSONObject) { console.log('setPageStyle:', style); const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - currentPage.$setPageStyle(style); + currentPage.setPageStyle(style); }, goSetDisablePullDownRefresh() { uni.navigateTo({ @@ -175,4 +175,4 @@ .radio-value { margin-left: 10px; } - + diff --git a/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue b/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue index f190e74e..2d8d995b 100644 --- a/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue +++ b/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh.uvue @@ -44,13 +44,13 @@ getPageStyle() { const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - this.currentPageStyle = currentPage.$getPageStyle(); + this.currentPageStyle = currentPage.getPageStyle(); }, setPageStyle(enable : boolean) { // 目前仅支持 enablePullDownRefresh const pages = getCurrentPages(); const currentPage = pages[pages.length - 1]; - currentPage.$setPageStyle({ + currentPage.setPageStyle({ enablePullDownRefresh: enable }); this.enablePullDownRefreshStatus = enable @@ -95,4 +95,4 @@ margin-top: 15px; opacity: .8; } - + diff --git a/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent.uvue b/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent.uvue index b4121e58..473ef629 100644 --- a/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent.uvue +++ b/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent.uvue @@ -16,10 +16,10 @@ changeColor() { let pages = getCurrentPages() let page = pages[pages.length - 1] - page.$setPageStyle({ "backgroundColorContent": this.isChange ? "" : "red" }) + page.setPageStyle({ "backgroundColorContent": this.isChange ? "" : "red" }) this.isChange = !this.isChange - let pageJson = page.$getPageStyle() + let pageJson = page.getPageStyle() this.currentBackgroundColorContent = pageJson["backgroundColorContent"] } } @@ -32,4 +32,4 @@ align-items: center; justify-content: center; } - + diff --git a/uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts b/uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts index c7392118..db20808d 100644 --- a/uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts +++ b/uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts @@ -224,19 +224,16 @@ export const get_page_name = (routepath : string) : string => { if (page.route != routepath) { const pages = getCurrentPages() // 如果传入路由与当前页面不同,则从页面栈找一个,如果找不到返回空 - let page_now = pages.find((v) : boolean => { - if (v.route == routepath) { - return true; - } - return false - }) + let page_now = pages.find((p): boolean => p.route == routepath) if (page_now == null) { return '' - } - page = page_now + } + // @ts-ignore + page = page_now.vm! } - - const pageStyle = page.$getPageStyle() + + // @ts-ignore + const pageStyle = page.$page.getPageStyle() const titleText = pageStyle['navigationBarTitleText'] ?? '' return titleText as string } @@ -250,8 +247,9 @@ export const get_page_vm = () : Page | null => { return null } let page = pages[pages.length - 1] - // TODO 正常来说,调用当前方法的地方只在 生命周期内,数组内最少会有一个页面,所以理论上是不存在获取不到的情况的 - return page + // TODO 正常来说,调用当前方法的地方只在 生命周期内,数组内最少会有一个页面,所以理论上是不存在获取不到的情况的 + // @ts-ignore + return page.vm } @@ -416,17 +414,17 @@ export const uni_cloud_config = () : UniCloudInitOptions | null => { export const get_space = (config : UniCloudInitOptions) : UniCloudInitOptions | null => { const uniCloudConfig = uni_cloud_config() if (uniCloudConfig == null) { - console.log(config); - // #ifdef APP-ANDROID - if (config.spaceId != '') { - return config - } - // #endif - // #ifndef APP-ANDROID - if (config?.spaceId != '') { - return config - } - // #endif + console.log(config); + // #ifdef APP-ANDROID + if (config.spaceId != '') { + return config + } + // #endif + // #ifndef APP-ANDROID + if (config?.spaceId != '') { + return config + } + // #endif return null } @@ -510,4 +508,4 @@ export const calibration = (eventName : string, options : any | null) : boolean return true } return false -} +} -- GitLab