init
This commit is contained in:
79
config/plugins/fix-tabbar-list.js
Normal file
79
config/plugins/fix-tabbar-list.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Taro 插件:修复 tabBar.list
|
||||
* 确保即使使用自定义 tabBar,也保留 list 配置
|
||||
*/
|
||||
module.exports = (ctx) => {
|
||||
return {
|
||||
name: 'fix-tabbar-list',
|
||||
// 修改 app 配置
|
||||
modifyAppConfig(config) {
|
||||
// 确保 tabBar.list 存在
|
||||
if (config.tabBar && !config.tabBar.list) {
|
||||
config.tabBar.list = [
|
||||
{
|
||||
pagePath: 'pages/home/index',
|
||||
text: '首页',
|
||||
iconPath: 'assets/tabbar/home.png',
|
||||
selectedIconPath: 'assets/tabbar/home-active.png'
|
||||
},
|
||||
{
|
||||
pagePath: 'pages/check/index',
|
||||
text: '质检',
|
||||
iconPath: 'assets/tabbar/check.png',
|
||||
selectedIconPath: 'assets/tabbar/check-active.png'
|
||||
},
|
||||
{
|
||||
pagePath: 'pages/personnel/index',
|
||||
text: '人员',
|
||||
iconPath: 'assets/tabbar/personnel.png',
|
||||
selectedIconPath: 'assets/tabbar/personnel-active.png'
|
||||
}
|
||||
]
|
||||
}
|
||||
return config
|
||||
},
|
||||
// 编译完成后再次检查(双重保险)
|
||||
onBuildFinish() {
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const appJsonPath = path.join(ctx.paths.outputPath, 'app.json')
|
||||
|
||||
if (fs.existsSync(appJsonPath)) {
|
||||
try {
|
||||
const appJson = JSON.parse(fs.readFileSync(appJsonPath, 'utf8'))
|
||||
|
||||
// 如果 tabBar 存在但没有 list,添加 list
|
||||
if (appJson.tabBar && !appJson.tabBar.list) {
|
||||
appJson.tabBar.list = [
|
||||
{
|
||||
pagePath: 'pages/home/index',
|
||||
text: '首页',
|
||||
iconPath: 'assets/tabbar/home.png',
|
||||
selectedIconPath: 'assets/tabbar/home-active.png'
|
||||
},
|
||||
{
|
||||
pagePath: 'pages/check/index',
|
||||
text: '质检',
|
||||
iconPath: 'assets/tabbar/check.png',
|
||||
selectedIconPath: 'assets/tabbar/check-active.png'
|
||||
},
|
||||
{
|
||||
pagePath: 'pages/personnel/index',
|
||||
text: '人员',
|
||||
iconPath: 'assets/tabbar/personnel.png',
|
||||
selectedIconPath: 'assets/tabbar/personnel-active.png'
|
||||
}
|
||||
]
|
||||
|
||||
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2), 'utf8')
|
||||
console.log('✅ [fix-tabbar-list] 已修复 dist/app.json 中的 tabBar.list')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ [fix-tabbar-list] 修复失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user