import { makeAutoObservable } from 'mobx'; import { apis } from '@/apis'; import { State, ReadonlyState, StateAction, WorkbenchStore } from './types'; // 定义状态 const stateGenerator = (): ReadonlyState => ({ pageLoading: false, }); // 修改状态 const stateActionsGenerator = (state: State): StateAction => { return { setPageLoading: (loading) => { state.pageLoading = loading; }, }; }; // 使用仓库 const useWorkbenchStore = (): WorkbenchStore => { const state = makeAutoObservable(stateGenerator()); const actions = stateActionsGenerator(state); const api = { } // 初始渲染 const init = () => { } // 状态重置 const reset = () => { const initialPageLoading = stateGenerator().pageLoading; actions.setPageLoading(initialPageLoading); } return { state, init, reset }; }; export default useWorkbenchStore();