Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
c3eadd64
U
uni-app
项目概览
MuGuiLin
/
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,发现更多精彩内容 >>
提交
c3eadd64
编写于
2月 10, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
094dce6f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
62 addition
and
63 deletion
+62
-63
packages/uni-app-plus/dist/uni.runtime.esm.js
packages/uni-app-plus/dist/uni.runtime.esm.js
+26
-27
packages/uni-app-plus/src/service/framework/page/define.ts
packages/uni-app-plus/src/service/framework/page/define.ts
+1
-1
packages/uni-app-plus/src/service/framework/page/preLoad.ts
packages/uni-app-plus/src/service/framework/page/preLoad.ts
+1
-2
packages/uni-app-plus/src/service/framework/page/register.ts
packages/uni-app-plus/src/service/framework/page/register.ts
+22
-28
packages/uni-app-plus/src/service/framework/page/setup.ts
packages/uni-app-plus/src/service/framework/page/setup.ts
+1
-1
packages/uni-app-plus/src/service/framework/webview/index.ts
packages/uni-app-plus/src/service/framework/webview/index.ts
+1
-1
packages/uni-app-plus/src/service/framework/webview/nvue.ts
packages/uni-app-plus/src/service/framework/webview/nvue.ts
+4
-2
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
+6
-1
未找到文件。
packages/uni-app-plus/dist/uni.runtime.esm.js
浏览文件 @
c3eadd64
...
...
@@ -17159,7 +17159,7 @@ function initDebugRefresh(isTab, path, query) {
};
}
function createNVueWebview({ path, query, routeOptions, webview
Style
, }) {
function createNVueWebview({ path, query, routeOptions, webview
Extras
, }) {
const curWebviewId = genWebviewId();
const curWebviewStyle = parseWebviewStyle(path, routeOptions.meta, {
id: curWebviewId + '',
...
...
@@ -17171,7 +17171,9 @@ function createNVueWebview({ path, query, routeOptions, webviewStyle, }) {
curWebviewStyle.isTab = !!routeOptions.meta.isTabBar;
return plus.webview.create('', String(curWebviewId), curWebviewStyle, extend({
nvue: true,
}, webviewStyle));
__path__: path,
__query__: JSON.stringify(query),
}, webviewExtras));
}
let preloadWebview$1;
...
...
@@ -18011,7 +18013,7 @@ const pagesMap = new Map();
function definePage(pagePath, asyncComponent) {
pagesMap.set(pagePath, once(createFactory(asyncComponent)));
}
function createPage(__pageId, __pagePath, __pageQuery, __pageInstance, pageOptions) {
function create
Vue
Page(__pageId, __pagePath, __pageQuery, __pageInstance, pageOptions) {
const pageNode = createPageNode(__pageId, pageOptions, true);
const app = getVueApp();
const component = pagesMap.get(__pagePath)();
...
...
@@ -18140,9 +18142,8 @@ function preloadWebview({ url, path, query, }) {
path,
routeOptions,
query,
webview
Style
: {
webview
Extras
: {
__preload__: true,
__query__: JSON.stringify(query),
},
});
}
...
...
@@ -18199,13 +18200,10 @@ function registerPage({ url, path, query, openType, webview, eventChannel, }) {
const pageInstance = initPageInternalInstance(openType, url, query, routeOptions.meta, eventChannel);
initNVueEntryPage(webview);
if (webview.nvue) {
// nvue 时,先启用一个占位 vm
const fakeNVueVm = createNVueVm(parseInt(webview.id), webview, pageInstance);
initPageVm(fakeNVueVm, pageInstance);
addCurrentPage(fakeNVueVm);
createNVuePage(parseInt(webview.id), webview, pageInstance);
}
else {
createPage(parseInt(webview.id), route, query, pageInstance, initPageOptions(routeOptions));
create
Vue
Page(parseInt(webview.id), route, query, pageInstance, initPageOptions(routeOptions));
}
return webview;
}
...
...
@@ -18245,24 +18243,9 @@ function initNVueEntryPage(webview) {
});
}
}
function createNVue
Vm
(pageId, webview, pageInstance) {
return
{
function createNVue
Page
(pageId, webview, pageInstance) {
const fakeNVueVm =
{
$: {},
onNVuePageCreated(vm, curNVuePage) {
vm.$ = {}; // 补充一个 nvue 的 $ 对象,模拟 vue3 的,不然有部分地方访问了 $
vm.$getAppWebview = () => webview;
vm.getOpenerEventChannel = curNVuePage.getOpenerEventChannel;
// 替换真实的 nvue 的 vm
initPageVm(vm, pageInstance);
const pages = getAllPages();
const index = pages.findIndex((p) => p === curNVuePage);
if (index > -1) {
pages.splice(index, 1, vm);
}
if (webview.__preload__) {
webview.__page__ = vm;
}
},
$getAppWebview() {
return webview;
},
...
...
@@ -18272,7 +18255,23 @@ function createNVueVm(pageId, webview, pageInstance) {
}
return pageInstance.eventChannel;
},
__setup(vm, curFakeNVueVm) {
const pages = getAllPages();
const index = pages.findIndex((p) => p === curFakeNVueVm);
if (index > -1) {
vm.$getAppWebview = () => webview;
vm.getOpenerEventChannel = curFakeNVueVm.getOpenerEventChannel;
// 替换真实的 nvue 的 vm
initPageVm(vm, pageInstance);
pages.splice(index, 1, vm);
if (webview.__preload__) {
webview.__page__ = vm;
}
}
},
};
initPageVm(fakeNVueVm, pageInstance);
addCurrentPage(fakeNVueVm);
}
const $navigateTo = (args, { resolve, reject }) => {
...
...
packages/uni-app-plus/src/service/framework/page/define.ts
浏览文件 @
c3eadd64
...
...
@@ -31,7 +31,7 @@ interface PageProps {
__pageInstance
:
Page
.
PageInstance
[
'
$page
'
]
}
export
function
createPage
(
export
function
create
Vue
Page
(
__pageId
:
number
,
__pagePath
:
string
,
__pageQuery
:
Record
<
string
,
any
>
,
...
...
packages/uni-app-plus/src/service/framework/page/preLoad.ts
浏览文件 @
c3eadd64
...
...
@@ -58,9 +58,8 @@ export function preloadWebview({
path
,
routeOptions
,
query
,
webview
Style
:
{
webview
Extras
:
{
__preload__
:
true
,
__query__
:
JSON
.
stringify
(
query
),
},
})
}
...
...
packages/uni-app-plus/src/service/framework/page/register.ts
浏览文件 @
c3eadd64
...
...
@@ -12,7 +12,7 @@ import { initPageInternalInstance, initPageVm } from '@dcloudio/uni-core'
import
{
initEntry
}
from
'
../app/initEntry
'
import
{
initRouteOptions
}
from
'
./routeOptions
'
import
{
createWebview
,
initWebview
}
from
'
../webview
'
import
{
createPage
}
from
'
./define
'
import
{
create
Vue
Page
}
from
'
./define
'
import
{
getStatusbarHeight
}
from
'
../../../helpers/statusBar
'
import
tabBar
from
'
../app/tabBar
'
import
{
addCurrentPage
,
getAllPages
}
from
'
./getCurrentPages
'
...
...
@@ -108,16 +108,9 @@ export function registerPage({
initNVueEntryPage
(
webview
)
if
((
webview
as
any
).
nvue
)
{
// nvue 时,先启用一个占位 vm
const
fakeNVueVm
=
createNVueVm
(
parseInt
(
webview
.
id
!
),
webview
,
pageInstance
)
initPageVm
(
fakeNVueVm
,
pageInstance
)
addCurrentPage
(
fakeNVueVm
)
createNVuePage
(
parseInt
(
webview
.
id
!
),
webview
,
pageInstance
)
}
else
{
createPage
(
create
Vue
Page
(
parseInt
(
webview
.
id
!
),
route
,
query
,
...
...
@@ -170,28 +163,13 @@ function initNVueEntryPage(webview: PlusWebviewWebviewObject) {
}
}
function
createNVue
Vm
(
function
createNVue
Page
(
pageId
:
number
,
webview
:
PlusWebviewWebviewObject
,
pageInstance
:
Page
.
PageInstance
[
'
$page
'
]
)
{
return
{
$
:
{},
// navigateBack 时,invokeHook 会调用 $
onNVuePageCreated
(
vm
:
ComponentPublicInstance
,
curNVuePage
:
unknown
)
{
;(
vm
as
any
).
$
=
{}
// 补充一个 nvue 的 $ 对象,模拟 vue3 的,不然有部分地方访问了 $
vm
.
$getAppWebview
=
()
=>
webview
vm
.
getOpenerEventChannel
=
(
curNVuePage
as
any
).
getOpenerEventChannel
// 替换真实的 nvue 的 vm
initPageVm
(
vm
,
pageInstance
)
const
pages
=
getAllPages
()
const
index
=
pages
.
findIndex
((
p
)
=>
p
===
curNVuePage
)
if
(
index
>
-
1
)
{
pages
.
splice
(
index
,
1
,
vm
)
}
if
((
webview
as
PreloadWebviewObject
).
__preload__
)
{
;(
webview
as
PreloadWebviewObject
).
__page__
=
vm
}
},
const
fakeNVueVm
=
{
$
:
{},
$getAppWebview
()
{
return
webview
},
...
...
@@ -201,5 +179,21 @@ function createNVueVm(
}
return
pageInstance
.
eventChannel
as
EventChannel
},
__setup
(
vm
:
ComponentPublicInstance
,
curFakeNVueVm
:
unknown
)
{
const
pages
=
getAllPages
()
const
index
=
pages
.
findIndex
((
p
)
=>
p
===
curFakeNVueVm
)
if
(
index
>
-
1
)
{
vm
.
$getAppWebview
=
()
=>
webview
vm
.
getOpenerEventChannel
=
(
curFakeNVueVm
as
any
).
getOpenerEventChannel
// 替换真实的 nvue 的 vm
initPageVm
(
vm
,
pageInstance
)
pages
.
splice
(
index
,
1
,
vm
)
if
((
webview
as
PreloadWebviewObject
).
__preload__
)
{
;(
webview
as
PreloadWebviewObject
).
__page__
=
vm
}
}
},
}
as
unknown
as
ComponentPublicInstance
initPageVm
(
fakeNVueVm
,
pageInstance
)
addCurrentPage
(
fakeNVueVm
)
}
packages/uni-app-plus/src/service/framework/page/setup.ts
浏览文件 @
c3eadd64
...
...
@@ -12,7 +12,7 @@ import {
onBeforeUnmount
,
onMounted
,
}
from
'
vue
'
import
{
VuePageComponent
}
from
'
./define
'
import
type
{
VuePageComponent
}
from
'
./define
'
import
{
addCurrentPage
}
from
'
./getCurrentPages
'
export
function
setupPage
(
component
:
VuePageComponent
)
{
...
...
packages/uni-app-plus/src/service/framework/webview/index.ts
浏览文件 @
c3eadd64
...
...
@@ -11,7 +11,7 @@ export interface CreateWebviewOptions {
path
:
string
query
:
Record
<
string
,
string
>
routeOptions
:
UniApp
.
UniRoute
webview
Style
?:
Record
<
string
,
any
>
webview
Extras
?:
Record
<
string
,
any
>
}
export
function
createWebview
(
options
:
CreateWebviewOptions
)
{
...
...
packages/uni-app-plus/src/service/framework/webview/nvue.ts
浏览文件 @
c3eadd64
...
...
@@ -9,7 +9,7 @@ export function createNVueWebview({
path
,
query
,
routeOptions
,
webview
Style
,
webview
Extras
,
}:
CreateWebviewOptions
)
{
const
curWebviewId
=
genWebviewId
()
const
curWebviewStyle
=
parseWebviewStyle
(
path
,
routeOptions
.
meta
,
{
...
...
@@ -30,8 +30,10 @@ export function createNVueWebview({
extend
(
{
nvue
:
true
,
__path__
:
path
,
__query__
:
JSON
.
stringify
(
query
),
},
webview
Style
webview
Extras
)
)
}
packages/uni-app-vite/src/nvue/plugins/esbuild.ts
浏览文件 @
c3eadd64
...
...
@@ -57,8 +57,13 @@ function buildNVuePage(filename: string, options: BuildOptions) {
return
transformWithEsbuild
(
`import App from './
${
filename
}
'
import { AppStyles } from './app.css.js'
const app = Vue.createApp(App,{$store:getApp().$store})
const webview = plus.webview.currentWebview()
const __pageId = parseInt(webview.id)
const __pagePath = webview.__path__
let __pageQuery = {}
try{ __pageQuery = JSON.parse(webview.__query__) }catch(e){}
App.mpType = 'page'
const app = Vue.createApp(App,{$store:getApp().$store,__pageId,__pagePath,__pageQuery})
app.provide('__globalStyles', Vue.useCssStyles([...AppStyles, ...App.styles]))
app.mount('#root')`
,
path
.
join
(
nvueOutDir
(),
'
main.js
'
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录