File size: 2,343 Bytes
dde4052 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | import { create } from 'zustand'
import type { TraderConfigData } from '../types'
interface TradersModalState {
// Modal 显示状态
showCreateModal: boolean
showEditModal: boolean
showModelModal: boolean
showExchangeModal: boolean
showSignalSourceModal: boolean
// 编辑状态
editingModel: string | null
editingExchange: string | null
editingTrader: TraderConfigData | null
// Actions
setShowCreateModal: (show: boolean) => void
setShowEditModal: (show: boolean) => void
setShowModelModal: (show: boolean) => void
setShowExchangeModal: (show: boolean) => void
setShowSignalSourceModal: (show: boolean) => void
setEditingModel: (modelId: string | null) => void
setEditingExchange: (exchangeId: string | null) => void
setEditingTrader: (trader: TraderConfigData | null) => void
// 便捷方法
openModelModal: (modelId?: string) => void
closeModelModal: () => void
openExchangeModal: (exchangeId?: string) => void
closeExchangeModal: () => void
// 重置
reset: () => void
}
const initialState = {
showCreateModal: false,
showEditModal: false,
showModelModal: false,
showExchangeModal: false,
showSignalSourceModal: false,
editingModel: null,
editingExchange: null,
editingTrader: null,
}
export const useTradersModalStore = create<TradersModalState>((set) => ({
...initialState,
setShowCreateModal: (show) => set({ showCreateModal: show }),
setShowEditModal: (show) => set({ showEditModal: show }),
setShowModelModal: (show) => set({ showModelModal: show }),
setShowExchangeModal: (show) => set({ showExchangeModal: show }),
setShowSignalSourceModal: (show) => set({ showSignalSourceModal: show }),
setEditingModel: (modelId) => set({ editingModel: modelId }),
setEditingExchange: (exchangeId) => set({ editingExchange: exchangeId }),
setEditingTrader: (trader) => set({ editingTrader: trader }),
openModelModal: (modelId) => {
set({ editingModel: modelId || null, showModelModal: true })
},
closeModelModal: () => {
set({ showModelModal: false, editingModel: null })
},
openExchangeModal: (exchangeId) => {
set({ editingExchange: exchangeId || null, showExchangeModal: true })
},
closeExchangeModal: () => {
set({ showExchangeModal: false, editingExchange: null })
},
reset: () => set(initialState),
}))
|