This commit is contained in:
张成
2025-12-22 16:26:59 +08:00
parent aa2d03ee30
commit e17d5610f5
54 changed files with 11735 additions and 3 deletions

View File

@@ -0,0 +1,65 @@
/**
* 平台信息管理 Mixin
*/
export default {
computed: {
currentPlatform() {
return this.$store ? this.$store.state.platform.currentPlatform : '-';
},
platformLoginStatus() {
return this.$store ? this.$store.state.platform.platformLoginStatus : '-';
},
platformLoginStatusColor() {
return this.$store ? this.$store.state.platform.platformLoginStatusColor : '#FF9800';
},
isPlatformLoggedIn() {
return this.$store ? this.$store.state.platform.isPlatformLoggedIn : false;
}
},
methods: {
// 接收主进程推送的平台登录状态(不做处理,直接更新 store
onPlatformLoginStatusUpdated(data) {
console.log('[PlatformMixin] 收到平台登录状态更新:', data);
if (this.$store && data) {
// 直接使用主进程提供的格式化数据
if (data.platform !== undefined) {
this.$store.dispatch('platform/updatePlatform', data.platform);
}
// 修复:确保正确处理 isLoggedIn 状态
const isLoggedIn = data.isLoggedIn !== undefined ? data.isLoggedIn : false;
this.$store.dispatch('platform/updatePlatformLoginStatus', {
status: data.status || (isLoggedIn ? '已登录' : '未登录'),
color: data.color || (isLoggedIn ? '#4CAF50' : '#FF9800'),
isLoggedIn: isLoggedIn
});
}
},
/**
* 主动检查平台登录状态
* 调用主进程接口检查状态,主进程会自动更新并通知前端
*/
async checkPlatformLoginStatus() {
if (!window.electronAPI || !window.electronAPI.invoke) {
console.warn('[PlatformMixin] electronAPI 不可用,无法检查平台登录状态');
return;
}
try {
const result = await window.electronAPI.invoke('auth:platform-login-status');
if (result && result.success) {
// 主进程已经通过 platform:login-status-updated 事件通知前端了
// 这里不需要再次更新 store因为事件处理已经更新了
console.log('[PlatformMixin] 平台登录状态检查完成:', {
platform: result.platformType,
isLoggedIn: result.isLoggedIn
});
}
} catch (error) {
console.error('[PlatformMixin] 检查平台登录状态失败:', error);
}
}
}
};