提交 67abe270 编写于 作者: D DCloud_LXH

fix: darkmode easycom question/156809

上级 000907d0
......@@ -6,12 +6,17 @@ const {
getJson
} = require('./json')
let themeConfig = {}
let manifestJsonDarkmode = false
function parseThemeByJsonStr (jsonStr, keys, theme) {
if (jsonStr.indexOf('@') === -1) {
return jsonStr
}
keys.forEach(key => {
jsonStr = jsonStr.replace(new RegExp('@' + key, 'g'), theme[key])
jsonStr = jsonStr.replace(new RegExp('@' + key, 'g'), $1 => {
return theme[key] || $1
})
})
return jsonStr
}
......@@ -22,11 +27,9 @@ function hasTheme (themeLocation = 'theme.json') {
}
function darkmode () {
return !!(global.uniPlugin.options || {}).darkmode
return manifestJsonDarkmode && !!(global.uniPlugin.options || {}).darkmode
}
let themeConfig = {}
module.exports = {
getTheme: () => themeConfig,
darkmode,
......@@ -34,6 +37,7 @@ module.exports = {
initTheme (manifestJson = {}) {
const platform = process.env.UNI_PLATFORM
const themeLocation = (manifestJson[platform] || {}).themeLocation || 'theme.json'
manifestJsonDarkmode = (manifestJson[platform] || {}).darkmode || false
if (!hasTheme(themeLocation)) {
return
}
......
......@@ -76,7 +76,7 @@ module.exports = function (content, map) {
}
this.addDependency(manifestJsonPath)
const originalPagesJson = parsePagesJson(content, {
const pagesJson = parsePagesJson(content, {
addDependency: file => {
(process.UNI_PAGES_DEPS || (process.UNI_PAGES_DEPS = new Set())).add(
normalizePath(file)
......@@ -85,7 +85,7 @@ module.exports = function (content, map) {
}
})
if (!originalPagesJson.pages || originalPagesJson.pages.length === 0) {
if (!pagesJson.pages || pagesJson.pages.length === 0) {
console.error(uniI18n.__('pagesLoader.pagesNodeCannotNull'))
process.exit(0)
}
......@@ -94,14 +94,13 @@ module.exports = function (content, map) {
const queryParam = loaderUtils.parseQuery(this.resourceQuery)
if (queryParam) {
if (queryParam.type === 'origin-pages-json') {
return `export default ${JSON.stringify(originalPagesJson)}`
return `export default ${JSON.stringify(pagesJson)}`
}
}
}
const platformManifestJson = manifestJson[process.env.UNI_PLATFORM] || {}
const pagesJson = parseTheme(originalPagesJson)
if (global.uniPlugin.defaultTheme) {
this.addDependency(
path.resolve(
......@@ -124,11 +123,16 @@ module.exports = function (content, map) {
process.UNI_TRANSFORM_PX = true
}
if (process.env.VUE_APP_DARK_MODE !== 'true') {
const { pages, globalStyle, tabBar } = parseTheme(pagesJson)
Object.assign(pagesJson, { pages, globalStyle, tabBar })
}
if (process.env.UNI_PLATFORM === 'h5') {
return this.callback(
null,
require('./platforms/h5')(
process.env.VUE_APP_DARK_MODE === 'true' ? originalPagesJson : pagesJson,
pagesJson,
manifestJson,
this
),
......@@ -178,9 +182,7 @@ module.exports = function (content, map) {
}
const jsonFiles = require('./platforms/' + process.env.UNI_PLATFORM)(
process.env.UNI_PLATFORM === 'app-plus' && process.env.VUE_APP_DARK_MODE === 'true'
? originalPagesJson
: pagesJson,
pagesJson,
manifestJson,
isAppView
)
......
......@@ -112,7 +112,7 @@ function updateFileFlag (appJson) {
function _initTheme (appJson, userManifestJson) {
const manifestJson = userManifestJson[process.env.UNI_PLATFORM] || {}
appJson.darkmode = manifestJson.darkmode || false
const themeLocation = manifestJson.themeLocation || ''
const themeLocation = manifestJson.themeLocation || 'theme.json'
if (themeLocation && hasTheme(themeLocation)) {
appJson.themeConfig = getTheme()
}
......
......@@ -12,7 +12,7 @@ export function normalizeTabBarStyles (borderStyle) {
return borderStyle
}
export function normallizeStyles (pageStyle, themeConfig, mode = 'light') {
export function normallizeStyles (pageStyle, themeConfig = {}, mode = 'light') {
const modeStyle = themeConfig[mode]
const styles = {}
if (!modeStyle) {
......@@ -29,7 +29,7 @@ export function normallizeStyles (pageStyle, themeConfig, mode = 'light') {
: item)
} else if (isStr(styleItem) && styleItem.startsWith('@')) {
const _key = styleItem.replace('@', '')
let _styleItem = modeStyle[_key]
let _styleItem = modeStyle[_key] || styleItem
switch (key) {
case 'borderStyle':
_styleItem = normalizeTabBarStyles(_styleItem)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册