首页 > 其他分享 >showDirectoryPicker

showDirectoryPicker

时间:2023-06-13 13:55:06浏览次数:36  
标签:files const showDirectoryPicker result reader id fileItem

import axios from "axios";
import qs from "qs"

const show = async function () {
  const result = [];
  const files = await showDirectoryPicker();
  console.log(files);
  const iterator = files.entries();
  let fileItem = null;
  let i = 0;

  while (true) {
    fileItem = await iterator.next();
    if (!fileItem || fileItem.done) {
      break;
    }
    const file = fileItem.value[1];
    const reader = new FileReader();
    reader.readAsText(await file.getFile());
    reader.onload = () => {
      const id = file.name.split('.')[0];
      // 处理
      axios.post("http://127.0.0.1:2000/svgToSymbol", qs.stringify({
        id: id,
        content: reader.result
      }), {
        headers: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        timeout: 600
      }).then(res => {
        result.push({
          id: id,
          label: id,
          content: res.data.data,
        });
      });

    }

  }

  setTimeout(() => {
    console.log(result.sort((a, b) => a.id > b.id ? 1 : -1));
  }, 5000);
};

标签:files,const,showDirectoryPicker,result,reader,id,fileItem
From: https://www.cnblogs.com/zhuxiang1633/p/17477310.html

相关文章