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

fix: darkmode easycom question/156809

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