Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tomleePHP
uni-app
提交
33679d5d
U
uni-app
项目概览
tomleePHP
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
33679d5d
编写于
7月 18, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(app-plus-nvue): refactor route
上级
2d30a925
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
344 addition
and
101 deletion
+344
-101
packages/uni-app-plus-nvue/dist/index.js
packages/uni-app-plus-nvue/dist/index.js
+214
-46
src/core/service/plugins/util.js
src/core/service/plugins/util.js
+3
-3
src/platforms/app-plus-nvue/service/uni/router/navigate-back.js
...atforms/app-plus-nvue/service/uni/router/navigate-back.js
+1
-1
src/platforms/app-plus-nvue/service/uni/router/navigate-to.js
...platforms/app-plus-nvue/service/uni/router/navigate-to.js
+9
-20
src/platforms/app-plus-nvue/service/uni/router/util.js
src/platforms/app-plus-nvue/service/uni/router/util.js
+0
-20
src/platforms/app-plus-nvue/service/uni/router/webview.js
src/platforms/app-plus-nvue/service/uni/router/webview.js
+14
-0
src/platforms/app-plus/service/uni/bridge.js
src/platforms/app-plus/service/uni/bridge.js
+16
-0
src/platforms/app-plus/service/uni/config.js
src/platforms/app-plus/service/uni/config.js
+2
-1
src/platforms/app-plus/service/uni/create-instance-context.js
...platforms/app-plus/service/uni/create-instance-context.js
+12
-5
src/platforms/app-plus/service/uni/page.js
src/platforms/app-plus/service/uni/page.js
+21
-5
src/platforms/app-plus/service/uni/webview.js
src/platforms/app-plus/service/uni/webview.js
+52
-0
未找到文件。
packages/uni-app-plus-nvue/dist/index.js
浏览文件 @
33679d5d
import
{
createUniInstance
}
from
'
./uni
'
;
const
ANI_SHOW
=
'
pop-in
'
;
const
ANI_DURATION
=
300
;
const
ANI_SHOW
=
'
pop-in
'
;
let
id
=
0
;
function
getId
()
{
return
id
++
}
function
parseWebviewStyle
(
path
)
{
return
{
titleNView
:
{
autoBackButton
:
true
,
titleText
:
'
titleText
'
},
uniNView
:
{
path
}
function
showWebview
(
webview
,
animationType
,
animationDuration
)
{
setTimeout
(()
=>
{
webview
.
show
(
animationType
||
ANI_SHOW
,
animationDuration
||
ANI_DURATION
,
()
=>
{
console
.
log
(
'
show.callback
'
);
}
);
},
50
);
}
function
initNavigateTo
({
plus
,
__registerPage
})
{
return
function
navigateTo
(
path
,
{
animationType
,
animationDuration
})
{
const
webview
=
plus
.
webview
.
open
(
''
,
String
(
getId
()),
parseWebviewStyle
(
path
),
animationType
||
ANI_SHOW
,
animationDuration
||
ANI_DURATION
,
()
=>
{
console
.
log
(
'
show.callback
'
);
});
showWebview
(
__registerPage
({
path
,
webview
});
path
}),
animationType
,
animationDuration
);
}
}
...
...
@@ -139,7 +125,7 @@ class Router {
let
appCtx
;
function
getApp
()
{
function
getApp
$1
()
{
return
appCtx
}
...
...
@@ -160,9 +146,62 @@ function registerApp (appVm, instanceContext) {
initListeners
(
instanceContext
);
}
const
WEBVIEW_LISTENERS
=
[
'
close
'
,
'
resize
'
,
'
popGesture
'
,
'
pullToRefresh
'
,
'
titleNViewSearchInputChanged
'
,
'
titleNViewSearchInputConfirmed
'
,
'
titleNViewSearchInputClicked
'
];
let
id
=
1
;
function
parseWebviewStyle
(
path
,
windowOptions
=
{})
{
return
{
titleNView
:
{
autoBackButton
:
true
,
titleText
:
'
titleText
'
},
uniNView
:
{
path
}
}
}
function
parseWindowOptions
(
windowOptions
=
{},
globalWindowOptions
=
{})
{
// TODO
return
windowOptions
}
function
createWebview
(
path
,
{
plus
,
__uniConfig
},
windowOptions
)
{
return
plus
.
webview
.
create
(
''
,
String
(
id
++
),
parseWebviewStyle
(
path
,
parseWindowOptions
(
windowOptions
,
__uniConfig
.
window
)
))
}
function
initWebview
(
webview
,
{
UniJSServiceBridge
})
{
// TODO subNVues
WEBVIEW_LISTENERS
.
forEach
(
listener
=>
{
webview
.
addEventListener
(
listener
,
(
e
)
=>
{
UniJSServiceBridge
.
emit
(
listener
,
e
);
});
});
}
const
pages
=
[];
function
getCurrentPages
()
{
function
getCurrentPages
$1
()
{
return
pages
}
/**
...
...
@@ -183,23 +222,34 @@ function getCurrentPages () {
*
*
*/
/**
* 首页需要主动registerPage,二级页面路由跳转时registerPage
*/
function
registerPage
({
vm
,
path
,
webview
},
instanceContext
)
{
const
routeOptions
=
instanceContext
.
__uniRoutes
.
find
(
route
=>
route
.
path
===
path
);
if
(
!
webview
)
{
webview
=
createWebview
(
path
,
instanceContext
,
routeOptions
.
window
);
}
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] registerPage`
,
path
,
webview
.
id
);
}
initWebview
(
webview
,
instanceContext
,
webview
.
id
===
'
1
'
&&
routeOptions
.
window
);
pages
.
push
({
route
:
path
.
slice
(
1
),
$getAppWebview
()
{
return
webview
},
$meta
:
instanceContext
.
__uniRoutes
.
find
(
route
=>
route
.
path
===
path
).
meta
,
$vm
:
vm
$meta
:
routeOptions
.
meta
});
return
webview
}
const
uniConfig
=
Object
.
create
(
null
);
...
...
@@ -231,23 +281,140 @@ function registerConfig (config) {
parseRoutes
(
uniConfig
);
}
function
callHook
(
vm
,
hook
,
params
)
{
return
(
vm
.
$vm
||
vm
).
__call_hook
(
hook
,
params
)
}
function
callAppHook
(
vm
,
hook
,
params
)
{
if
(
hook
!==
'
onError
'
)
{
console
.
debug
(
`App:
${
hook
}
have been invoked`
+
(
params
?
`
${
JSON
.
stringify
(
params
)}
`
:
''
));
}
return
(
vm
.
$vm
||
vm
).
__call_hook
(
hook
,
params
)
}
function
callPageHook
(
vm
,
hook
,
params
)
{
// hack 一下,H5 平台通知 View 层onShow,方便 View 层来切换 scroll 事件监听
if
(
__PLATFORM__
===
'
h5
'
)
{
if
(
hook
===
'
onLoad
'
)
{
vm
.
$mp
.
query
=
params
;
UniServiceJSBridge
.
publishHandler
(
'
onPageLoad
'
,
vm
,
vm
.
$page
.
id
);
}
if
(
hook
===
'
onShow
'
)
{
if
(
vm
.
$route
.
meta
.
isTabBar
&&
vm
.
$route
.
params
.
detail
)
{
UniServiceJSBridge
.
emit
(
'
onTabItemTap
'
,
vm
.
$route
.
params
.
detail
);
}
UniServiceJSBridge
.
publishHandler
(
'
onPageShow
'
,
vm
,
vm
.
$page
.
id
);
}
}
if
(
hook
!==
'
onPageScroll
'
)
{
console
.
debug
(
`
${
vm
.
$page
.
route
}
[
${
vm
.
$page
.
id
}
]:
${
hook
}
have been invoked`
);
}
return
callHook
(
vm
,
hook
,
params
)
}
function
onError
(
err
)
{
callAppHook
(
getApp
(),
'
onError
'
,
err
);
}
function
onPageNotFound
(
page
)
{
callAppHook
(
getApp
(),
'
onPageNotFound
'
,
page
);
}
function
onPullDownRefresh
(
args
,
pageId
)
{
const
page
=
getCurrentPages
().
find
(
page
=>
page
.
$page
.
id
===
pageId
);
if
(
page
)
{
callPageHook
(
page
,
'
onPullDownRefresh
'
);
}
}
function
callCurrentPageHook
(
hook
,
args
)
{
const
pages
=
getCurrentPages
();
if
(
pages
.
length
)
{
callPageHook
(
pages
[
pages
.
length
-
1
],
hook
,
args
);
}
}
function
createCallCurrentPageHook
(
hook
)
{
return
function
(
args
)
{
callCurrentPageHook
(
hook
,
args
);
}
}
function
onAppEnterBackground
()
{
callAppHook
(
getApp
(),
'
onHide
'
);
callCurrentPageHook
(
'
onHide
'
);
}
function
onAppEnterForeground
()
{
callAppHook
(
getApp
(),
'
onShow
'
);
callCurrentPageHook
(
'
onShow
'
);
}
function
onWebInvokeAppService
({
name
,
arg
},
pageId
)
{
if
(
name
===
'
postMessage
'
)
;
else
{
uni
[
name
](
arg
);
}
}
function
initOn
(
on
)
{
on
(
'
onError
'
,
onError
);
on
(
'
onPageNotFound
'
,
onPageNotFound
);
on
(
'
onAppEnterBackground
'
,
onAppEnterBackground
);
on
(
'
onAppEnterForeground
'
,
onAppEnterForeground
);
on
(
'
onPullDownRefresh
'
,
onPullDownRefresh
);
on
(
'
onTabItemTap
'
,
createCallCurrentPageHook
(
'
onTabItemTap
'
));
on
(
'
onNavigationBarButtonTap
'
,
createCallCurrentPageHook
(
'
onNavigationBarButtonTap
'
));
on
(
'
onNavigationBarSearchInputChanged
'
,
createCallCurrentPageHook
(
'
onNavigationBarSearchInputChanged
'
));
on
(
'
onNavigationBarSearchInputConfirmed
'
,
createCallCurrentPageHook
(
'
onNavigationBarSearchInputConfirmed
'
));
on
(
'
onNavigationBarSearchInputClicked
'
,
createCallCurrentPageHook
(
'
onNavigationBarSearchInputClicked
'
));
on
(
'
onWebInvokeAppService
'
,
onWebInvokeAppService
);
}
function
initServiceJSBridge
(
Vue
)
{
const
Emitter
=
new
Vue
();
const
bridge
=
{
on
:
Emitter
.
$on
.
bind
(
Emitter
),
off
:
Emitter
.
$off
.
bind
(
Emitter
),
once
:
Emitter
.
$once
.
bind
(
Emitter
),
emit
:
Emitter
.
$emit
.
bind
(
Emitter
)
};
initOn
(
bridge
.
on
);
return
bridge
}
function
createInstanceContext
(
instanceContext
)
{
const
{
weex
,
Vue
,
WeexPlus
}
=
instanceContext
;
const
plus
=
new
WeexPlus
(
weex
);
const
UniJSServiceBridge
=
initServiceJSBridge
(
Vue
);
return
{
__uniConfig
:
uniConfig
,
__uniRoutes
:
uniRoutes
,
__registerConfig
(
config
)
{
re
gisterConfig
(
config
,
instanceContext
);
re
turn
registerConfig
(
config
,
instanceContext
)
},
__registerApp
(
appVm
)
{
re
gisterApp
(
appVm
,
instanceContext
);
re
turn
registerApp
(
appVm
,
instanceContext
)
},
__registerPage
(
page
)
{
re
gisterPage
(
page
,
instanceContext
);
re
turn
registerPage
(
page
,
instanceContext
)
},
plus
,
uni
:
createUniInstance
(
...
...
@@ -255,11 +422,12 @@ function createInstanceContext (instanceContext) {
plus
,
uniConfig
,
uniRoutes
,
getApp
,
getCurrentPages
getApp
$1
,
getCurrentPages
$1
),
getApp
,
getCurrentPages
getApp
:
getApp$1
,
getCurrentPages
:
getCurrentPages$1
,
UniJSServiceBridge
}
}
...
...
src/core/service/plugins/util.js
浏览文件 @
33679d5d
function
callHook
(
vm
,
hook
,
params
)
{
return
vm
.
__call_hook
(
hook
,
params
)
return
(
vm
.
$vm
||
vm
)
.
__call_hook
(
hook
,
params
)
}
export
function
callAppHook
(
vm
,
hook
,
params
)
{
if
(
hook
!==
'
onError
'
)
{
console
.
debug
(
`App:
${
hook
}
have been invoked`
+
(
params
?
`
${
JSON
.
stringify
(
params
)}
`
:
''
))
}
return
vm
.
__call_hook
(
hook
,
params
)
return
(
vm
.
$vm
||
vm
)
.
__call_hook
(
hook
,
params
)
}
export
function
callPageHook
(
vm
,
hook
,
params
)
{
...
...
src/platforms/app-plus-nvue/service/uni/router/navigate-back.js
浏览文件 @
33679d5d
import
{
ANI_DURATION
}
from
'
./
util
'
}
from
'
./
webview
'
let
firstBackTime
=
0
...
...
src/platforms/app-plus-nvue/service/uni/router/navigate-to.js
浏览文件 @
33679d5d
import
{
getId
,
ANI_SHOW
,
ANI_DURATION
,
parseWebviewStyle
}
from
'
./util
'
showWebview
}
from
'
./webview
'
export
default
function
initNavigateTo
({
plus
,
__registerPage
})
{
return
function
navigateTo
(
path
,
{
animationType
,
animationDuration
})
{
const
webview
=
plus
.
webview
.
open
(
''
,
String
(
getId
()),
parseWebviewStyle
(
path
),
animationType
||
ANI_SHOW
,
animationDuration
||
ANI_DURATION
,
()
=>
{
console
.
log
(
'
show.callback
'
)
})
showWebview
(
__registerPage
({
path
,
webview
})
path
}),
animationType
,
animationDuration
)
}
}
src/platforms/app-plus-nvue/service/uni/router/util.js
已删除
100644 → 0
浏览文件 @
2d30a925
export
const
ANI_SHOW
=
'
pop-in
'
export
const
ANI_DURATION
=
300
let
id
=
0
export
function
getId
()
{
return
id
++
}
export
function
parseWebviewStyle
(
path
)
{
return
{
titleNView
:
{
autoBackButton
:
true
,
titleText
:
'
titleText
'
},
uniNView
:
{
path
}
}
}
src/platforms/app-plus-nvue/service/uni/router/webview.js
0 → 100644
浏览文件 @
33679d5d
export
const
ANI_DURATION
=
300
const
ANI_SHOW
=
'
pop-in
'
export
function
showWebview
(
webview
,
animationType
,
animationDuration
)
{
setTimeout
(()
=>
{
webview
.
show
(
animationType
||
ANI_SHOW
,
animationDuration
||
ANI_DURATION
,
()
=>
{
console
.
log
(
'
show.callback
'
)
}
)
},
50
)
}
src/platforms/app-plus/service/uni/bridge.js
0 → 100644
浏览文件 @
33679d5d
import
initOn
from
'
uni-core/service/bridge/on
'
export
function
initServiceJSBridge
(
Vue
)
{
const
Emitter
=
new
Vue
()
const
bridge
=
{
on
:
Emitter
.
$on
.
bind
(
Emitter
),
off
:
Emitter
.
$off
.
bind
(
Emitter
),
once
:
Emitter
.
$once
.
bind
(
Emitter
),
emit
:
Emitter
.
$emit
.
bind
(
Emitter
)
}
initOn
(
bridge
.
on
)
return
bridge
}
src/platforms/app-plus/service/uni/config.js
浏览文件 @
33679d5d
...
...
@@ -14,7 +14,8 @@ function parseRoutes (config) {
meta
:
{
isQuit
,
isTabBar
}
},
window
:
config
.
page
[
pagePath
]
||
{}
})
})
}
...
...
src/platforms/app-plus/service/uni/create-instance-context.js
浏览文件 @
33679d5d
...
...
@@ -18,23 +18,29 @@ import {
createUniInstance
}
from
'
./uni
'
import
{
initServiceJSBridge
}
from
'
./bridge
'
export
function
createInstanceContext
(
instanceContext
)
{
const
{
weex
,
Vue
,
WeexPlus
}
=
instanceContext
const
plus
=
new
WeexPlus
(
weex
)
const
UniJSServiceBridge
=
initServiceJSBridge
(
Vue
)
return
{
__uniConfig
:
uniConfig
,
__uniRoutes
:
uniRoutes
,
__registerConfig
(
config
)
{
registerConfig
(
config
,
instanceContext
)
re
turn
re
gisterConfig
(
config
,
instanceContext
)
},
__registerApp
(
appVm
)
{
registerApp
(
appVm
,
instanceContext
)
re
turn
re
gisterApp
(
appVm
,
instanceContext
)
},
__registerPage
(
page
)
{
registerPage
(
page
,
instanceContext
)
re
turn
re
gisterPage
(
page
,
instanceContext
)
},
plus
,
uni
:
createUniInstance
(
...
...
@@ -46,6 +52,7 @@ export function createInstanceContext (instanceContext) {
getCurrentPages
),
getApp
,
getCurrentPages
getCurrentPages
,
UniJSServiceBridge
}
}
src/platforms/app-plus/service/uni/page.js
浏览文件 @
33679d5d
import
{
initWebview
,
createWebview
}
from
'
./webview
'
const
pages
=
[]
export
function
getCurrentPages
()
{
...
...
@@ -21,21 +26,32 @@ export function getCurrentPages () {
*
*
*/
/**
* 首页需要主动registerPage,二级页面路由跳转时registerPage
*/
export
function
registerPage
({
vm
,
path
,
webview
},
instanceContext
)
{
const
routeOptions
=
instanceContext
.
__uniRoutes
.
find
(
route
=>
route
.
path
===
path
)
if
(
!
webview
)
{
webview
=
createWebview
(
path
,
instanceContext
,
routeOptions
.
window
)
}
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] registerPage`
,
path
,
webview
.
id
)
}
initWebview
(
webview
,
instanceContext
,
webview
.
id
===
'
1
'
&&
routeOptions
.
window
)
pages
.
push
({
route
:
path
.
slice
(
1
),
$getAppWebview
()
{
return
webview
},
$meta
:
instanceContext
.
__uniRoutes
.
find
(
route
=>
route
.
path
===
path
).
meta
,
$vm
:
vm
$meta
:
routeOptions
.
meta
})
return
webview
}
src/platforms/app-plus/service/uni/webview.js
0 → 100644
浏览文件 @
33679d5d
const
WEBVIEW_LISTENERS
=
[
'
close
'
,
'
resize
'
,
'
popGesture
'
,
'
pullToRefresh
'
,
'
titleNViewSearchInputChanged
'
,
'
titleNViewSearchInputConfirmed
'
,
'
titleNViewSearchInputClicked
'
]
let
id
=
1
function
parseWebviewStyle
(
path
,
windowOptions
=
{})
{
return
{
titleNView
:
{
autoBackButton
:
true
,
titleText
:
'
titleText
'
},
uniNView
:
{
path
}
}
}
function
parseWindowOptions
(
windowOptions
=
{},
globalWindowOptions
=
{})
{
// TODO
return
windowOptions
}
export
function
createWebview
(
path
,
{
plus
,
__uniConfig
},
windowOptions
)
{
return
plus
.
webview
.
create
(
''
,
String
(
id
++
),
parseWebviewStyle
(
path
,
parseWindowOptions
(
windowOptions
,
__uniConfig
.
window
)
))
}
export
function
initWebview
(
webview
,
{
UniJSServiceBridge
})
{
// TODO subNVues
WEBVIEW_LISTENERS
.
forEach
(
listener
=>
{
webview
.
addEventListener
(
listener
,
(
e
)
=>
{
UniJSServiceBridge
.
emit
(
listener
,
e
)
})
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录