提交 be9dfe80 编写于 作者: fxy060608's avatar fxy060608

feat(v3): condition

上级 5aa2189e
......@@ -7111,8 +7111,8 @@ var serviceContext = (function () {
if (!currentPage.__uniapp_webview) {
return backPage(webview)
}
backWebview(webview, () => {
backPage(webview);
backWebview(webview, () => {
backPage(webview);
});
}
......@@ -7138,10 +7138,16 @@ var serviceContext = (function () {
uni.hideToast(); // 后退时,关闭 toast,loading
currentPage.$page.meta.isQuit
? quit()
: back(delta, animationType, animationDuration);
// 当前页面是 condition 进入
if (currentPage.$page.id === 1 && __uniConfig.realEntryPagePath) {
uni.reLaunch({
url: '/' + __uniConfig.realEntryPagePath
});
} else {
currentPage.$page.meta.isQuit
? quit()
: back(delta, animationType, animationDuration);
}
return {
errMsg: 'navigateBack:ok'
}
......@@ -7319,7 +7325,7 @@ var serviceContext = (function () {
const titleNView = parseTitleNView(routeOptions);
if (titleNView) {
if (id === 1 && __uniConfig.realEntryPagePath === path) {
if (id === 1 && __uniConfig.realEntryPagePath) {
titleNView.autoBackButton = true;
}
webviewStyle.titleNView = titleNView;
......@@ -7995,17 +8001,16 @@ var serviceContext = (function () {
'none',
0,
() => {
pages.forEach(page => {
page.$remove();
page.$getAppWebview().close('none');
});
invoke$1(callbackId, {
errMsg: 'reLaunch:ok'
});
}
);
pages.forEach(page => {
page.$remove();
page.$getAppWebview().close('none');
});
setStatusBarStyle();
}
......
......@@ -4,27 +4,19 @@ const path = require('path')
const merge = require('merge')
const {
parsePages,
normalizePath,
getFlexDirection
} = require('@dcloudio/uni-cli-shared')
const {
addPageUsingComponents
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
parseStyle
} = require('../../util')
const definePages = require('./define-pages')
const appConfigService = require('./app-config-service')
const wxPageOrientationMapping = {
auto: ['portrait-primary', 'portrait-secondary', 'landscape-primary', 'landscape-secondary'],
portrait: ['portrait-primary', 'portrait-secondary'],
landscape: ['landscape-primary', 'landscape-secondary']
}
const wxPageOrientationMapping = {
auto: ['portrait-primary', 'portrait-secondary', 'landscape-primary', 'landscape-secondary'],
portrait: ['portrait-primary', 'portrait-secondary'],
landscape: ['landscape-primary', 'landscape-secondary']
}
function parseConfig (appJson) {
return {
......@@ -137,7 +129,7 @@ module.exports = function (pagesJson, userManifestJson) {
if (manifestJson.plus.screenOrientation) { // app平台优先使用 manifest 配置
manifestJson.screenOrientation = manifestJson.plus.screenOrientation
delete manifestJson.plus.screenOrientation
} else if (appJson.window && appJson.window.pageOrientation) { // 兼容微信小程序
} else if (appJson.window && appJson.window.pageOrientation) { // 兼容微信小程序
const pageOrientationValue = wxPageOrientationMapping[appJson.window.pageOrientation]
if (pageOrientationValue) {
manifestJson.screenOrientation = pageOrientationValue
......@@ -484,51 +476,12 @@ module.exports = function (pagesJson, userManifestJson) {
return [manifest, parseConfig(appJson)]
}
if (process.env.UNI_USING_V3) { // v3
appJson.entryPagePath = appJson.pages[0]
// timeout
normalizeNetworkTimeout(appJson)
appJson.page = Object.create(null)
const addPage = function (pagePath, windowOptions, nvue) {
// 缓存页面级usingComponents
addPageUsingComponents(pagePath, windowOptions.usingComponents)
delete windowOptions.usingComponents
appJson.page[pagePath] = {
window: windowOptions,
nvue
}
}
parsePages(pagesJson, function (page) {
addPage(page.path, parseStyle(page.style), !!page.nvue)
}, function (root, page) {
addPage(normalizePath(path.join(root, page.path)), parseStyle(page.style, root), !!page.nvue)
if (process.env.UNI_USING_V3) {
return require('./index.v3')(appJson, manifestJson, {
manifest,
pagesJson,
normalizeNetworkTimeout
})
// nvue 权限
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
}
// TODO 需要考虑 condition
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
delete manifestJson.plus.launchwebview['uni-app']
if (appJson.page[appJson.entryPagePath].nvue) { // 首页是 nvue
manifestJson.launch_path = '' // 首页地址为空
manifestJson.plus.launchwebview.uniNView = {
path: appJson.entryPagePath
}
if (manifestJson.plus.tabBar) {
manifestJson.plus.tabBar.child = ['lauchwebview']
}
} else {
manifestJson.plus.launch_path = '__uniappview.html' // 首页地址固定
}
manifest.name = 'manifest.json'
manifest.content = JSON.stringify(manifest.content)
delete appJson.nvue
return [manifest, definePages(appJson), appConfigService(appJson)]
}
return [app, manifest]
}
const path = require('path')
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const {
parsePages,
addPageUsingComponents
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
parseStyle
} = require('../../util')
const definePages = require('./define-pages')
const appConfigService = require('./app-config-service')
function parseEntryPagePath (appJson, manifestJson) {
const argsJsonStr = manifestJson.plus.arguments
if (argsJsonStr) {
try {
const args = JSON.parse(argsJsonStr)
const pathName = args.path || args.pathName
if (pathName && pathName !== appJson.pages[0]) {
appJson.entryPagePath = pathName
appJson.realEntryPagePath = appJson.pages[0]
}
} catch (e) {}
}
if (!appJson.entryPagePath) {
appJson.entryPagePath = appJson.pages[0]
}
}
module.exports = function (appJson, manifestJson, {
pagesJson,
manifest,
normalizeNetworkTimeout
}) {
parseEntryPagePath(appJson, manifestJson)
// timeout
normalizeNetworkTimeout(appJson)
appJson.page = Object.create(null)
const addPage = function (pagePath, windowOptions, nvue) {
// 缓存页面级usingComponents
addPageUsingComponents(pagePath, windowOptions.usingComponents)
delete windowOptions.usingComponents
appJson.page[pagePath] = {
window: windowOptions,
nvue
}
}
parsePages(pagesJson, function (page) {
addPage(page.path, parseStyle(page.style), !!page.nvue)
}, function (root, page) {
addPage(normalizePath(path.join(root, page.path)), parseStyle(page.style, root), !!page.nvue)
})
// nvue 权限
manifestJson.permissions.UniNView = {
'description': 'UniNView原生渲染'
}
// TODO 需要考虑 condition
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
delete manifestJson.plus.launchwebview['uni-app']
if (appJson.page[appJson.entryPagePath].nvue) { // 首页是 nvue
manifestJson.launch_path = '' // 首页地址为空
manifestJson.plus.launchwebview.uniNView = {
path: appJson.entryPagePath
}
if (manifestJson.plus.tabBar) {
manifestJson.plus.tabBar.child = ['lauchwebview']
}
} else {
manifestJson.plus.launch_path = '__uniappview.html' // 首页地址固定
}
manifest.name = 'manifest.json'
manifest.content = JSON.stringify(manifest.content)
delete appJson.nvue
return [manifest, definePages(appJson), appConfigService(appJson)]
}
......@@ -67,22 +67,21 @@ const manifestJson2AppJson = {
'debug': defaultCopy
}
const pagesJson2ProjectJson = {
'condition': function (name, value, json) {
if (process.env.NODE_ENV === 'development') { // 仅开发期间 condition 生效
// 启动Condition
const condition = getCondition(value)
if (condition) {
if (!json.condition) {
json.condition = {}
}
process.UNI_CONDITION = condition // app-plus编译时,需要获取该参数
json.condition.miniprogram = condition
function parseCondition (projectJson, pagesJson) {
if (process.env.NODE_ENV === 'development') { // 仅开发期间 condition 生效
// 启动Condition
const condition = getCondition(pagesJson)
if (condition) {
if (!projectJson.condition) {
projectJson.condition = {}
}
projectJson.condition.miniprogram = condition
}
}
}
const pagesJson2ProjectJson = {}
const manifestJson2ProjectJson = {
'name': function (name, value, json) {
......@@ -119,7 +118,8 @@ function copyToJson (json, fromJson, options) {
})
}
function getCondition (condition) {
function getCondition (pagesJson) {
const condition = pagesJson.condition
const launchPagePath = process.env.UNI_CLI_LAUNCH_PAGE_PATH || ''
const launchPageQuery = process.env.UNI_CLI_LAUNCH_PAGE_QUERY || ''
......@@ -158,10 +158,11 @@ function getCondition (condition) {
}
}
if (launchPagePath) {
return {
pagesJson.condition = {
'current': 0,
'list': [launchPageOptions]
}
return pagesJson.condition
}
return false
}
......@@ -248,7 +249,9 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
content: require(projectPath)
}
}
} else {
} else {
parseCondition(project, pagesJson)
copyToJson(project, pagesJson, pagesJson2ProjectJson)
copyToJson(project, manifestJson, manifestJson2ProjectJson)
......
......@@ -73,8 +73,8 @@ function back (delta, animationType, animationDuration) {
if (!currentPage.__uniapp_webview) {
return backPage(webview)
}
backWebview(webview, () => {
backPage(webview)
backWebview(webview, () => {
backPage(webview)
})
}
......@@ -100,10 +100,16 @@ export function navigateBack ({
uni.hideToast() // 后退时,关闭 toast,loading
currentPage.$page.meta.isQuit
? quit()
: back(delta, animationType, animationDuration)
// 当前页面是 condition 进入
if (currentPage.$page.id === 1 && __uniConfig.realEntryPagePath) {
uni.reLaunch({
url: '/' + __uniConfig.realEntryPagePath
})
} else {
currentPage.$page.meta.isQuit
? quit()
: back(delta, animationType, animationDuration)
}
return {
errMsg: 'navigateBack:ok'
}
......
......@@ -42,17 +42,16 @@ function _reLaunch ({
'none',
0,
() => {
pages.forEach(page => {
page.$remove()
page.$getAppWebview().close('none')
})
invoke(callbackId, {
errMsg: 'reLaunch:ok'
})
}
)
pages.forEach(page => {
page.$remove()
page.$getAppWebview().close('none')
})
setStatusBarStyle()
}
......
......@@ -44,7 +44,7 @@ export function parseWebviewStyle (id, path, routeOptions = {}) {
const titleNView = parseTitleNView(routeOptions)
if (titleNView) {
if (id === 1 && __uniConfig.realEntryPagePath === path) {
if (id === 1 && __uniConfig.realEntryPagePath) {
titleNView.autoBackButton = true
}
webviewStyle.titleNView = titleNView
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册