fix-theme:
// 修复 uni-app 编译后的 theme.json 文件
// 解决 Unicode 编码和 BOM 问题
const fs = require('fs');
const path = require('path');
// 主题配置(直接在脚本中定义,避免编码问题)
const themeConfig = {
"light": {
"navigationBarTextStyle": "black",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8",
"backgroundTextStyle": "light",
"tabBarColor": "#666666",
"tabBarSelectedColor": "#2a82e4",
"tabBarBackgroundColor": "#ffffff",
"tabBarBorderStyle": "black"
},
"dark": {
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#1a1a1a",
"backgroundColor": "#121212",
"backgroundTextStyle": "dark",
"tabBarColor": "#888888",
"tabBarSelectedColor": "#64b5f6",
"tabBarBackgroundColor": "#1a1a1a",
"tabBarBorderStyle": "white"
}
};
// 目标文件路径
const targetTheme = path.join(__dirname, '../unpackage/dist/dev/mp-weixin/theme.json');
try {
// 检查目标目录是否存在
const targetDir = path.dirname(targetTheme);
if (!fs.existsSync(targetDir)) {
console.error('❌ 目标目录不存在,请先编译项目');
process.exit(1);
}
// 将配置转换为 JSON 字符串(无 BOM,UTF-8)
const themeContent = JSON.stringify(themeConfig, null, 2);
// 写入目标文件(确保无 BOM)
fs.writeFileSync(targetTheme, themeContent, { encoding: 'utf8', flag: 'w' });
console.log('✅ theme.json 已成功修复');
console.log('? 目标文件:', targetTheme);
console.log('? 内容预览:', themeContent.substring(0, 100) + '...');
} catch (error) {
console.error('❌ 修复失败:', error.message);
process.exit(1);
}
1***@qq.com (作者)
{
"light": {
"navigationBarTextStyle": "black",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8",
"backgroundTextStyle": "light",
"tabBarColor": "#666666",
"tabBarSelectedColor": "#2a82e4",
"tabBarBackgroundColor": "#ffffff",
"tabBarBorderStyle": "black"
},
"dark": {
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#1a1a1a",
"backgroundColor": "#121212",
"backgroundTextStyle": "dark",
"tabBarColor": "#888888",
"tabBarSelectedColor": "#64b5f6",
"tabBarBackgroundColor": "#1a1a1a",
"tabBarBorderStyle": "white"
}
}
2025-11-23 16:43
DCloud_UNI_JBB
theme.json也不会进行转化吧,你是什么设备测试的?什么时候遇到的这个问题?
1 分钟前