Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
d3b33bbe
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d3b33bbe
编写于
5月 27, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(ssr): setNavigationBarTitle
上级
75d1c7e9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
92 addition
and
26 deletion
+92
-26
packages/uni-app/dist/uni-app.cjs.js
packages/uni-app/dist/uni-app.cjs.js
+1
-1
packages/uni-app/dist/uni-app.es.js
packages/uni-app/dist/uni-app.es.js
+1
-1
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+61
-9
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+12
-9
packages/uni-h5/src/helpers/useDocumentTitle.ts
packages/uni-h5/src/helpers/useDocumentTitle.ts
+11
-6
packages/uni-h5/src/service/api/index.ts
packages/uni-h5/src/service/api/index.ts
+1
-0
packages/uni-h5/src/service/api/ui/navigationBar.ts
packages/uni-h5/src/service/api/ui/navigationBar.ts
+5
-0
未找到文件。
packages/uni-app/dist/uni-app.cjs.js
浏览文件 @
d3b33bbe
...
...
@@ -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
);
...
...
packages/uni-app/dist/uni-app.es.js
浏览文件 @
d3b33bbe
...
...
@@ -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
);
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
d3b33bbe
...
...
@@ -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
;
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
d3b33bbe
...
...
@@ -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;
...
...
packages/uni-h5/src/helpers/useDocumentTitle.ts
浏览文件 @
d3b33bbe
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
<
string
,
any
>
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
)
...
...
packages/uni-h5/src/service/api/index.ts
浏览文件 @
d3b33bbe
...
...
@@ -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
'
...
...
packages/uni-h5/src/service/api/ui/navigationBar.ts
浏览文件 @
d3b33bbe
...
...
@@ -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)) {
// // 仅当前页面
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录