Files
autoAiWorkSys/app/mixins/platformMixin.js
张成 e17d5610f5 1
2025-12-22 16:26:59 +08:00

66 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 平台信息管理 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);
}
}
}
};