Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
dad264b4
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
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,发现更多精彩内容 >>
提交
dad264b4
编写于
5月 20, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): support nvue mode
上级
51251932
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
69 deletion
+105
-69
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+3
-0
packages/uni-cli-shared/src/json/pages.ts
packages/uni-cli-shared/src/json/pages.ts
+10
-5
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+28
-17
packages/uni-h5/src/framework/setup/page.ts
packages/uni-h5/src/framework/setup/page.ts
+12
-0
packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
...s/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
+35
-30
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
+4
-4
packages/vite-plugin-uni/src/utils/ssr.ts
packages/vite-plugin-uni/src/utils/ssr.ts
+13
-13
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
dad264b4
...
...
@@ -27,6 +27,9 @@ declare namespace UniApp {
strict
:
boolean
base
:
string
}
nvue
:
{
'
flex-direction
'
:
'
column
'
|
'
row
'
}
globalStyle
:
{
navigationBar
:
PageNavigationBar
refreshOptions
?:
PageRefreshOptions
...
...
packages/uni-cli-shared/src/json/pages.ts
浏览文件 @
dad264b4
...
...
@@ -13,14 +13,18 @@ export const parsePagesJson = (
)
=>
{
const
jsonStr
=
fs
.
readFileSync
(
path
.
join
(
inputDir
,
'
pages.json
'
),
'
utf8
'
)
if
(
normalize
)
{
return
normalizePagesJson
(
jsonStr
,
platform
)
return
normalizePagesJson
(
jsonStr
,
inputDir
,
platform
)
}
return
parseJson
(
jsonStr
,
true
)
as
UniApp
.
PagesJson
}
export
const
parsePagesJsonOnce
=
once
(
parsePagesJson
)
export
function
normalizePagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
export
function
normalizePagesJson
(
jsonStr
:
string
,
inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
let
pagesJson
:
UniApp
.
PagesJson
=
{
pages
:
[],
globalStyle
:
{
...
...
@@ -40,7 +44,7 @@ export function normalizePagesJson(jsonStr: string, platform: UniApp.PLATFORM) {
...
normalizeSubpackages
(
pagesJson
.
subPackages
||
pagesJson
.
subpackages
)
)
// pageStyle
normalizePages
(
pagesJson
.
pages
,
platform
)
normalizePages
(
pagesJson
.
pages
,
inputDir
,
platform
)
// globalStyle
pagesJson
.
globalStyle
=
normalizePageStyle
(
pagesJson
.
globalStyle
!
,
platform
)
// tabBar
...
...
@@ -69,12 +73,13 @@ function validatePages(pagesJson: Record<string, any>, jsonStr: string) {
function
normalizePages
(
pages
:
UniApp
.
PagesJsonPageOptions
[],
_inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
pages
.
forEach
((
page
)
=>
{
return
pages
.
filter
((
page
)
=>
{
page
.
style
=
normalizePageStyle
(
page
.
style
!
,
platform
)
return
true
})
return
pages
}
function
normalizeSubpackages
(
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
dad264b4
...
...
@@ -485,7 +485,7 @@ var safeAreaInsets = {
onChange,
offChange
};
var
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out = safeAreaInsets;
var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => {
...
...
@@ -497,10 +497,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right"));
return {
top: top ? top +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top : 0,
bottom: bottom ? bottom +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom : 0,
left: left ? left +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left : 0,
right: right ? right +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right : 0
top: top ? top + out.top : 0,
bottom: bottom ? bottom + out.bottom : 0,
left: left ? left + out.left : 0,
right: right ? right + out.right : 0
};
}
function updateCssVar(cssVars) {
...
...
@@ -1190,7 +1190,7 @@ function normalizePageMeta(pageMeta) {
let offset = rpx2px(refreshOptions.offset);
const {type} = navigationBar;
if (type !== "transparent" && type !== "none") {
offset += NAVBAR_HEIGHT +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
offset += NAVBAR_HEIGHT + out.top;
}
refreshOptions.offset = offset;
refreshOptions.height = rpx2px(refreshOptions.height);
...
...
@@ -12978,9 +12978,20 @@ function pruneRouteCache(key) {
}
});
}
function updateCurPageAttrs(pageMeta) {
const nvueDirKey = "nvue-dir-" + __uniConfig.nvue["flex-direction"];
if (pageMeta.isNVue) {
document.body.setAttribute("nvue", "");
document.body.setAttribute(nvueDirKey, "");
} else {
document.body.removeAttribute("nvue");
document.body.removeAttribute(nvueDirKey);
}
}
function onPageShow(instance2, pageMeta) {
updateBodyScopeId(instance2);
updateCurPageCssVar(pageMeta);
updateCurPageAttrs(pageMeta);
initPageScrollListener(instance2, pageMeta);
}
function onPageReady(instance2) {
...
...
@@ -14928,7 +14939,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight;
const language = navigator.language;
const statusBarHeight =
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
const statusBarHeight = out.top;
let osname;
let osversion;
let model;
...
...
@@ -15041,12 +15052,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
const safeArea = {
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left,
right: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
bottom: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
width: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
height: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom
left: out.left,
right: windowWidth - out.right,
top: out.top,
bottom: windowHeight - out.bottom,
width: windowWidth -
out.left -
out.right,
height: windowHeight -
out.top -
out.bottom
};
const {top: windowTop, bottom: windowBottom} = getWindowOffset();
windowHeight -= windowTop;
...
...
@@ -15066,10 +15077,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model,
safeArea,
safeAreaInsets: {
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
right:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
bottom:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left
top: out.top,
right: out.right,
bottom: out.bottom,
left: out.left
}
};
});
...
...
packages/uni-h5/src/framework/setup/page.ts
浏览文件 @
dad264b4
...
...
@@ -184,12 +184,24 @@ function pruneRouteCache(key: string) {
})
}
function
updateCurPageAttrs
(
pageMeta
:
UniApp
.
PageRouteMeta
)
{
const
nvueDirKey
=
'
nvue-dir-
'
+
__uniConfig
.
nvue
[
'
flex-direction
'
]
if
(
pageMeta
.
isNVue
)
{
document
.
body
.
setAttribute
(
'
nvue
'
,
''
)
document
.
body
.
setAttribute
(
nvueDirKey
,
''
)
}
else
{
document
.
body
.
removeAttribute
(
'
nvue
'
)
document
.
body
.
removeAttribute
(
nvueDirKey
)
}
}
export
function
onPageShow
(
instance
:
ComponentInternalInstance
,
pageMeta
:
UniApp
.
PageRouteMeta
)
{
updateBodyScopeId
(
instance
)
updateCurPageCssVar
(
pageMeta
)
updateCurPageAttrs
(
pageMeta
)
initPageScrollListener
(
instance
,
pageMeta
)
}
...
...
packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
浏览文件 @
dad264b4
...
...
@@ -61,9 +61,13 @@ function generatePagesJsonCode(
options
:
VitePluginUniResolvedOptions
)
{
const
globalName
=
getGlobal
(
ssr
)
const
pagesJson
=
normalizePagesJson
(
jsonStr
,
options
.
platform
)
const
pagesJson
=
normalizePagesJson
(
jsonStr
,
options
.
inputDir
,
options
.
platform
)
const
definePagesCode
=
generatePagesDefineCode
(
pagesJson
,
config
)
const
uniRoutesCode
=
generateRoutes
(
globalName
,
pagesJson
,
config
)
const
uniRoutesCode
=
generateRoutes
(
globalName
,
pagesJson
,
config
,
options
)
const
uniConfigCode
=
generateConfig
(
globalName
,
pagesJson
,
options
)
const
manifestJsonPath
=
slash
(
path
.
resolve
(
options
.
inputDir
,
'
manifest.json.js
'
)
...
...
@@ -71,9 +75,7 @@ function generatePagesJsonCode(
const
cssCode
=
generateCssCode
(
config
,
options
)
return
`
import {
${
config
.
define
!
.
__UNI_FEATURE_PAGES__
?
'
defineAsyncComponent,
'
:
''
}
resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '
${
manifestJsonPath
}
'
const extend = Object.assign
...
...
@@ -124,9 +126,9 @@ function generateCssCode(
)
{
const
define
=
config
.
define
!
as
FEATURE_DEFINES
const
cssFiles
=
[
H5_FRAMEWORK_STYLE_PATH
+
'
base.css
'
]
if
(
define
.
__UNI_FEATURE_PAGES__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
async.css
'
)
}
//
if (define.__UNI_FEATURE_PAGES__) {
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
async.css
'
)
//
}
if
(
define
.
__UNI_FEATURE_RESPONSIVE__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
layout.css
'
)
}
...
...
@@ -167,16 +169,16 @@ const ${pageIdent} = defineAsyncComponent(extend({loader:${pageIdent}Loader},Asy
function
generatePagesDefineCode
(
pagesJson
:
UniApp
.
PagesJson
,
config
:
ResolvedConfig
_
config
:
ResolvedConfig
)
{
const
define
=
config
.
define
!
as
FEATURE_DEFINES
if
(
!
define
.
__UNI_FEATURE_PAGES__
)
{
// single page
const
pagePath
=
pagesJson
.
pages
[
0
].
path
return
`import
${
normalizePageIdentifier
(
pagePath
)}
from './
${
pagePath
}
.vue?mpType=page'`
}
//
const define = config.define! as FEATURE_DEFINES
//
if (!define.__UNI_FEATURE_PAGES__) {
//
// single page
//
const pagePath = pagesJson.pages[0].path
//
return `import ${normalizePageIdentifier(
//
pagePath
//
)} from './${pagePath}.vue?mpType=page'`
//
}
const
{
pages
}
=
pagesJson
return
(
`const AsyncComponentOptions = {
...
...
@@ -190,22 +192,28 @@ function generatePagesDefineCode(
)
}
function
normalizePagesRoute
(
pagesJson
:
UniApp
.
PagesJson
):
PageRouteOptions
[]
{
function
normalizePagesRoute
(
pagesJson
:
UniApp
.
PagesJson
,
options
:
VitePluginUniResolvedOptions
):
PageRouteOptions
[]
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
path
=
pageOptions
.
path
const
name
=
normalizePageIdentifier
(
path
)
const
isEntry
=
firstPagePath
===
path
?
true
:
undefined
const
pa
gePa
th
=
pageOptions
.
path
const
name
=
normalizePageIdentifier
(
pa
gePa
th
)
const
isEntry
=
firstPagePath
===
pa
gePa
th
?
true
:
undefined
const
tabBarIndex
=
tabBarList
.
findIndex
(
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
path
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
pa
gePa
th
)
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
const
isNVue
=
fs
.
existsSync
(
path
.
join
(
options
.
inputDir
,
pagePath
+
'
.nvue
'
)
)
let
windowTop
=
0
const
meta
=
Object
.
assign
(
{
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
...
...
@@ -231,11 +239,7 @@ function generatePageRoute(
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{render(){return renderPage(
${
name
}
)}},
loader:
${
config
.
define
!
.
__UNI_FEATURE_PAGES__
?
normalizePageIdentifier
(
path
)
+
'
Loader
'
:
'
null
'
}
,
loader:
${
normalizePageIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
}
...
...
@@ -252,14 +256,15 @@ function generatePagesRoute(
function
generateRoutes
(
globalName
:
string
,
pagesJson
:
UniApp
.
PagesJson
,
config
:
ResolvedConfig
config
:
ResolvedConfig
,
options
:
VitePluginUniResolvedOptions
)
{
return
`
function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
}
${
globalName
}
.__uniRoutes=[
${[
...
generatePagesRoute
(
normalizePagesRoute
(
pagesJson
),
config
),
...
generatePagesRoute
(
normalizePagesRoute
(
pagesJson
,
options
),
config
),
].
join
(
'
,
'
)}
]`
}
...
...
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
浏览文件 @
dad264b4
...
...
@@ -16,8 +16,8 @@ import {
isIdentifier
,
isCallExpression
,
isMemberExpression
,
generateS
SR
DefineCode
,
generateS
SR
EntryServerCode
,
generateS
sr
DefineCode
,
generateS
sr
EntryServerCode
,
}
from
'
../../utils
'
const
debugSSR
=
debug
(
'
vite:uni:ssr
'
)
...
...
@@ -32,7 +32,7 @@ export function uniSSRPlugin(
):
Plugin
{
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
const
entryServerJs
=
path
.
join
(
options
.
inputDir
,
ENTRY_SERVER_JS
)
const
entryServerJsCode
=
generateS
SR
EntryServerCode
()
const
entryServerJsCode
=
generateS
sr
EntryServerCode
()
return
{
name
:
'
vite:uni-ssr
'
,
resolveId
(
id
)
{
...
...
@@ -85,7 +85,7 @@ export function uniSSRPlugin(
const
chunk
=
bundle
[
'
entry-server.js
'
]
as
OutputChunk
if
(
chunk
)
{
chunk
.
code
=
generateS
SR
DefineCode
(
config
,
parseRpx2UnitOnce
(
options
.
inputDir
))
+
generateS
sr
DefineCode
(
config
,
parseRpx2UnitOnce
(
options
.
inputDir
))
+
'
\n
'
+
chunk
.
code
}
...
...
packages/vite-plugin-uni/src/utils/ssr.ts
浏览文件 @
dad264b4
...
...
@@ -50,29 +50,29 @@ function serializeDefine(define: Record<string, any>): string {
return
res
+
`}`
}
export
function
generateSSRDefineCode
(
function
normalizeSsrDefine
(
config
:
ResolvedConfig
)
{
const
defines
=
extend
(
{
__IMPORT_META_ENV_BASE_URL__
:
JSON
.
stringify
(
config
.
env
.
BASE_URL
),
},
config
.
define
!
)
delete
defines
[
'
import.meta.env.LEGACY
'
]
return
defines
}
export
function
generateSsrDefineCode
(
config
:
ResolvedConfig
,
{
unit
,
unitRatio
,
unitPrecision
}:
Rpx2UnitOptions
):
string
{
return
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
../../lib/ssr/define.js
'
),
'
utf8
'
)
.
replace
(
'
__DEFINES__
'
,
serializeDefine
(
extend
(
{
__IMPORT_META_ENV_BASE_URL__
:
JSON
.
stringify
(
config
.
env
.
BASE_URL
),
},
config
.
define
!
)
)
)
.
replace
(
'
__DEFINES__
'
,
serializeDefine
(
normalizeSsrDefine
(
config
)))
.
replace
(
'
__UNIT__
'
,
JSON
.
stringify
(
unit
))
.
replace
(
'
__UNIT_RATIO__
'
,
JSON
.
stringify
(
unitRatio
))
.
replace
(
'
__UNIT_PRECISION__
'
,
JSON
.
stringify
(
unitPrecision
))
}
export
function
generateS
SR
EntryServerCode
()
{
export
function
generateS
sr
EntryServerCode
()
{
return
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
../../lib/ssr/entry-server.js
'
),
'
utf8
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录