ZUSTAND_MIGRATION_PLAN.md 2.8 KB

Zustand 迁移计划

📊 当前状态

总 Store 数量: 40 个 MobX store

已迁移: 2 个 ✅

  • src/pages/appCenter/appPlazaList/store.ts
  • src/pages/appCenter/categoryApps/store.ts

待迁移: 38 个 ❌


📋 迁移优先级

P0 - 核心功能(必须迁移)

  1. src/pages/login/store.ts - 登录功能
  2. src/pages/layout/store.ts - 布局状态
  3. src/store/route.tsx - 路由状态
  4. src/store/index.ts - 全局状态

P1 - 主要页面(重要)

  1. src/pages/home/store.ts - 首页统计
  2. src/pages/questionAnswer/info/store.ts - 创建应用
  3. src/pages/knowledgeLib/list/store.ts - 知识库列表
  4. src/pages/knowledgeLib/detail/store.ts - 知识库详情

P2 - 系统管理(次要)

  1. src/pages/system/audit/store.ts - 应用审核
  2. src/pages/system/apiKey/store.ts - API 管理
  3. src/pages/system/usageStatistics/store.ts - 用量统计
  4. src/pages/system/contentManagement/store.ts - 内容管理

P3 - 其他功能(可选)

13-40. 其他 DeepSeek 相关 store...


🎯 迁移步骤

步骤 1:迁移登录 Store(P0)

  • 文件:src/pages/login/store.ts
  • 功能:登录、验证码
  • 预估时间:15 分钟

步骤 2:迁移布局 Store(P0)

  • 文件:src/pages/layout/store.ts
  • 功能:菜单展开/收起、面包屑
  • 预估时间:20 分钟

步骤 3:迁移路由 Store(P0)

  • 文件:src/store/route.tsx
  • 功能:路由配置、菜单生成
  • 预估时间:30 分钟

步骤 4:迁移首页 Store(P1)

  • 文件:src/pages/home/store.ts
  • 功能:统计数据、图表
  • 预估时间:20 分钟

步骤 5:迁移其他 Store(P1-P3)

  • 按优先级逐个迁移
  • 每个约 15-20 分钟

📈 迁移进度

优先级 数量 已完成 进度
P0 4 0 0%
P1 4 0 0%
P2 4 0 0%
P3 26 0 0%
总计 38 0 0%

💡 迁移模板

MobX(旧)

import { makeAutoObservable } from 'mobx';

const stateGenerator = () => ({
    loading: false,
    data: null,
});

const stateActionsGenerator = (state: any) => ({
    setLoading: (loading) => {
        state.loading = loading;
    },
});

const useStore = () => {
    const state = makeAutoObservable(stateGenerator());
    const actions = stateActionsGenerator(state);
    return { state, ...actions };
};

Zustand(新)

import { create } from 'zustand';

interface State {
    loading: boolean;
    data: any;
}

interface Actions {
    setLoading: (loading: boolean) => void;
}

export const useStore = create<State & Actions>((set) => ({
    loading: false,
    data: null,
    setLoading: (loading) => set({ loading }),
}));

下一步: 开始迁移 P0 核心功能 Store