store.ts 963 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { makeAutoObservable } from 'mobx';
  2. import { apis } from '@/apis';
  3. import { State, ReadonlyState, StateAction, WorkbenchStore } from './types';
  4. // 定义状态
  5. const stateGenerator = (): ReadonlyState => ({
  6. pageLoading: false,
  7. });
  8. // 修改状态
  9. const stateActionsGenerator = (state: State): StateAction => {
  10. return {
  11. setPageLoading: (loading) => {
  12. state.pageLoading = loading;
  13. },
  14. };
  15. };
  16. // 使用仓库
  17. const useWorkbenchStore = (): WorkbenchStore => {
  18. const state = makeAutoObservable(stateGenerator());
  19. const actions = stateActionsGenerator(state);
  20. const api = {
  21. }
  22. // 初始渲染
  23. const init = () => {
  24. }
  25. // 状态重置
  26. const reset = () => {
  27. const initialPageLoading = stateGenerator().pageLoading;
  28. actions.setPageLoading(initialPageLoading);
  29. }
  30. return {
  31. state,
  32. init,
  33. reset
  34. };
  35. };
  36. export default useWorkbenchStore();