refactor(frontend): 重构前端第二版
This commit is contained in:
1 parent
2631f78b00
commit
4b562cfa82
205 files changed
+15399
-12015
No files matched your search
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* features/chat/composables/useChatGuides.ts
|
||||
* Agent 学习之窗:指南列表加载与弹窗状态。
|
||||
*/
|
||||
import { computed, ref, type ComputedRef } from 'vue';
|
||||
import { listAgentGuides } from '@/features/auth/api/user.api';
|
||||
|
||||
export interface AgentGuide {
|
||||
id: number;
|
||||
file_name: string;
|
||||
file_type?: string;
|
||||
file_url?: string;
|
||||
file_path?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
export interface UseChatGuidesOptions {
|
||||
currentAgentId: ComputedRef<number>;
|
||||
}
|
||||
|
||||
export function useChatGuides(options: UseChatGuidesOptions) {
|
||||
const { currentAgentId } = options;
|
||||
|
||||
const guides = ref<AgentGuide[]>([]);
|
||||
const showModal = ref(false);
|
||||
const activeGuideId = ref<number | null>(null);
|
||||
const showSidebar = ref(true);
|
||||
|
||||
const activeGuide = computed(() => guides.value.find((g) => g.id === activeGuideId.value));
|
||||
|
||||
const loadGuides = async () => {
|
||||
try {
|
||||
const res = await listAgentGuides(currentAgentId.value || 0);
|
||||
guides.value = Array.isArray(res) ? (res as AgentGuide[]) : [];
|
||||
} catch (error) {
|
||||
console.error('Failed to load agent guides:', error);
|
||||
guides.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const clearGuides = () => {
|
||||
guides.value = [];
|
||||
};
|
||||
|
||||
const openModal = () => {
|
||||
const first = guides.value[0];
|
||||
if (!first) return;
|
||||
activeGuideId.value = first.id;
|
||||
showModal.value = true;
|
||||
showSidebar.value = true;
|
||||
};
|
||||
|
||||
const closeModal = () => {
|
||||
showModal.value = false;
|
||||
};
|
||||
|
||||
return {
|
||||
guides,
|
||||
showModal,
|
||||
activeGuideId,
|
||||
activeGuide,
|
||||
showSidebar,
|
||||
loadGuides,
|
||||
clearGuides,
|
||||
openModal,
|
||||
closeModal,
|
||||
};
|
||||
}
|
||||
|
||||
export type UseChatGuidesReturn = ReturnType<typeof useChatGuides>;
|
||||
Reference in new issue
Block a user