refactor: 优化认证系统和组件类型安全性
- 新增 safeLocalStorage 工具函数增强本地存储安全性 - 简化认证流程,重构用户数据结构和 token 管理 - 修复多个模块的 TypeScript 类型错误和导入问题 - 优化状态管理,重构各模块 store 结构 - 清理冗余代码,移除未使用的组件和函数 - 改进错误处理和边界情况处理 - 更新配置文件以支持最新的类型检查 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* 规范:遵循crop-x/docs/开发项目规范.md,使用useReducer状态管理模式
|
||||
*/
|
||||
|
||||
import { safeLocalStorage } from '@/utils/storage';
|
||||
|
||||
// 决策类型
|
||||
export type DecisionType = 'irrigation' | 'fertilizer' | 'pesticide' | 'harvest' | 'soil' | 'weather';
|
||||
|
||||
@@ -303,29 +305,25 @@ const calculateLatestDecisions = (decisions: DecisionRecord[]): DecisionRecord[]
|
||||
|
||||
// 保存到本地存储
|
||||
const saveToStorage = (state: AIDecisionDashboardState) => {
|
||||
try {
|
||||
localStorage.setItem('ai-decision-dashboard', JSON.stringify({
|
||||
decisions: state.decisions,
|
||||
lastUpdated: state.lastUpdated,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.warn('Failed to save to localStorage:', error);
|
||||
}
|
||||
safeLocalStorage.setItem('ai-decision-dashboard', JSON.stringify({
|
||||
decisions: state.decisions,
|
||||
lastUpdated: state.lastUpdated,
|
||||
}));
|
||||
};
|
||||
|
||||
// 从本地存储加载
|
||||
const loadFromStorage = () => {
|
||||
try {
|
||||
const stored = localStorage.getItem('ai-decision-dashboard');
|
||||
if (stored) {
|
||||
const stored = safeLocalStorage.getItem('ai-decision-dashboard');
|
||||
if (stored) {
|
||||
try {
|
||||
const data = JSON.parse(stored);
|
||||
return {
|
||||
decisions: data.decisions || initialDecisions,
|
||||
lastUpdated: data.lastUpdated || new Date().toISOString(),
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse stored data:', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load from localStorage:', error);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user