- 新增 safeLocalStorage 工具函数增强本地存储安全性 - 简化认证流程,重构用户数据结构和 token 管理 - 修复多个模块的 TypeScript 类型错误和导入问题 - 优化状态管理,重构各模块 store 结构 - 清理冗余代码,移除未使用的组件和函数 - 改进错误处理和边界情况处理 - 更新配置文件以支持最新的类型检查 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
130 lines
3.3 KiB
TypeScript
130 lines
3.3 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
// 灌溉系统接口
|
|
export interface IrrigationSystem {
|
|
id: string;
|
|
name: string;
|
|
type: string;
|
|
status: 'active' | 'inactive' | 'maintenance';
|
|
location: string;
|
|
capacity: number;
|
|
flow_rate: number;
|
|
installation_date?: string | null;
|
|
last_maintenance_date?: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// 灌溉区域接口
|
|
export interface IrrigationZone {
|
|
id: string;
|
|
name: string;
|
|
system_id: string;
|
|
area: number;
|
|
crop_type: string;
|
|
soil_moisture_threshold: number;
|
|
irrigation_duration: number;
|
|
status: 'active' | 'inactive';
|
|
coordinates?: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// 灌溉调度接口
|
|
export interface IrrigationSchedule {
|
|
id: string;
|
|
zone_id: string;
|
|
start_time: string;
|
|
duration: number;
|
|
frequency: string;
|
|
water_amount: number;
|
|
status: 'pending' | 'active' | 'completed' | 'cancelled';
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// Irrigation state interface
|
|
export interface IrrigationState {
|
|
irrigationSystems: IrrigationSystem[];
|
|
currentSystem: IrrigationSystem | null;
|
|
irrigationZones: IrrigationZone[];
|
|
currentZone: IrrigationZone | null;
|
|
irrigationSchedules: IrrigationSchedule[];
|
|
currentSchedule: IrrigationSchedule | null;
|
|
|
|
// Actions
|
|
setIrrigationSystems: (systems: IrrigationSystem[]) => void;
|
|
setCurrentSystem: (system: IrrigationSystem | null) => void;
|
|
setIrrigationZones: (zones: IrrigationZone[]) => void;
|
|
setCurrentZone: (zone: IrrigationZone | null) => void;
|
|
setIrrigationSchedules: (schedules: IrrigationSchedule[]) => void;
|
|
setCurrentSchedule: (schedule: IrrigationSchedule | null) => void;
|
|
|
|
// Getters
|
|
getIrrigationSystems: () => IrrigationSystem[];
|
|
getCurrentSystem: () => IrrigationSystem | null;
|
|
getIrrigationZones: () => IrrigationZone[];
|
|
getCurrentZone: () => IrrigationZone | null;
|
|
getIrrigationSchedules: () => IrrigationSchedule[];
|
|
getCurrentSchedule: () => IrrigationSchedule | null;
|
|
}
|
|
|
|
// Create Irrigation store
|
|
export const useIrrigationStore = create<IrrigationState>((set, get) => ({
|
|
irrigationSystems: [],
|
|
currentSystem: null,
|
|
irrigationZones: [],
|
|
currentZone: null,
|
|
irrigationSchedules: [],
|
|
currentSchedule: null,
|
|
|
|
setIrrigationSystems: (systems: IrrigationSystem[]) => {
|
|
set({ irrigationSystems: systems });
|
|
},
|
|
|
|
setCurrentSystem: (system: IrrigationSystem | null) => {
|
|
set({ currentSystem: system });
|
|
},
|
|
|
|
setIrrigationZones: (zones: IrrigationZone[]) => {
|
|
set({ irrigationZones: zones });
|
|
},
|
|
|
|
setCurrentZone: (zone: IrrigationZone | null) => {
|
|
set({ currentZone: zone });
|
|
},
|
|
|
|
setIrrigationSchedules: (schedules: IrrigationSchedule[]) => {
|
|
set({ irrigationSchedules: schedules });
|
|
},
|
|
|
|
setCurrentSchedule: (schedule: IrrigationSchedule | null) => {
|
|
set({ currentSchedule: schedule });
|
|
},
|
|
|
|
getIrrigationSystems: () => {
|
|
return get().irrigationSystems;
|
|
},
|
|
|
|
getCurrentSystem: () => {
|
|
return get().currentSystem;
|
|
},
|
|
|
|
getIrrigationZones: () => {
|
|
return get().irrigationZones;
|
|
},
|
|
|
|
getCurrentZone: () => {
|
|
return get().currentZone;
|
|
},
|
|
|
|
getIrrigationSchedules: () => {
|
|
return get().irrigationSchedules;
|
|
},
|
|
|
|
getCurrentSchedule: () => {
|
|
return get().currentSchedule;
|
|
},
|
|
}));
|
|
|
|
export default useIrrigationStore; |