mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 07:33:53 +08:00
fix: 修复刷新页面菜单、页脚闪动的问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//功能配置工具
|
||||
import Api from "@/apis/api";
|
||||
import store from "@/store";
|
||||
|
||||
class FeatureManager {
|
||||
constructor() {
|
||||
@@ -72,7 +73,13 @@ class FeatureManager {
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新config缓存
|
||||
*/
|
||||
updateConfigCache(config) {
|
||||
store.commit('setPubConfig', config);
|
||||
localStorage.setItem('pubConfig', JSON.stringify(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从pub-config接口获取配置
|
||||
@@ -85,6 +92,7 @@ class FeatureManager {
|
||||
if (result && result.status === 200) {
|
||||
// 检查是否有data字段
|
||||
if (result.data) {
|
||||
const configCache = result.data.data || {};
|
||||
// 检查是否有code字段,如果有则按照code判断
|
||||
if (result.data.code !== undefined) {
|
||||
if (result.data.code === 0 && result.data.data && result.data.data.systemWebMenu) {
|
||||
@@ -110,6 +118,7 @@ class FeatureManager {
|
||||
console.warn('配置中缺少features对象,使用默认配置');
|
||||
resolve(this.defaultFeatures);
|
||||
}
|
||||
configCache.systemWebMenu = config;
|
||||
} catch (error) {
|
||||
console.warn('处理systemWebMenu配置失败:', error);
|
||||
resolve(null);
|
||||
@@ -143,6 +152,7 @@ class FeatureManager {
|
||||
console.warn('配置中缺少features对象,使用默认配置');
|
||||
resolve(this.defaultFeatures);
|
||||
}
|
||||
configCache.systemWebMenu = config;
|
||||
} catch (error) {
|
||||
console.warn('处理systemWebMenu配置失败:', error);
|
||||
resolve(null);
|
||||
@@ -152,6 +162,7 @@ class FeatureManager {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
this.updateConfigCache(configCache)
|
||||
} else {
|
||||
console.warn('接口返回数据中缺少data字段,使用默认配置');
|
||||
resolve(null);
|
||||
@@ -183,6 +194,8 @@ class FeatureManager {
|
||||
// 异步保存到后端API
|
||||
this.saveConfigToAPI(config).catch(error => {
|
||||
console.warn('保存配置到API失败:', error);
|
||||
}).finally(() => {
|
||||
this.init()
|
||||
});
|
||||
|
||||
// 触发配置变更事件
|
||||
|
||||
Reference in New Issue
Block a user