use-global-store.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type { GlobalState } from "./pinia.types";
  2. import { defineStore } from "pinia";
  3. import { toRefs, reactive } from "vue";
  4. const useStore = defineStore("globalStore", () => {
  5. const state: GlobalState = reactive({
  6. globalLoading: false,
  7. routerLoading: false,
  8. requestLoading: false,
  9. fullScreenLoading: false,
  10. isPageSwitching: false,
  11. statusBarHeight: 0,
  12. theme: "light"
  13. });
  14. const setGlobalTheme = (payload: string) => {
  15. state.theme = payload;
  16. };
  17. const setBarHeight = (payload: number) => {
  18. state.statusBarHeight = payload;
  19. };
  20. const setGlobalLoading = (payload: boolean) => {
  21. state.globalLoading = payload;
  22. };
  23. const setRouterLoading = (payload: boolean) => {
  24. state.routerLoading = payload;
  25. };
  26. const setRequestLoading = (payload: boolean) => {
  27. state.requestLoading = payload;
  28. };
  29. const setFullScreenLoading = (payload: boolean) => {
  30. state.fullScreenLoading = payload;
  31. };
  32. return {
  33. ...toRefs(state),
  34. setGlobalLoading,
  35. setBarHeight,
  36. setGlobalTheme,
  37. setRouterLoading,
  38. setRequestLoading,
  39. setFullScreenLoading,
  40. };
  41. });
  42. export default useStore; // 导出