context.js 869 B

12345678910111213141516171819202122
  1. import { jsx as _jsx } from "react/jsx-runtime";
  2. import { createContext, useRef, useState } from 'react';
  3. export const DageUploadContext = createContext(null);
  4. export const DageUploadConsumer = DageUploadContext.Consumer;
  5. export const DageUploadProvider = (props) => {
  6. /** 待上传文件数量 */
  7. const uploadingFileNum = useRef(0);
  8. const [uploading, setUploading] = useState(false);
  9. const handleUploadingFileNum = (type) => {
  10. if (type === 'add') {
  11. uploadingFileNum.current += 1;
  12. setUploading(true);
  13. }
  14. else {
  15. uploadingFileNum.current -= 1;
  16. if (uploading && !uploadingFileNum.current) {
  17. setUploading(false);
  18. }
  19. }
  20. };
  21. return (_jsx(DageUploadContext.Provider, { value: { uploading, handleUploadingFileNum }, children: props.children }));
  22. };