1
This commit is contained in:
65
app/mixins/platformMixin.js
Normal file
65
app/mixins/platformMixin.js
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user