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

refactor: 调整示例,兼容 UniPage

上级 78555572
...@@ -43,10 +43,10 @@ ...@@ -43,10 +43,10 @@
// 自动化测试 // 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1) setLifeCycleNum(state.lifeCycleNum + 1)
const currentPages = getCurrentPages() const currentPages = getCurrentPages()
const parentPage = this.getParentPage()! const parentPage = this.$page.getParentPage()!
const grandParentPage = parentPage.getParentPage() const grandParentPage = parentPage.getParentPage()
const dialogPages = parentPage.getDialogPages() const dialogPages = parentPage.getDialogPages()
const dialogPage = this.$dialogPage! const dialogPage = this.$page as UniDialogPage
if ( if (
currentPages.length == 1 && currentPages.length == 1 &&
grandParentPage == null && grandParentPage == null &&
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
}, },
closeThisDialog() { closeThisDialog() {
uni.closeDialogPage({ uni.closeDialogPage({
dialogPage: this.$dialogPage, dialogPage: this.$page as UniDialogPage,
success(res) { success(res) {
console.log('closeThisDialog success', res) console.log('closeThisDialog success', res)
// 自动化测试 // 自动化测试
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
}, },
closeThisDialog() { closeThisDialog() {
uni.closeDialogPage({ uni.closeDialogPage({
dialogPage: this.$dialogPage, dialogPage: this.$page as UniDialogPage,
success(res) { success(res) {
console.log('closeThisDialog success', res) console.log('closeThisDialog success', res)
// 自动化测试 // 自动化测试
...@@ -138,4 +138,4 @@ ...@@ -138,4 +138,4 @@
.mt-10 { .mt-10 {
margin-top: 10px; margin-top: 10px;
} }
</style> </style>
...@@ -112,14 +112,14 @@ ...@@ -112,14 +112,14 @@
getPageStyle() : UTSJSONObject { getPageStyle() : UTSJSONObject {
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
this.currentPageStyle = currentPage.$getPageStyle() this.currentPageStyle = currentPage.getPageStyle()
return this.currentPageStyle; return this.currentPageStyle;
}, },
setPageStyle(style : UTSJSONObject) { setPageStyle(style : UTSJSONObject) {
console.log('setPageStyle:', style); console.log('setPageStyle:', style);
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
currentPage.$setPageStyle(style); currentPage.setPageStyle(style);
}, },
goSetDisablePullDownRefresh() { goSetDisablePullDownRefresh() {
uni.navigateTo({ uni.navigateTo({
...@@ -175,4 +175,4 @@ ...@@ -175,4 +175,4 @@
.radio-value { .radio-value {
margin-left: 10px; margin-left: 10px;
} }
</style> </style>
...@@ -44,13 +44,13 @@ ...@@ -44,13 +44,13 @@
getPageStyle() { getPageStyle() {
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
this.currentPageStyle = currentPage.$getPageStyle(); this.currentPageStyle = currentPage.getPageStyle();
}, },
setPageStyle(enable : boolean) { setPageStyle(enable : boolean) {
// 目前仅支持 enablePullDownRefresh // 目前仅支持 enablePullDownRefresh
const pages = getCurrentPages(); const pages = getCurrentPages();
const currentPage = pages[pages.length - 1]; const currentPage = pages[pages.length - 1];
currentPage.$setPageStyle({ currentPage.setPageStyle({
enablePullDownRefresh: enable enablePullDownRefresh: enable
}); });
this.enablePullDownRefreshStatus = enable this.enablePullDownRefreshStatus = enable
...@@ -95,4 +95,4 @@ ...@@ -95,4 +95,4 @@
margin-top: 15px; margin-top: 15px;
opacity: .8; opacity: .8;
} }
</style> </style>
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
changeColor() { changeColor() {
let pages = getCurrentPages() let pages = getCurrentPages()
let page = pages[pages.length - 1] let page = pages[pages.length - 1]
page.$setPageStyle({ "backgroundColorContent": this.isChange ? "" : "red" }) page.setPageStyle({ "backgroundColorContent": this.isChange ? "" : "red" })
this.isChange = !this.isChange this.isChange = !this.isChange
let pageJson = page.$getPageStyle() let pageJson = page.getPageStyle()
this.currentBackgroundColorContent = pageJson["backgroundColorContent"] this.currentBackgroundColorContent = pageJson["backgroundColorContent"]
} }
} }
...@@ -32,4 +32,4 @@ ...@@ -32,4 +32,4 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
</style> </style>
...@@ -224,19 +224,16 @@ export const get_page_name = (routepath : string) : string => { ...@@ -224,19 +224,16 @@ export const get_page_name = (routepath : string) : string => {
if (page.route != routepath) { if (page.route != routepath) {
const pages = getCurrentPages() const pages = getCurrentPages()
// 如果传入路由与当前页面不同,则从页面栈找一个,如果找不到返回空 // 如果传入路由与当前页面不同,则从页面栈找一个,如果找不到返回空
let page_now = pages.find((v) : boolean => { let page_now = pages.find((p): boolean => p.route == routepath)
if (v.route == routepath) {
return true;
}
return false
})
if (page_now == null) { if (page_now == null) {
return '' 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'] ?? '' const titleText = pageStyle['navigationBarTitleText'] ?? ''
return titleText as string return titleText as string
} }
...@@ -250,8 +247,9 @@ export const get_page_vm = () : Page | null => { ...@@ -250,8 +247,9 @@ export const get_page_vm = () : Page | null => {
return null return null
} }
let page = pages[pages.length - 1] let page = pages[pages.length - 1]
// TODO 正常来说,调用当前方法的地方只在 生命周期内,数组内最少会有一个页面,所以理论上是不存在获取不到的情况的 // TODO 正常来说,调用当前方法的地方只在 生命周期内,数组内最少会有一个页面,所以理论上是不存在获取不到的情况的
return page // @ts-ignore
return page.vm
} }
...@@ -416,17 +414,17 @@ export const uni_cloud_config = () : UniCloudInitOptions | null => { ...@@ -416,17 +414,17 @@ export const uni_cloud_config = () : UniCloudInitOptions | null => {
export const get_space = (config : UniCloudInitOptions) : UniCloudInitOptions | null => { export const get_space = (config : UniCloudInitOptions) : UniCloudInitOptions | null => {
const uniCloudConfig = uni_cloud_config() const uniCloudConfig = uni_cloud_config()
if (uniCloudConfig == null) { if (uniCloudConfig == null) {
console.log(config); console.log(config);
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
if (config.spaceId != '') { if (config.spaceId != '') {
return config return config
} }
// #endif // #endif
// #ifndef APP-ANDROID // #ifndef APP-ANDROID
if (config?.spaceId != '') { if (config?.spaceId != '') {
return config return config
} }
// #endif // #endif
return null return null
} }
...@@ -510,4 +508,4 @@ export const calibration = (eventName : string, options : any | null) : boolean ...@@ -510,4 +508,4 @@ export const calibration = (eventName : string, options : any | null) : boolean
return true return true
} }
return false return false
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册