temp
This commit is contained in:
33
src/pages/home/store.ts
Normal file
33
src/pages/home/store.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @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] }))
|
||||
}
|
||||
}));
|
||||
Reference in New Issue
Block a user