| | |
| | | import { getUnreadCount } from '@/api/message' |
| | | import storage from '@/utils/storage' |
| | | import { redirectToLoginByEnvironment } from '@/utils/wechat' |
| | | import { getAppFeatures } from '@/api/appConfig' |
| | | |
| | | export default { |
| | | data() { |
| | |
| | | this.lastToken = token |
| | | this.updateUnreadMessageBadge() |
| | | // this.startMessagePolling() |
| | | // 加载服务器配置 |
| | | this.loadServerConfig() |
| | | } |
| | | }) |
| | | |
| | |
| | | // 注意:不在应用启动时自动启动轮询 |
| | | // 只有在用户主动登录成功后才启动(通过 user-login 事件触发) |
| | | }, |
| | | |
| | | // 初始化配置:合并本地配置和服务器配置 |
| | | initConfig() { |
| | | // 先使用本地默认配置 |
| | | this.globalData.config = config |
| | | |
| | | // 如果用户已登录,尝试加载服务器配置 |
| | | if (getToken()) { |
| | | this.loadServerConfig() |
| | | } else { |
| | | console.log('用户未登录,使用本地默认配置') |
| | | } |
| | | }, |
| | | |
| | | // 从服务器加载配置 |
| | | loadServerConfig() { |
| | | getAppFeatures().then(response => { |
| | | console.log('加载服务器配置成功:', response.data) |
| | | // 合并配置:服务器配置覆盖本地配置 |
| | | if (response.data) { |
| | | this.globalData.config.features = Object.assign({}, |
| | | this.globalData.config.features || {}, |
| | | response.data |
| | | ) |
| | | // 更新全局config对象,确保其他地方也能获取到最新配置 |
| | | config.features = this.globalData.config.features |
| | | } |
| | | }).catch(error => { |
| | | console.error('加载服务器配置失败:', error) |
| | | console.log('使用本地默认配置') |
| | | }) |
| | | }, |
| | | // 检查登录状态并自动跳转到合适的登录页面 |
| | | checkLoginAndRedirect(options) { |