diff --git a/miniprogram/assets/icons/sparkles.svg b/miniprogram/assets/icons/sparkles.svg
index a3b9133c..e2a4461f 100644
--- a/miniprogram/assets/icons/sparkles.svg
+++ b/miniprogram/assets/icons/sparkles.svg
@@ -1,4 +1,6 @@
diff --git a/miniprogram/custom-tab-bar/index.js b/miniprogram/custom-tab-bar/index.js
index 01e98621..2ccba866 100644
--- a/miniprogram/custom-tab-bar/index.js
+++ b/miniprogram/custom-tab-bar/index.js
@@ -3,7 +3,10 @@
* 根据后台配置动态显示/隐藏"找伙伴"按钮
*/
+console.log('[TabBar] ===== 组件文件开始加载 =====')
+
const app = getApp()
+console.log('[TabBar] App 对象:', app)
Component({
data: {
@@ -38,37 +41,73 @@ Component({
lifetimes: {
attached() {
+ console.log('[TabBar] Component attached 生命周期触发')
this.loadFeatureConfig()
+ },
+ ready() {
+ console.log('[TabBar] Component ready 生命周期触发')
+ // 如果 attached 中没有成功加载,在 ready 中再次尝试
+ if (this.data.matchEnabled === undefined || this.data.matchEnabled === null) {
+ console.log('[TabBar] 在 ready 中重新加载配置')
+ this.loadFeatureConfig()
+ }
}
},
+
+ // 页面加载时也调用(兼容性更好)
+ attached() {
+ console.log('[TabBar] attached() 方法触发')
+ this.loadFeatureConfig()
+ },
methods: {
// 加载功能配置
async loadFeatureConfig() {
try {
- const res = await app.request({
- url: '/api/db/config',
+ console.log('[TabBar] 开始加载功能配置...')
+ console.log('[TabBar] API地址:', app.globalData.baseUrl + '/api/db/config')
+
+ // app.request 的第一个参数是 url 字符串,第二个参数是 options 对象
+ const res = await app.request('/api/db/config', {
method: 'GET'
})
- if (res && res.features) {
- const matchEnabled = res.features.matchEnabled === true
- this.setData({ matchEnabled }, () => {
- // 配置加载完成后,根据当前路由设置选中状态
- this.updateSelected()
- })
-
- // 如果当前在找伙伴页面,但功能已关闭,跳转到首页
- if (!matchEnabled) {
- const pages = getCurrentPages()
- const currentPage = pages[pages.length - 1]
- if (currentPage && currentPage.route === 'pages/match/match') {
- wx.switchTab({ url: '/pages/index/index' })
- }
+
+ // 兼容两种返回格式
+ let matchEnabled = false
+
+ if (res && res.success && res.features) {
+ console.log('[TabBar] features配置:', JSON.stringify(res.features))
+ matchEnabled = res.features.matchEnabled === true
+ console.log('[TabBar] matchEnabled值:', matchEnabled)
+ } else if (res && res.configs && res.configs.feature_config) {
+ // 备用格式:从 configs.feature_config 读取
+ console.log('[TabBar] 使用备用格式,从configs读取')
+ matchEnabled = res.configs.feature_config.matchEnabled === true
+ console.log('[TabBar] matchEnabled值:', matchEnabled)
+ } else {
+ console.log('[TabBar] ⚠️ 未找到features配置,使用默认值false')
+ console.log('[TabBar] res对象keys:', Object.keys(res || {}))
+ }
+
+ this.setData({ matchEnabled }, () => {
+ console.log('[TabBar] ✅ matchEnabled已设置为:', this.data.matchEnabled)
+ // 配置加载完成后,根据当前路由设置选中状态
+ this.updateSelected()
+ })
+
+ // 如果当前在找伙伴页面,但功能已关闭,跳转到首页
+ if (!matchEnabled) {
+ const pages = getCurrentPages()
+ const currentPage = pages[pages.length - 1]
+ if (currentPage && currentPage.route === 'pages/match/match') {
+ console.log('[TabBar] 找伙伴功能已关闭,从match页面跳转到首页')
+ wx.switchTab({ url: '/pages/index/index' })
}
}
} catch (error) {
- console.log('TabBar加载功能配置失败:', error)
+ console.log('[TabBar] ❌ 加载功能配置失败:', error)
+ console.log('[TabBar] 错误详情:', error.message || error)
// 默认关闭找伙伴功能
this.setData({ matchEnabled: false }, () => {
this.updateSelected()
diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js
index aa78390b..4e9570f6 100644
--- a/miniprogram/pages/index/index.js
+++ b/miniprogram/pages/index/index.js
@@ -4,6 +4,8 @@
* 技术支持: 存客宝
*/
+console.log('[Index] ===== 首页文件开始加载 =====')
+
const app = getApp()
Page({
@@ -46,6 +48,8 @@ Page({
},
onLoad(options) {
+ console.log('[Index] ===== onLoad 触发 =====')
+
// 获取系统信息
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
@@ -63,14 +67,27 @@ Page({
},
onShow() {
+ console.log('[Index] onShow 触发')
+
// 设置TabBar选中状态
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
const tabBar = this.getTabBar()
- if (tabBar.updateSelected) {
+ console.log('[Index] TabBar 组件:', tabBar ? '已找到' : '未找到')
+
+ // 主动触发配置加载
+ if (tabBar && tabBar.loadFeatureConfig) {
+ console.log('[Index] 主动调用 TabBar.loadFeatureConfig()')
+ tabBar.loadFeatureConfig()
+ }
+
+ // 更新选中状态
+ if (tabBar && tabBar.updateSelected) {
tabBar.updateSelected()
- } else {
+ } else if (tabBar) {
tabBar.setData({ selected: 0 })
}
+ } else {
+ console.log('[Index] TabBar 组件未找到或 getTabBar 方法不存在')
}
// 更新用户状态
diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml
index fdfaf704..523fe6a9 100644
--- a/miniprogram/pages/index/index.wxml
+++ b/miniprogram/pages/index/index.wxml
@@ -5,7 +5,7 @@
-