diff --git a/packages/runtime-web/src/components/src/private/page-host.ts b/packages/runtime-web/src/components/src/private/page-host.ts index 1f57a170..2f211aae 100644 --- a/packages/runtime-web/src/components/src/private/page-host.ts +++ b/packages/runtime-web/src/components/src/private/page-host.ts @@ -12,6 +12,7 @@ import { converterForPx, defineElement, getCurrentPageParams, + getPageConfig, shouldEnableFor } from '../utils' import boolConverter from '../utils/bool-converter' @@ -113,6 +114,22 @@ export default class PageHost extends LitElement implements IPageHost { private styleElement: HTMLStyleElement setConfig(config: IPageConfig) { this.config = { ...this.config, ...config } + // 业务在页面打开时有覆盖页面配置的场景 + const updatePageConfig = get(window.$MOR_APP_CONFIG, 'updatePageConfig') + if (updatePageConfig) { + const { path: pagePath, options: pageOptions } = getCurrentPageParams([ + 'path', + 'options' + ]) + const resultConfig = getPageConfig( + updatePageConfig, + pagePath, + pageOptions + ) + + if (typeof resultConfig === 'object') + this.config = Object.assign(this.config, resultConfig) + } // 强制渲染 this.requestUpdate() // NOTE: 页面背景色 diff --git a/packages/runtime-web/src/components/src/utils/index.ts b/packages/runtime-web/src/components/src/utils/index.ts index 11bde9cf..2148c848 100644 --- a/packages/runtime-web/src/components/src/utils/index.ts +++ b/packages/runtime-web/src/components/src/utils/index.ts @@ -121,6 +121,25 @@ export function shouldEnableFor( } } +export function getPageConfig( + config: + | Record + | (( + pagePath: string, + pageOptions: Record + ) => Record), + pagePath: string, + pageOptions: Record +) { + if (!pagePath) return + if (typeof config === 'object') return config + + if (typeof config === 'function') { + const result = config(pagePath, pageOptions) + if (typeof result === 'object') return result + } +} + export const getCurrentPageParams = (keys = []): Record => { try { const pageStack = getCurrentPages() || []