diff --git a/packages/uni-app/dist/uni-app.cjs.js b/packages/uni-app/dist/uni-app.cjs.js index ccde103250df0c637ab76aff2f8da8b698ff16fd..a834ee3a7d2e92c4c7ce124295318eeaa9c260bd 100644 --- a/packages/uni-app/dist/uni-app.cjs.js +++ b/packages/uni-app/dist/uni-app.cjs.js @@ -117,7 +117,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); - +// export const onLoad = /*#__PURE__*/ createHook(ON_LOAD) const onReady = /*#__PURE__*/ createHook(ON_READY); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onResize = /*#__PURE__*/ createHook(ON_RESIZE); diff --git a/packages/uni-app/dist/uni-app.es.js b/packages/uni-app/dist/uni-app.es.js index 32fba22addde471952aac91a854a9900a8647262..00ab56a6260595e650a95231cf9d363dfde92caf 100644 --- a/packages/uni-app/dist/uni-app.es.js +++ b/packages/uni-app/dist/uni-app.es.js @@ -82,7 +82,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); - +// export const onLoad = /*#__PURE__*/ createHook(ON_LOAD) const onReady = /*#__PURE__*/ createHook(ON_READY); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onResize = /*#__PURE__*/ createHook(ON_RESIZE); diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 3eddd34e841ef31a9cbca67f63bbdb57c64cc921..86dc18b67d84b879f19b9e4da6c4213a47334d2e 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -7341,6 +7341,16 @@ const RequestOptions = { } } }; +const API_SET_NAVIGATION_BAR_COLOR = "setNavigationBarColor"; +const API_SET_NAVIGATION_BAR_TITLE = "setNavigationBarTitle"; +const SetNavigationBarTitleProtocol = { + title: { + type: String, + required: true + } +}; +const API_SHOW_NAVIGATION_BAR_LOADING = "showNavigationBarLoading"; +const API_HIDE_NAVIGATION_BAR_LOADING = "hideNavigationBarLoading"; const envMethod = /* @__PURE__ */ (() => "env")(); function normalizeWindowBottom(windowBottom) { return `calc(${windowBottom}px + ${envMethod}(safe-area-inset-bottom))`; @@ -10288,11 +10298,61 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", () }; } }); +function updateDocumentTitle(title) { + { + const ctx = vue.useSSRContext(); + ctx[uniShared.UNI_SSR_TITLE] = title; + } +} +function useDocumentTitle(pageMeta) { + function update() { + updateDocumentTitle(pageMeta.navigationBar.titleText); + } + vue.watchEffect(update); +} +function setNavigationBar(pageMeta, type, args, resolve, reject) { + if (!pageMeta) { + return reject("page not found"); + } + const {navigationBar} = pageMeta; + switch (type) { + case API_SET_NAVIGATION_BAR_COLOR: + const {frontColor, backgroundColor, animation: animation2} = args; + const {duration, timingFunc} = animation2; + if (frontColor) { + navigationBar.titleColor = frontColor === "#000000" ? "#000" : "#fff"; + } + if (backgroundColor) { + navigationBar.backgroundColor = backgroundColor; + } + navigationBar.duration = duration + "ms"; + navigationBar.timingFunc = timingFunc; + break; + case API_SHOW_NAVIGATION_BAR_LOADING: + navigationBar.loading = true; + break; + case API_HIDE_NAVIGATION_BAR_LOADING: + navigationBar.loading = false; + break; + case API_SET_NAVIGATION_BAR_TITLE: + const {title} = args; + navigationBar.titleText = title; + { + updateDocumentTitle(args.title); + } + break; + } + resolve(); +} +const setNavigationBarTitle = /* @__PURE__ */ defineAsyncApi(API_SET_NAVIGATION_BAR_TITLE, (args, {resolve, reject}) => { + setNavigationBar(getCurrentPageMeta(), API_SET_NAVIGATION_BAR_TITLE, args, resolve, reject); +}, SetNavigationBarTitleProtocol); require("localstorage-polyfill"); global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; var api = /* @__PURE__ */ Object.freeze({ __proto__: null, [Symbol.toStringTag]: "Module", + setNavigationBarTitle, request, setStorageSync, setStorage, @@ -10848,15 +10908,6 @@ function createRightWindowTsx(rightWindow, layoutState, windowState) { }, windowState), null, 16)])], 12, ["data-show"]), [[vue.vShow, layoutState.showRightWindow || layoutState.apiShowRightWindow]]); } } -function useDocumentTitle(pageMeta) { - const ctx = vue.useSSRContext(); - function update() { - { - ctx[uniShared.UNI_SSR_TITLE] = pageMeta.navigationBar.titleText; - } - } - vue.watchEffect(update); -} function hexToRgba(hex) { let r; let g2; @@ -11421,6 +11472,7 @@ exports.plugin = index$9; exports.removeStorage = removeStorage; exports.removeStorageSync = removeStorageSync; exports.request = request; +exports.setNavigationBarTitle = setNavigationBarTitle; exports.setStorage = setStorage; exports.setStorageSync = setStorageSync; exports.setupApp = setupApp; diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index c13136a937b0b12c7ba608d4896dae180bc09dd4..4a5af42d36d54845c77946306a7d5901fd3d10f6 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -17714,6 +17714,18 @@ const loadFontFace = /* @__PURE__ */ defineAsyncApi(API_LOAD_FONT_FACE, ({family reject(`loadFontFace:fail ${err}`); }); }, LoadFontFaceProtocol); +function updateDocumentTitle(title) { + { + document.title = title; + } +} +function useDocumentTitle(pageMeta) { + function update() { + updateDocumentTitle(pageMeta.navigationBar.titleText); + } + watchEffect(update); + onActivated(update); +} function setNavigationBar(pageMeta, type, args, resolve, reject) { if (!pageMeta) { return reject("page not found"); @@ -19958,15 +19970,6 @@ const UniServiceJSBridge$1 = /* @__PURE__ */ extend(ServiceJSBridge, { UniViewJSBridge.subscribeHandler(pageId + "." + event, args, pageId); } }); -function useDocumentTitle(pageMeta) { - function update() { - { - document.title = pageMeta.navigationBar.titleText; - } - } - watchEffect(update); - onActivated(update); -} function hexToRgba(hex) { let r; let g2; diff --git a/packages/uni-h5/src/helpers/useDocumentTitle.ts b/packages/uni-h5/src/helpers/useDocumentTitle.ts index bd93ae3de82f903993e5cff5c6705587bcc55fae..31c80e5fe7ced7bee2692e3e6419272aef7bd8df 100644 --- a/packages/uni-h5/src/helpers/useDocumentTitle.ts +++ b/packages/uni-h5/src/helpers/useDocumentTitle.ts @@ -1,13 +1,18 @@ import { watchEffect, onActivated, useSSRContext } from 'vue' import { UNI_SSR_TITLE } from '@dcloudio/uni-shared' + +export function updateDocumentTitle(title: string) { + if (__NODE_JS__) { + const ctx = useSSRContext() + ctx![UNI_SSR_TITLE] = title + } else { + document.title = title + } +} + export function useDocumentTitle(pageMeta: UniApp.PageRouteMeta) { - const ctx = (__NODE_JS__ && useSSRContext()) as Record function update() { - if (__NODE_JS__) { - ctx![UNI_SSR_TITLE] = pageMeta.navigationBar.titleText - } else { - document.title = pageMeta.navigationBar.titleText! - } + updateDocumentTitle(pageMeta.navigationBar.titleText!) } watchEffect(update) onActivated(update) diff --git a/packages/uni-h5/src/service/api/index.ts b/packages/uni-h5/src/service/api/index.ts index ece642f2823444b7443f94f093c5e45a1dcc279d..33ae2ba71163f12f24bea3db90bed95b6d4a433f 100644 --- a/packages/uni-h5/src/service/api/index.ts +++ b/packages/uni-h5/src/service/api/index.ts @@ -7,6 +7,7 @@ global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest export * from './network/request' export * from './storage/storage' export * from './device/getSystemInfoSync' +export { setNavigationBarTitle } from './ui/navigationBar' //#else export * from './base/canIUse' diff --git a/packages/uni-h5/src/service/api/ui/navigationBar.ts b/packages/uni-h5/src/service/api/ui/navigationBar.ts index 28e06c841f1039022f178b66df123b5e165dcc3a..c602265c1b8f83d3b675e7c149628b91a3c0471f 100644 --- a/packages/uni-h5/src/service/api/ui/navigationBar.ts +++ b/packages/uni-h5/src/service/api/ui/navigationBar.ts @@ -13,6 +13,7 @@ import { SetNavigationBarTitleProtocol, } from '@dcloudio/uni-api' import { getCurrentPageMeta } from '@dcloudio/uni-core' +import { updateDocumentTitle } from '../../../helpers/useDocumentTitle' function setNavigationBar( pageMeta: UniApp.PageRouteMeta | undefined, @@ -53,6 +54,10 @@ function setNavigationBar( case API_SET_NAVIGATION_BAR_TITLE: const { title } = args navigationBar.titleText = title + if (__NODE_JS__) { + // watch 无效,主动更新 title + updateDocumentTitle(args.title) + } // TODO isCurrentPage逻辑主要是navigationBar组件使用 // if (isCurrentPage(page)) { // // 仅当前页面