提交 fb2e5277 编写于 作者: Q qiang

feat: App、H5 新增 rpx 计算相关配置

上级 211d4749
......@@ -17,7 +17,7 @@ const {
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
initTheme,
initTheme,
parseTheme
} = require('@dcloudio/uni-cli-shared/lib/theme')
......@@ -95,7 +95,7 @@ module.exports = function (content, map) {
})
}
const jsonFiles = require('./platforms/' + process.env.UNI_PLATFORM)(pagesJson, manifestJson)
const jsonFiles = require('./platforms/' + process.env.UNI_PLATFORM)(pagesJson, manifestJson, isAppView)
if (jsonFiles && jsonFiles.length) {
if (process.env.UNI_USING_V3) {
......@@ -144,4 +144,4 @@ module.exports = function (content, map) {
}
this.callback(null, '', map)
}
}
......@@ -7,10 +7,14 @@ function generatePageCode (pages, pageOptions) {
}).join('\n')
}
module.exports = function definePages (appJson) {
function generateUniConfig (appJson, isAppView) {
return isAppView ? `window.__uniConfig = ${JSON.stringify({ window: appJson.window }, null)};` : ''
}
module.exports = function definePages (appJson, isAppView) {
return {
name: 'define-pages.js',
content: `
content: `
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
const promise = this.constructor
......@@ -22,10 +26,11 @@ if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
)
}
}
${generateUniConfig(appJson, isAppView)}
if(uni.restoreGlobal){
uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
}
${generatePageCode(appJson.pages, appJson.page)}
`
}
}
}
......@@ -91,7 +91,7 @@ function updateFileFlag (appJson) {
}
}
module.exports = function (pagesJson, userManifestJson) {
module.exports = function (pagesJson, userManifestJson, isAppView) {
const {
app
} = require('../mp')(pagesJson, userManifestJson)
......@@ -179,7 +179,7 @@ module.exports = function (pagesJson, userManifestJson) {
if (!manifestJson.permissions) {
manifestJson.permissions = {}
}
const nvuePages = process.env.UNI_USING_V3_NATIVE ? pagesJson.pages : (pagesJson.nvue && pagesJson.nvue.pages)
if (nvuePages && nvuePages.length) {
......@@ -197,12 +197,12 @@ module.exports = function (pagesJson, userManifestJson) {
appJson.nvue = {
pages
}
if (process.env.UNI_USING_V3_NATIVE) {
appJson.nvue.entryPagePath = nvuePages[0]
} else if (pagesJson.nvue.entryPagePath) {
appJson.nvue.entryPagePath = pagesJson.nvue.entryPagePath
}
if (process.env.UNI_USING_V3_NATIVE) {
appJson.nvue.entryPagePath = nvuePages[0]
} else if (pagesJson.nvue.entryPagePath) {
appJson.nvue.entryPagePath = pagesJson.nvue.entryPagePath
}
// nvue 权限
manifestJson.permissions.UniNView = {
......@@ -347,10 +347,10 @@ module.exports = function (pagesJson, userManifestJson) {
resources[key.replace(/\.nvue$/, '.js')] = confusion.resources[key]
}
if (!Object.keys(nvuePages).find(path => {
const subNVues = nvuePages[path].window.subNVues || []
// TODO
return (path.replace(/\.html$/, '.nvue') === key || path.replace(/\.html$/, '.nvue') + '.nvue' === key) || subNVues.find(({
path
const subNVues = nvuePages[path].window.subNVues || []
// TODO
return (path.replace(/\.html$/, '.nvue') === key || path.replace(/\.html$/, '.nvue') + '.nvue' === key) || subNVues.find(({
path
}) => path === key.replace(/\.nvue$/, ''))
}) && !pagesJson.pages.find(({
style = {}
......@@ -514,7 +514,7 @@ module.exports = function (pagesJson, userManifestJson) {
manifest,
pagesJson,
normalizeNetworkTimeout
})
}, isAppView)
}
return [app, manifest]
}
}
......@@ -52,7 +52,7 @@ module.exports = function (appJson, manifestJson, {
pagesJson,
manifest,
normalizeNetworkTimeout
}) {
}, isAppView) {
parseEntryPagePath(appJson, manifestJson)
// timeout
......@@ -82,12 +82,12 @@ module.exports = function (appJson, manifestJson, {
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
delete manifestJson.plus.launchwebview['uni-app']
const entryPagePath = appJson.entryPagePath
if (!appJson.page[entryPagePath]) {
console.error(
`pages.json condition['list'][current]['path']: ${entryPagePath} 需在 pages 数组中`
)
process.exit(0)
const entryPagePath = appJson.entryPagePath
if (!appJson.page[entryPagePath]) {
console.error(
`pages.json condition['list'][current]['path']: ${entryPagePath} 需在 pages 数组中`
)
process.exit(0)
}
if (appJson.page[entryPagePath].nvue) { // 首页是 nvue
manifestJson.launch_path = '' // 首页地址为空
......@@ -109,5 +109,5 @@ module.exports = function (appJson, manifestJson, {
manifest.name = 'manifest.json'
manifest.content = JSON.stringify(manifest.content)
delete appJson.nvue
return [manifest, definePages(appJson), appConfigService(appJson)]
return [manifest, definePages(appJson, isAppView), appConfigService(appJson)]
}
......@@ -16,6 +16,11 @@ function checkDeviceWidth () {
isIOS = platform === 'ios'
}
function checkValue (value, defaultValue) {
value = Number(value)
return isNaN(value) ? defaultValue : value
}
export function upx2px (number, newDeviceWidth) {
if (deviceWidth === 0) {
checkDeviceWidth()
......@@ -25,7 +30,13 @@ export function upx2px (number, newDeviceWidth) {
if (number === 0) {
return 0
}
let result = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth)
const config = __uniConfig.globalStyle || __uniConfig.window || {}
const maxWidth = checkValue(config.rpxCalcMaxDeviceWidth, 960)
const baseWidth = checkValue(config.rpxCalcBaseDeviceWidth, 375)
const includeWidth = checkValue(config.rpxCalcIncludeWidth, 750)
let width = newDeviceWidth || deviceWidth
width = number === includeWidth || width <= maxWidth ? width : baseWidth
let result = (number / BASE_DEVICE_WIDTH) * width
if (result < 0) {
result = -result
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册