Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Velpro187
uni-app
提交
62918d28
U
uni-app
项目概览
Velpro187
/
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,发现更多精彩内容 >>
提交
62918d28
编写于
7月 30, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): navigationBar
上级
9550e4b5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
247 addition
and
0 deletion
+247
-0
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+117
-0
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
packages/uni-app-plus/src/service/api/ui/navigationBar.ts
packages/uni-app-plus/src/service/api/ui/navigationBar.ts
+122
-0
packages/uni-app-plus/src/service/utils.ts
packages/uni-app-plus/src/service/utils.ts
+7
-0
未找到文件。
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
62918d28
...
@@ -4844,6 +4844,47 @@ var serviceContext = (function (vue) {
...
@@ -4844,6 +4844,47 @@ var serviceContext = (function (vue) {
desc: Object,
desc: Object,
};
};
const FRONT_COLORS = ['#ffffff', '#000000'];
const API_SET_NAVIGATION_BAR_COLOR = 'setNavigationBarColor';
const SetNavigationBarColorOptions = {
formatArgs: {
animation(animation, params) {
if (!animation) {
animation = { duration: 0, timingFunc: 'linear' };
}
params.animation = {
duration: animation.duration || 0,
timingFunc: animation.timingFunc || 'linear',
};
},
},
};
const SetNavigationBarColorProtocol = {
frontColor: {
type: String,
required: true,
validator(frontColor) {
if (FRONT_COLORS.indexOf(frontColor) === -1) {
return `invalid frontColor "${frontColor}"`;
}
},
},
backgroundColor: {
type: String,
required: true,
},
animation: Object,
};
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 API_PAGE_SCROLL_TO = 'pageScrollTo';
const API_PAGE_SCROLL_TO = 'pageScrollTo';
const PageScrollToProtocol = {
const PageScrollToProtocol = {
scrollTop: Number,
scrollTop: Number,
...
@@ -5603,6 +5644,12 @@ var serviceContext = (function (vue) {
...
@@ -5603,6 +5644,12 @@ var serviceContext = (function (vue) {
}
}
return null;
return null;
}
}
function getWebview(page) {
if (page) {
return page.$getAppWebview();
}
return getCurrentWebview();
}
let pullDownRefreshWebview = null;
let pullDownRefreshWebview = null;
function getPullDownRefreshWebview() {
function getPullDownRefreshWebview() {
return pullDownRefreshWebview;
return pullDownRefreshWebview;
...
@@ -8474,6 +8521,72 @@ var serviceContext = (function (vue) {
...
@@ -8474,6 +8521,72 @@ var serviceContext = (function (vue) {
UniServiceJSBridge.invokeViewMethod(PAGE_SCROLL_TO, options, pageId, resolve);
UniServiceJSBridge.invokeViewMethod(PAGE_SCROLL_TO, options, pageId, resolve);
}, PageScrollToProtocol, PageScrollToOptions);
}, PageScrollToProtocol, PageScrollToOptions);
const setNavigationBarTitle = defineAsyncApi(API_SET_NAVIGATION_BAR_TITLE, ({ __page__, title }, { resolve, reject }) => {
const webview = getWebview(__page__);
if (webview) {
const style = webview.getStyle();
if (style && style.titleNView) {
webview.setStyle({
titleNView: {
titleText: title
}
});
}
resolve();
}
else {
reject();
}
}, SetNavigationBarTitleProtocol);
const showNavigationBarLoading = defineAsyncApi(API_SHOW_NAVIGATION_BAR_LOADING, (_, { resolve }) => {
plus.nativeUI.showWaiting('', {
modal: false
});
resolve();
});
const hideNavigationBarLoading = defineAsyncApi(API_HIDE_NAVIGATION_BAR_LOADING, (_, { resolve }) => {
plus.nativeUI.closeWaiting();
resolve();
});
function setPageMeta(statusBarStyle) {
const pages = getCurrentPages();
if (!pages.length) {
return;
}
// 框架内部页面跳转会从这里获取style配置
pages[pages.length - 1].$page.statusBarStyle = statusBarStyle;
}
const setNavigationBarColor = defineAsyncApi(API_SET_NAVIGATION_BAR_COLOR, ({ __page__, frontColor, backgroundColor }, { resolve, reject }) => {
const webview = getWebview(__page__);
if (webview) {
const styles = {};
if (frontColor) {
styles.titleColor = frontColor;
}
if (backgroundColor) {
styles.backgroundColor = backgroundColor;
}
const statusBarStyle = frontColor === '#000000' ? 'dark' : 'light';
plus.navigator.setStatusBarStyle(statusBarStyle);
// 用户调用api时同时改变当前页配置,这样在系统调用设置时,可以避免覆盖用户设置
setPageMeta(statusBarStyle);
const style = webview.getStyle();
if (style && style.titleNView) {
if (style.titleNView.autoBackButton) {
styles.backButton = styles.backButton || {};
styles.backButton.color = frontColor;
}
webview.setStyle({
titleNView: styles
});
}
resolve();
}
else {
reject();
}
}, SetNavigationBarColorProtocol, SetNavigationBarColorOptions);
const providers = {
const providers = {
oauth(callback) {
oauth(callback) {
plus.oauth.getServices((services) => {
plus.oauth.getServices((services) => {
...
@@ -11093,6 +11206,10 @@ var serviceContext = (function (vue) {
...
@@ -11093,6 +11206,10 @@ var serviceContext = (function (vue) {
stopPullDownRefresh: stopPullDownRefresh,
stopPullDownRefresh: stopPullDownRefresh,
loadFontFace: loadFontFace,
loadFontFace: loadFontFace,
pageScrollTo: pageScrollTo,
pageScrollTo: pageScrollTo,
setNavigationBarTitle: setNavigationBarTitle,
showNavigationBarLoading: showNavigationBarLoading,
hideNavigationBarLoading: hideNavigationBarLoading,
setNavigationBarColor: setNavigationBarColor,
getProvider: getProvider,
getProvider: getProvider,
login: login,
login: login,
getUserInfo: getUserInfo,
getUserInfo: getUserInfo,
...
...
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
62918d28
...
@@ -48,6 +48,7 @@ export * from './ui/startPullDownRefresh'
...
@@ -48,6 +48,7 @@ export * from './ui/startPullDownRefresh'
export
*
from
'
./ui/stopPullDownRefresh
'
export
*
from
'
./ui/stopPullDownRefresh
'
export
*
from
'
./ui/loadFontFace
'
export
*
from
'
./ui/loadFontFace
'
export
*
from
'
./ui/pageScrollTo
'
export
*
from
'
./ui/pageScrollTo
'
export
*
from
'
./ui/navigationBar
'
export
*
from
'
./plugin/getProvider
'
export
*
from
'
./plugin/getProvider
'
export
*
from
'
./plugin/oauth
'
export
*
from
'
./plugin/oauth
'
...
...
packages/uni-app-plus/src/service/api/ui/navigationBar.ts
0 → 100644
浏览文件 @
62918d28
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
defineAsyncApi
,
API_SET_NAVIGATION_BAR_COLOR
,
API_SET_NAVIGATION_BAR_TITLE
,
API_SHOW_NAVIGATION_BAR_LOADING
,
API_HIDE_NAVIGATION_BAR_LOADING
,
API_TYPE_SET_NAVIGATION_BAR_COLOR
,
API_TYPE_SET_NAVIGATION_BAR_TITLE
,
API_TYPE_SHOW_NAVIGATION_BAR_LOADING
,
API_TYPE_HIDE_NAVIGATION_BAR_LOADING
,
SetNavigationBarColorOptions
,
SetNavigationBarColorProtocol
,
SetNavigationBarTitleProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
getWebview
}
from
'
../../../service/utils
'
import
{
StatusBarStyle
}
from
'
../../statusBar
'
interface
SetNavigationBarTitleOptions
extends
UniApp
.
SetNavigationBarTitleOptions
{
__page__
?:
ComponentPublicInstance
}
export
const
setNavigationBarTitle
=
defineAsyncApi
<
API_TYPE_SET_NAVIGATION_BAR_TITLE
>
(
API_SET_NAVIGATION_BAR_TITLE
,
(
{
__page__
,
title
}:
SetNavigationBarTitleOptions
,
{
resolve
,
reject
}
)
=>
{
const
webview
=
getWebview
(
__page__
)
if
(
webview
)
{
const
style
=
webview
.
getStyle
()
if
(
style
&&
style
.
titleNView
)
{
webview
.
setStyle
({
titleNView
:
{
titleText
:
title
,
},
})
}
resolve
()
}
else
{
reject
()
}
},
SetNavigationBarTitleProtocol
)
export
const
showNavigationBarLoading
=
defineAsyncApi
<
API_TYPE_SHOW_NAVIGATION_BAR_LOADING
>
(
API_SHOW_NAVIGATION_BAR_LOADING
,
(
_
,
{
resolve
})
=>
{
plus
.
nativeUI
.
showWaiting
(
''
,
{
modal
:
false
,
})
resolve
()
}
)
export
const
hideNavigationBarLoading
=
defineAsyncApi
<
API_TYPE_HIDE_NAVIGATION_BAR_LOADING
>
(
API_HIDE_NAVIGATION_BAR_LOADING
,
(
_
,
{
resolve
})
=>
{
plus
.
nativeUI
.
closeWaiting
()
resolve
()
}
)
function
setPageMeta
(
statusBarStyle
:
StatusBarStyle
)
{
const
pages
=
getCurrentPages
()
if
(
!
pages
.
length
)
{
return
}
// 框架内部页面跳转会从这里获取style配置
pages
[
pages
.
length
-
1
].
$page
.
statusBarStyle
=
statusBarStyle
}
interface
SetNavigationbarColorOptions
extends
UniApp
.
SetNavigationbarColorOptions
{
__page__
?:
ComponentPublicInstance
}
export
const
setNavigationBarColor
=
defineAsyncApi
<
API_TYPE_SET_NAVIGATION_BAR_COLOR
>
(
API_SET_NAVIGATION_BAR_COLOR
,
(
{
__page__
,
frontColor
,
backgroundColor
}:
SetNavigationbarColorOptions
,
{
resolve
,
reject
}
)
=>
{
const
webview
=
getWebview
(
__page__
)
if
(
webview
)
{
const
styles
:
PlusWebviewWebviewTitleNViewStyles
=
{}
if
(
frontColor
)
{
styles
.
titleColor
=
frontColor
}
if
(
backgroundColor
)
{
styles
.
backgroundColor
=
backgroundColor
}
const
statusBarStyle
=
frontColor
===
'
#000000
'
?
'
dark
'
:
'
light
'
plus
.
navigator
.
setStatusBarStyle
(
statusBarStyle
)
// 用户调用api时同时改变当前页配置,这样在系统调用设置时,可以避免覆盖用户设置
setPageMeta
(
statusBarStyle
)
const
style
=
webview
.
getStyle
()
if
(
style
&&
style
.
titleNView
)
{
if
(
style
.
titleNView
.
autoBackButton
)
{
styles
.
backButton
=
styles
.
backButton
||
{}
styles
.
backButton
.
color
=
frontColor
}
webview
.
setStyle
({
titleNView
:
styles
,
})
}
resolve
()
}
else
{
reject
()
}
},
SetNavigationBarColorProtocol
,
SetNavigationBarColorOptions
)
packages/uni-app-plus/src/service/utils.ts
浏览文件 @
62918d28
...
@@ -9,6 +9,13 @@ export function getCurrentWebview() {
...
@@ -9,6 +9,13 @@ export function getCurrentWebview() {
return
null
return
null
}
}
export
function
getWebview
(
page
?:
ComponentPublicInstance
)
{
if
(
page
)
{
return
page
.
$getAppWebview
!
()
}
return
getCurrentWebview
()
}
let
pullDownRefreshWebview
:
PlusWebviewWebviewObject
|
null
=
null
let
pullDownRefreshWebview
:
PlusWebviewWebviewObject
|
null
=
null
export
function
getPullDownRefreshWebview
()
{
export
function
getPullDownRefreshWebview
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录