Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
1c08837a
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
718
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1c08837a
编写于
11月 01, 2019
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(v3): subNvue
上级
023dc196
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
234 addition
and
12 deletion
+234
-12
src/platforms/app-plus/service/framework/app.js
src/platforms/app-plus/service/framework/app.js
+6
-6
src/platforms/app-plus/service/framework/backbutton.js
src/platforms/app-plus/service/framework/backbutton.js
+5
-0
src/platforms/app-plus/service/framework/upx.js
src/platforms/app-plus/service/framework/upx.js
+7
-0
src/platforms/app-plus/service/framework/webview/index.js
src/platforms/app-plus/service/framework/webview/index.js
+45
-3
src/platforms/app-plus/service/framework/webview/parser/style-unit-parser.js
...lus/service/framework/webview/parser/style-unit-parser.js
+20
-0
src/platforms/app-plus/service/framework/webview/parser/sub-nvue-parser.js
...-plus/service/framework/webview/parser/sub-nvue-parser.js
+144
-0
src/platforms/app-plus/service/framework/webview/parser/webview-style-parser.js
.../service/framework/webview/parser/webview-style-parser.js
+7
-3
未找到文件。
src/platforms/app-plus/service/framework/app.js
浏览文件 @
1c08837a
...
...
@@ -30,6 +30,10 @@ import {
perf
}
from
'
./perf
'
import
{
backbuttonListener
}
from
'
./backbutton
'
let
appCtx
export
function
getApp
()
{
...
...
@@ -39,11 +43,7 @@ export function getApp () {
function
initGlobalListeners
()
{
const
emit
=
UniServiceJSBridge
.
emit
plus
.
key
.
addEventListener
(
'
backbutton
'
,
()
=>
{
uni
.
navigateBack
({
from
:
'
backbutton
'
})
})
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
)
plus
.
globalEvent
.
addEventListener
(
'
pause
'
,
()
=>
{
emit
(
'
onAppEnterBackground
'
)
...
...
src/platforms/app-plus/service/framework/backbutton.js
0 → 100644
浏览文件 @
1c08837a
export
function
backbuttonListener
()
{
uni
.
navigateBack
({
from
:
'
backbutton
'
})
}
src/platforms/app-plus/service/framework/upx.js
0 → 100644
浏览文件 @
1c08837a
const
REGEX_UPX
=
/
(\d
+
(\.\d
+
)?)[
r|u
]
px/g
export
function
transformCSS
(
css
)
{
return
css
.
replace
(
REGEX_UPX
,
(
a
,
b
)
=>
{
return
uni
.
upx2px
(
parseInt
(
b
)
||
0
)
+
'
px
'
})
}
src/platforms/app-plus/service/framework/webview/index.js
浏览文件 @
1c08837a
...
...
@@ -2,6 +2,10 @@ import {
parseWebviewStyle
}
from
'
./parser/webview-style-parser
'
import
{
initSubNVues
}
from
'
./parser/sub-nvue-parser
'
import
{
publish
}
from
'
../../bridge
'
...
...
@@ -125,6 +129,44 @@ export function initWebview (webview, routeOptions) {
}
=
UniServiceJSBridge
// TODO subNVues
initSubNVues
(
routeOptions
,
webview
)
// TODO 优化相关依赖性
// webview.addEventListener('popGesture', e => {
// if (e.type === 'start') {
// // 开始拖拽,还原状态栏前景色
// this.restoreStatusBarStyle()
// } else if (e.type === 'end' && !e.result) {
// // 拖拽未完成,设置为当前状态栏前景色
// this.setStatusBarStyle()
// } else if (e.type === 'end' && e.result) {
// removeWebview(this.id)
// const lastWebview = getLastWebview()
// if (lastWebview) {
// publish('onAppRoute', {
// path: lastWebview.page.replace('.html', ''),
// query: {},
// openType: 'navigateBack',
// webviewId: lastWebview.id
// })
// }
// }
// })
webview
.
addEventListener
(
'
close
'
,
()
=>
{
if
(
this
.
popupSubNVueWebviews
)
{
// 移除所有 popupSubNVueWebview
Object
.
keys
(
this
.
popupSubNVueWebviews
).
forEach
(
id
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
this
.
id
}
]:popupSubNVueWebview[
${
id
}
].close`
)
}
this
.
popupSubNVueWebviews
[
id
].
close
(
'
none
'
)
})
}
typeof
this
.
closeCallback
===
'
function
'
&&
this
.
closeCallback
()
})
Object
.
keys
(
WEBVIEW_LISTENERS
).
forEach
(
name
=>
{
webview
.
addEventListener
(
name
,
(
e
)
=>
{
emit
(
WEBVIEW_LISTENERS
[
name
],
e
,
parseInt
(
webview
.
id
))
...
...
src/platforms/app-plus/service/framework/webview/parser/style-unit-parser.js
0 → 100644
浏览文件 @
1c08837a
import
{
transformCSS
}
from
'
../../upx
'
export
function
parseStyleUnit
(
styles
)
{
let
newStyles
=
{}
const
stylesStr
=
JSON
.
stringify
(
styles
)
if
(
~
stylesStr
.
indexOf
(
'
upx
'
)
||
~
stylesStr
.
indexOf
(
'
rpx
'
))
{
try
{
newStyles
=
JSON
.
parse
(
transformCSS
(
stylesStr
))
}
catch
(
e
)
{
newStyles
=
styles
console
.
error
(
e
)
}
}
else
{
newStyles
=
JSON
.
parse
(
stylesStr
)
}
return
newStyles
}
src/platforms/app-plus/service/framework/webview/parser/sub-nvue-parser.js
0 → 100644
浏览文件 @
1c08837a
import
{
TITLEBAR_HEIGHT
}
from
'
../../../constants
'
import
{
backbuttonListener
}
from
'
../../backbutton
'
import
{
isTabBarPage
}
from
'
../../../bridge
'
function
getDefaultFontSize
(
width
)
{
return
Math
.
round
((
width
||
plus
.
screen
.
resolutionWidth
)
/
20
)
}
function
getDefaultViewport
()
{
return
plus
.
screen
.
resolutionWidth
}
function
initPopupSubNVue
(
subNVueWebview
,
style
,
maskWebview
)
{
if
(
!
maskWebview
.
popupSubNVueWebviews
)
{
maskWebview
.
popupSubNVueWebviews
=
{}
}
maskWebview
.
popupSubNVueWebviews
[
subNVueWebview
.
id
]
=
subNVueWebview
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
maskWebview
.
id
}
]:add.popupSubNVueWebview[
${
subNVueWebview
.
id
}
]`
)
}
const
hideSubNVue
=
function
()
{
maskWebview
.
setStyle
({
mask
:
'
none
'
})
subNVueWebview
.
hide
(
'
auto
'
)
}
maskWebview
.
addEventListener
(
'
maskClick
'
,
hideSubNVue
)
let
isRemoved
=
false
// 增加个 remove 标记,防止出错
subNVueWebview
.
addEventListener
(
'
show
'
,
()
=>
{
if
(
!
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
backbuttonListener
)
plus
.
key
.
addEventListener
(
'
backbutton
'
,
hideSubNVue
)
isRemoved
=
true
}
})
subNVueWebview
.
addEventListener
(
'
hide
'
,
()
=>
{
if
(
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
hideSubNVue
)
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
)
isRemoved
=
false
}
})
subNVueWebview
.
addEventListener
(
'
close
'
,
()
=>
{
delete
maskWebview
.
popupSubNVueWebviews
[
subNVueWebview
.
id
]
if
(
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
hideSubNVue
)
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
)
isRemoved
=
false
}
})
}
function
initNormalSubNVue
(
subNVueWebview
,
style
,
webview
)
{
webview
.
append
(
subNVueWebview
)
}
function
initSubNVue
(
subNVue
,
routeOptions
,
webview
)
{
if
(
!
subNVue
.
path
)
{
return
}
const
style
=
subNVue
.
style
||
{}
// 格式化
const
isNavigationBar
=
subNVue
.
type
===
'
navigationBar
'
const
isPopup
=
subNVue
.
type
===
'
popup
'
delete
style
.
type
if
(
isPopup
&&
!
subNVue
.
id
)
{
console
.
warn
(
'
subNVue[
'
+
subNVue
.
path
+
'
] 尚未配置 id
'
)
}
// TODO lazyload
style
.
uniNView
=
{
path
:
subNVue
.
path
.
replace
(
'
.nvue
'
,
'
.js
'
),
defaultFontSize
:
getDefaultFontSize
(),
viewport
:
getDefaultViewport
()
}
const
extras
=
{
__uniapp_host
:
routeOptions
.
path
,
__uniapp_origin
:
style
.
uniNView
.
path
.
split
(
'
?
'
)[
0
].
replace
(
'
.js
'
,
''
),
__uniapp_origin_id
:
webview
.
id
,
__uniapp_origin_type
:
webview
.
__uniapp_type
}
let
maskWebview
if
(
isNavigationBar
)
{
style
.
position
=
'
dock
'
style
.
dock
=
'
top
'
style
.
top
=
0
style
.
width
=
'
100%
'
style
.
height
=
TITLEBAR_HEIGHT
+
plus
.
navigator
.
getStatusbarHeight
()
delete
style
.
left
delete
style
.
right
delete
style
.
bottom
delete
style
.
margin
}
else
if
(
isPopup
)
{
style
.
position
=
'
absolute
'
console
.
log
(
isTabBarPage
(
routeOptions
.
path
));
if
(
isTabBarPage
(
routeOptions
.
path
))
{
maskWebview
=
tabBar
}
else
{
maskWebview
=
webview
}
extras
.
__uniapp_mask
=
style
.
mask
||
'
rgba(0,0,0,0.5)
'
extras
.
__uniapp_mask_id
=
maskWebview
.
id
}
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
webview
.
id
}
]:create[
${
subNVue
.
id
}
]:
${
JSON
.
stringify
(
style
)}
`
)
}
const
subNVueWebview
=
plus
.
webview
.
create
(
''
,
subNVue
.
id
,
style
,
extras
)
if
(
isPopup
)
{
initPopupSubNVue
(
subNVueWebview
,
style
,
maskWebview
)
}
else
{
initNormalSubNVue
(
subNVueWebview
,
style
,
webview
)
}
}
export
function
initSubNVues
(
routeOptions
,
webview
)
{
const
subNVues
=
routeOptions
.
window
.
subNVues
if
(
!
subNVues
||
!
subNVues
.
length
)
{
return
}
subNVues
.
forEach
(
subNVue
=>
{
initSubNVue
(
subNVue
,
routeOptions
,
webview
)
})
}
src/platforms/app-plus/service/framework/webview/parser/webview-style-parser.js
浏览文件 @
1c08837a
...
...
@@ -6,6 +6,10 @@ import {
parsePullToRefresh
}
from
'
./pull-to-refresh-parser
'
import
{
parseStyleUnit
}
from
'
./style-unit-parser
'
const
WEBVIEW_STYLE_BLACKLIST
=
[
'
navigationBarBackgroundColor
'
,
'
navigationBarTextStyle
'
,
...
...
@@ -27,10 +31,10 @@ export function parseWebviewStyle (id, path, routeOptions = {}) {
const
webviewStyle
=
Object
.
create
(
null
)
// 合并
routeOptions
.
window
=
Object
.
assign
(
routeOptions
.
window
=
parseStyleUnit
(
Object
.
assign
(
JSON
.
parse
(
JSON
.
stringify
(
__uniConfig
.
window
||
{})),
routeOptions
.
window
||
{}
)
)
)
Object
.
keys
(
routeOptions
.
window
).
forEach
(
name
=>
{
if
(
WEBVIEW_STYLE_BLACKLIST
.
indexOf
(
name
)
===
-
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录