34 lines
914 B
TypeScript
34 lines
914 B
TypeScript
/**
|
|
* @title Home Store
|
|
* @description 管理 home 页面的输入框数据和加载状态
|
|
* @tags zustand, state-management, input, loading
|
|
* @createdAt 2025-12-04
|
|
*/
|
|
|
|
import { create } from 'zustand';
|
|
|
|
interface HomeState {
|
|
// 输入框内容
|
|
inputValue: string;
|
|
// 加载状态
|
|
isLoading: boolean;
|
|
|
|
// Actions
|
|
setInputValue: (value: string) => void;
|
|
setLoading: (loading: boolean) => void;
|
|
messages: { role: 'user' | 'assistant'; content: string, key: string }[];
|
|
addMessage: (message: { role: 'user' | 'assistant'; content: string, key: string }) => void;
|
|
}
|
|
|
|
export const useHomeStore = create<HomeState>((set) => ({
|
|
inputValue: '',
|
|
isLoading: false,
|
|
|
|
setInputValue: (value) => set({ inputValue: value }),
|
|
setLoading: (loading) => set({ isLoading: loading }),
|
|
messages: [],
|
|
addMessage: (message) => {
|
|
set((state) => ({ messages: [...state.messages, message] }))
|
|
}
|
|
}));
|