提交 d3b33bbe 编写于 作者: Q qiang

feat(ssr): setNavigationBarTitle

上级 75d1c7e9
...@@ -117,7 +117,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); ...@@ -117,7 +117,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR);
const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE);
const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND);
const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION);
// export const onLoad = /*#__PURE__*/ createHook(ON_LOAD)
const onReady = /*#__PURE__*/ createHook(ON_READY); const onReady = /*#__PURE__*/ createHook(ON_READY);
const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD);
const onResize = /*#__PURE__*/ createHook(ON_RESIZE); const onResize = /*#__PURE__*/ createHook(ON_RESIZE);
......
...@@ -82,7 +82,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR); ...@@ -82,7 +82,7 @@ const onError = /*#__PURE__*/ createHook(ON_ERROR);
const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE); const onThemeChange = /*#__PURE__*/ createHook(ON_THEME_CHANGE);
const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND); const onPageNotFound = /*#__PURE__*/ createHook(ON_PAGE_NOT_FOUND);
const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION); const onUnhandledRejection = /*#__PURE__*/ createHook(ON_UNHANDLE_REJECTION);
// export const onLoad = /*#__PURE__*/ createHook(ON_LOAD)
const onReady = /*#__PURE__*/ createHook(ON_READY); const onReady = /*#__PURE__*/ createHook(ON_READY);
const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD); const onUnload = /*#__PURE__*/ createHook(ON_UNLOAD);
const onResize = /*#__PURE__*/ createHook(ON_RESIZE); const onResize = /*#__PURE__*/ createHook(ON_RESIZE);
......
...@@ -7341,6 +7341,16 @@ const RequestOptions = { ...@@ -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")(); const envMethod = /* @__PURE__ */ (() => "env")();
function normalizeWindowBottom(windowBottom) { function normalizeWindowBottom(windowBottom) {
return `calc(${windowBottom}px + ${envMethod}(safe-area-inset-bottom))`; return `calc(${windowBottom}px + ${envMethod}(safe-area-inset-bottom))`;
...@@ -10288,11 +10298,61 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", () ...@@ -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"); require("localstorage-polyfill");
global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var api = /* @__PURE__ */ Object.freeze({ var api = /* @__PURE__ */ Object.freeze({
__proto__: null, __proto__: null,
[Symbol.toStringTag]: "Module", [Symbol.toStringTag]: "Module",
setNavigationBarTitle,
request, request,
setStorageSync, setStorageSync,
setStorage, setStorage,
...@@ -10848,15 +10908,6 @@ function createRightWindowTsx(rightWindow, layoutState, windowState) { ...@@ -10848,15 +10908,6 @@ function createRightWindowTsx(rightWindow, layoutState, windowState) {
}, windowState), null, 16)])], 12, ["data-show"]), [[vue.vShow, layoutState.showRightWindow || layoutState.apiShowRightWindow]]); }, 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) { function hexToRgba(hex) {
let r; let r;
let g2; let g2;
...@@ -11421,6 +11472,7 @@ exports.plugin = index$9; ...@@ -11421,6 +11472,7 @@ exports.plugin = index$9;
exports.removeStorage = removeStorage; exports.removeStorage = removeStorage;
exports.removeStorageSync = removeStorageSync; exports.removeStorageSync = removeStorageSync;
exports.request = request; exports.request = request;
exports.setNavigationBarTitle = setNavigationBarTitle;
exports.setStorage = setStorage; exports.setStorage = setStorage;
exports.setStorageSync = setStorageSync; exports.setStorageSync = setStorageSync;
exports.setupApp = setupApp; exports.setupApp = setupApp;
......
...@@ -17714,6 +17714,18 @@ const loadFontFace = /* @__PURE__ */ defineAsyncApi(API_LOAD_FONT_FACE, ({family ...@@ -17714,6 +17714,18 @@ const loadFontFace = /* @__PURE__ */ defineAsyncApi(API_LOAD_FONT_FACE, ({family
reject(`loadFontFace:fail ${err}`); reject(`loadFontFace:fail ${err}`);
}); });
}, LoadFontFaceProtocol); }, 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) { function setNavigationBar(pageMeta, type, args, resolve, reject) {
if (!pageMeta) { if (!pageMeta) {
return reject("page not found"); return reject("page not found");
...@@ -19958,15 +19970,6 @@ const UniServiceJSBridge$1 = /* @__PURE__ */ extend(ServiceJSBridge, { ...@@ -19958,15 +19970,6 @@ const UniServiceJSBridge$1 = /* @__PURE__ */ extend(ServiceJSBridge, {
UniViewJSBridge.subscribeHandler(pageId + "." + event, args, pageId); UniViewJSBridge.subscribeHandler(pageId + "." + event, args, pageId);
} }
}); });
function useDocumentTitle(pageMeta) {
function update() {
{
document.title = pageMeta.navigationBar.titleText;
}
}
watchEffect(update);
onActivated(update);
}
function hexToRgba(hex) { function hexToRgba(hex) {
let r; let r;
let g2; let g2;
......
import { watchEffect, onActivated, useSSRContext } from 'vue' import { watchEffect, onActivated, useSSRContext } from 'vue'
import { UNI_SSR_TITLE } from '@dcloudio/uni-shared' import { UNI_SSR_TITLE } from '@dcloudio/uni-shared'
export function useDocumentTitle(pageMeta: UniApp.PageRouteMeta) {
const ctx = (__NODE_JS__ && useSSRContext()) as Record<string, any> export function updateDocumentTitle(title: string) {
function update() {
if (__NODE_JS__) { if (__NODE_JS__) {
ctx![UNI_SSR_TITLE] = pageMeta.navigationBar.titleText const ctx = useSSRContext()
ctx![UNI_SSR_TITLE] = title
} else { } else {
document.title = pageMeta.navigationBar.titleText! document.title = title
} }
}
export function useDocumentTitle(pageMeta: UniApp.PageRouteMeta) {
function update() {
updateDocumentTitle(pageMeta.navigationBar.titleText!)
} }
watchEffect(update) watchEffect(update)
onActivated(update) onActivated(update)
......
...@@ -7,6 +7,7 @@ global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest ...@@ -7,6 +7,7 @@ global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
export * from './network/request' export * from './network/request'
export * from './storage/storage' export * from './storage/storage'
export * from './device/getSystemInfoSync' export * from './device/getSystemInfoSync'
export { setNavigationBarTitle } from './ui/navigationBar'
//#else //#else
export * from './base/canIUse' export * from './base/canIUse'
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
SetNavigationBarTitleProtocol, SetNavigationBarTitleProtocol,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
import { getCurrentPageMeta } from '@dcloudio/uni-core' import { getCurrentPageMeta } from '@dcloudio/uni-core'
import { updateDocumentTitle } from '../../../helpers/useDocumentTitle'
function setNavigationBar( function setNavigationBar(
pageMeta: UniApp.PageRouteMeta | undefined, pageMeta: UniApp.PageRouteMeta | undefined,
...@@ -53,6 +54,10 @@ function setNavigationBar( ...@@ -53,6 +54,10 @@ function setNavigationBar(
case API_SET_NAVIGATION_BAR_TITLE: case API_SET_NAVIGATION_BAR_TITLE:
const { title } = args const { title } = args
navigationBar.titleText = title navigationBar.titleText = title
if (__NODE_JS__) {
// watch 无效,主动更新 title
updateDocumentTitle(args.title)
}
// TODO isCurrentPage逻辑主要是navigationBar组件使用 // TODO isCurrentPage逻辑主要是navigationBar组件使用
// if (isCurrentPage(page)) { // if (isCurrentPage(page)) {
// // 仅当前页面 // // 仅当前页面
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册