| | |
| | | // 加载状态的逻辑管理 |
| | | |
| | | 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 = []; |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | }); |