| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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();
|