Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
21547aeb
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,发现更多精彩内容 >>
提交
21547aeb
编写于
12月 16, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): support condition (#3079)
上级
0152af33
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
12 deletion
+60
-12
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+7
-1
packages/uni-cli-shared/src/json/mp/project.ts
packages/uni-cli-shared/src/json/mp/project.ts
+47
-6
packages/uni-mp-vite/src/plugins/manifestJson.ts
packages/uni-mp-vite/src/plugins/manifestJson.ts
+6
-5
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
21547aeb
...
...
@@ -256,7 +256,13 @@ declare namespace UniApp {
}
condition
?:
{
current
?:
number
list
?:
{
name
?:
string
;
path
:
string
;
query
?:
string
}[]
list
?:
{
id
?:
string
|
number
name
?:
string
path
?:
string
pathName
?:
string
query
?:
string
}[]
}
}
...
...
packages/uni-cli-shared/src/json/mp/project.ts
浏览文件 @
21547aeb
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
hasOwn
,
isArray
}
from
'
@vue/shared
'
import
{
parseJson
}
from
'
../json
'
interface
ParseMiniProgramProjectJsonOptions
{
template
:
Record
<
string
,
any
>
pagesJson
:
UniApp
.
PagesJson
}
interface
ProjectConfig
{
projectname
:
string
condition
?:
{
miniprogram
?:
UniApp
.
PagesJson
[
'
condition
'
]
}
}
const
projectKeys
=
[
...
...
@@ -31,20 +35,57 @@ export function isMiniProgramProjectJsonKey(name: string) {
export
function
parseMiniProgramProjectJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
,
{
template
}:
ParseMiniProgramProjectJsonOptions
{
template
,
pagesJson
}:
ParseMiniProgramProjectJsonOptions
)
{
const
project
=
JSON
.
parse
(
JSON
.
stringify
(
template
))
as
ProjectConfig
const
project
Json
=
JSON
.
parse
(
JSON
.
stringify
(
template
))
as
ProjectConfig
const
manifestJson
=
parseJson
(
jsonStr
)
if
(
manifestJson
)
{
project
.
projectname
=
manifestJson
.
name
project
Json
.
projectname
=
manifestJson
.
name
const
platformConfig
=
manifestJson
[
platform
]
if
(
platformConfig
)
{
projectKeys
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
platformConfig
,
name
))
{
;(
project
as
Record
<
string
,
any
>
)[
name
]
=
platformConfig
[
name
]
;(
project
Json
as
Record
<
string
,
any
>
)[
name
]
=
platformConfig
[
name
]
}
})
}
}
return
project
// 其实仅开发期间 condition 生效即可,暂不做判断
const
miniprogram
=
parseMiniProgramCondition
(
pagesJson
)
if
(
miniprogram
)
{
if
(
!
projectJson
.
condition
)
{
projectJson
.
condition
=
{}
}
projectJson
.
condition
.
miniprogram
=
miniprogram
}
return
projectJson
}
function
parseMiniProgramCondition
(
pagesJson
:
UniApp
.
PagesJson
)
{
const
launchPagePath
=
process
.
env
.
UNI_CLI_LAUNCH_PAGE_PATH
||
''
if
(
launchPagePath
)
{
return
{
current
:
0
,
list
:
[
{
id
:
0
,
name
:
launchPagePath
,
// 模式名称
pathName
:
launchPagePath
,
// 启动页面,必选
query
:
process
.
env
.
UNI_CLI_LAUNCH_PAGE_QUERY
||
''
,
// 启动参数,在页面的onLoad函数里面得到。
},
],
}
}
const
condition
=
pagesJson
.
condition
if
(
!
condition
||
!
isArray
(
condition
.
list
)
||
!
condition
.
list
.
length
)
{
return
}
condition
.
list
.
forEach
(
function
(
item
,
index
)
{
item
.
id
=
item
.
id
||
index
if
(
item
.
path
)
{
item
.
pathName
=
item
.
path
delete
item
.
path
}
})
return
condition
}
packages/uni-mp-vite/src/plugins/manifestJson.ts
浏览文件 @
21547aeb
...
...
@@ -5,6 +5,7 @@ import {
defineUniManifestJsonPlugin
,
getLocaleFiles
,
parseMiniProgramProjectJson
,
parsePagesJsonOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
../plugin
'
...
...
@@ -21,6 +22,7 @@ export function uniManifestJsonPlugin(
return
}
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
platform
=
process
.
env
.
UNI_PLATFORM
this
.
addWatchFile
(
path
.
resolve
(
inputDir
,
'
manifest.json
'
))
getLocaleFiles
(
path
.
resolve
(
inputDir
,
'
locale
'
)).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
...
...
@@ -40,11 +42,10 @@ export function uniManifestJsonPlugin(
}
template
.
setting
.
urlCheck
=
false
}
projectJson
=
parseMiniProgramProjectJson
(
code
,
process
.
env
.
UNI_PLATFORM
,
{
template
}
)
projectJson
=
parseMiniProgramProjectJson
(
code
,
platform
,
{
template
,
pagesJson
:
parsePagesJsonOnce
(
inputDir
,
platform
),
})
}
else
{
// 无需解析,直接拷贝,如 quickapp-webview
projectJson
=
template
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录