刘光辉
118 分钟以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import type { InjectionKey } from 'vue';
 
import { computed, provide, reactive } from 'vue';
 
export const uploadEditLoadingKey: InjectionKey<() => () => void> = Symbol('upload-edit-loading');
 
/** 每个窗口独立计数;并行附件、过期请求各自释放,不覆盖窗口原有加载状态。 */
export function provideUploadEditLoading() {
  const pending = reactive(new Set<symbol>());
  provide(uploadEditLoadingKey, () => {
    const token = Symbol('attachment-operation');
    pending.add(token);
    return () => {
      pending.delete(token);
    };
  });
  return computed(() => pending.size > 0);
}