refactor(ai): optimize AI action initialization and user state handling

This commit is contained in:
Ray.Hao
2025-11-18 00:18:25 +08:00
parent 0fbd489e49
commit 0ce931ee39
5 changed files with 103 additions and 124 deletions

View File

@@ -16,23 +16,24 @@
</template>
<script setup lang="ts">
import { useAppStore, useSettingsStore } from "@/store";
import { useAppStore, useSettingsStore, useUserStore } from "@/store";
import { defaultSettings } from "@/settings";
import { ThemeMode, ComponentSize } from "@/enums";
import AiAssistant from "@/components/AiAssistant/index.vue";
import { AuthStorage } from "@/utils/auth";
const appStore = useAppStore();
const settingsStore = useSettingsStore();
const userStore = useUserStore();
const locale = computed(() => appStore.locale);
const size = computed(() => appStore.size as ComponentSize);
const showWatermark = computed(() => settingsStore.showWatermark);
// 只有在启用 AI 助手且用户已登录时才显示
// 使用 userInfo 作为响应式依赖,当用户退出登录时会自动更新
const enableAiAssistant = computed(() => {
const isEnabled = settingsStore.enableAiAssistant;
const isLoggedIn = !!AuthStorage.getAccessToken();
const isLoggedIn = userStore.userInfo && Object.keys(userStore.userInfo).length > 0;
return isEnabled && isLoggedIn;
});