| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import type { GlobalState } from "./pinia.types";
- import { defineStore } from "pinia";
- import ls from "@/utils/store2";
- import { toRefs, reactive } from "vue";
- const useStore = defineStore("globalStore", () => {
- const state: GlobalState = reactive({
- globalLoading: false,
- routerLoading: false,
- requestLoading: false,
- fullScreenLoading: false,
- isPageSwitching: false,
- statusBarHeight: 0,
- mode: 'customer',
- theme: "light"
- });
- const setGlobalTheme = (payload: string) => {
- state.theme = payload;
- };
- const initMode = () => {
- const encryptedMode = ls.get('mode');
- state.mode = encryptedMode || 'customer';
- };
- const setMode = (payload: 'customer' | 'ib') => {
- ls.set('mode', payload)
- state.mode = payload;
- };
- const setBarHeight = (payload: number) => {
- state.statusBarHeight = payload;
- };
- const setGlobalLoading = (payload: boolean) => {
- state.globalLoading = payload;
- };
- const setRouterLoading = (payload: boolean) => {
- state.routerLoading = payload;
- };
- const setRequestLoading = (payload: boolean) => {
- state.requestLoading = payload;
- };
- const setFullScreenLoading = (payload: boolean) => {
- state.fullScreenLoading = payload;
- };
- initMode()
- return {
- ...toRefs(state),
- setGlobalLoading,
- setMode,
- setBarHeight,
- setGlobalTheme,
- setRouterLoading,
- setRequestLoading,
- setFullScreenLoading,
- };
- });
- export default useStore; // 导出
|