export default (function (obj) {
  var body = document.getElementsByTagName('body')[0];
  var imgUploadInput = document.createElement('input');
  imgUploadInput.type = 'file';
  imgUploadInput.multiple = obj === null || obj === void 0 ? void 0 : obj.multiple;
  imgUploadInput.style.height = '0';
  body.appendChild(imgUploadInput);

  imgUploadInput.onclick = function (e) {// body.removeChild(imgUploadInput as HTMLInputElement);
  };

  imgUploadInput.onchange = function (e) {
    var files = e.target.files;

    if ((obj === null || obj === void 0 ? void 0 : obj.multiple) && files.length > obj.count) {
      console.log('选择数量超过最大数量');
      return;
    }

    var filesTask = [];

    var _loop = function _loop(i) {
      var fileTask = new Promise(function (resolve, reject) {
        var file = files[i];
        var reader = new FileReader();

        reader.onload = function (evt) {
          resolve(evt.target.result);
        };

        reader.readAsDataURL(file);
      });
      filesTask.push(fileTask);
    };

    for (var i = 0; i < files.length; i += 1) {
      _loop(i);
    }

    Promise.all(filesTask).then(function (result) {
      var params = {
        filePaths: result
      };
      obj === null || obj === void 0 ? void 0 : obj.success(params);
    }).catch(function (error) {
      console.error('Read file error', error);
    });
    body.removeChild(imgUploadInput);
  };

  imgUploadInput.click();
});