riku
2025-09-17 4aa86b1ec441c4e358e1cc488d8f021fb80f1355
src/stores/loadingStore.js
@@ -1,23 +1,26 @@
// 加载状态的逻辑管理
import { defineStore } from 'pinia'
import { defineStore } from 'pinia';
export const useLoadingStore = defineStore('loading', {
  state: () => {
    return {
      loadingStatus: []
    }
    };
  },
  actions: {
    pushLoading(func) {
      const timeout = setTimeout(func, 3000);
      this.loadingStatus.push({ t: timeout, f: func });
    },
    clearLoading() {
      this.loadingStatus.forEach(l => {
        if (typeof l === 'function') {
          l()
        }
      });
      if (this.loadingStatus.length > 0) {
        this.loadingStatus = []
        this.loadingStatus.forEach((obj) => {
          clearTimeout(obj.t)
          obj.f()
        });
        this.loadingStatus = [];
      }
    }
  }
})
});