- 新增 safeLocalStorage 工具函数增强本地存储安全性 - 简化认证流程,重构用户数据结构和 token 管理 - 修复多个模块的 TypeScript 类型错误和导入问题 - 优化状态管理,重构各模块 store 结构 - 清理冗余代码,移除未使用的组件和函数 - 改进错误处理和边界情况处理 - 更新配置文件以支持最新的类型检查 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
// 农机设备接口
|
|
export interface Machinery {
|
|
id: string;
|
|
name: string;
|
|
type: string;
|
|
model: string;
|
|
status: 'active' | 'maintenance' | 'inactive' | 'repair';
|
|
license_plate?: string | null;
|
|
purchase_date?: string | null;
|
|
last_maintenance_date?: string | null;
|
|
next_maintenance_date?: string | null;
|
|
operator_id?: string | null;
|
|
location?: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// 驾驶员接口
|
|
export interface Driver {
|
|
id: string;
|
|
name: string;
|
|
phone: string;
|
|
license_number: string;
|
|
license_type: string;
|
|
experience_years?: number | null;
|
|
status: 'active' | 'inactive' | 'on_leave';
|
|
hire_date?: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
// Machinery state interface
|
|
export interface MachineryState {
|
|
machineries: Machinery[];
|
|
currentMachinery: Machinery | null;
|
|
drivers: Driver[];
|
|
currentDriver: Driver | null;
|
|
|
|
// Actions
|
|
setMachineries: (machineries: Machinery[]) => void;
|
|
setCurrentMachinery: (machinery: Machinery | null) => void;
|
|
setDrivers: (drivers: Driver[]) => void;
|
|
setCurrentDriver: (driver: Driver | null) => void;
|
|
|
|
// Getters
|
|
getMachineries: () => Machinery[];
|
|
getCurrentMachinery: () => Machinery | null;
|
|
getDrivers: () => Driver[];
|
|
getCurrentDriver: () => Driver | null;
|
|
}
|
|
|
|
// Create Machinery store
|
|
export const useMachineryStore = create<MachineryState>((set, get) => ({
|
|
machineries: [],
|
|
currentMachinery: null,
|
|
drivers: [],
|
|
currentDriver: null,
|
|
|
|
setMachineries: (machineries: Machinery[]) => {
|
|
set({ machineries });
|
|
},
|
|
|
|
setCurrentMachinery: (machinery: Machinery | null) => {
|
|
set({ currentMachinery: machinery });
|
|
},
|
|
|
|
setDrivers: (drivers: Driver[]) => {
|
|
set({ drivers });
|
|
},
|
|
|
|
setCurrentDriver: (driver: Driver | null) => {
|
|
set({ currentDriver: driver });
|
|
},
|
|
|
|
getMachineries: () => {
|
|
return get().machineries;
|
|
},
|
|
|
|
getCurrentMachinery: () => {
|
|
return get().currentMachinery;
|
|
},
|
|
|
|
getDrivers: () => {
|
|
return get().drivers;
|
|
},
|
|
|
|
getCurrentDriver: () => {
|
|
return get().currentDriver;
|
|
},
|
|
}));
|
|
|
|
export default useMachineryStore; |