Ejemplo n.º 1
0
 }, () => {
   let pathArr = [];
   let fileNameMap = {};
   for (let file of this.state.fileList) {
     if (util.string.isEmpty(file.url)) continue;
     pathArr.push(file.url);
     fileNameMap[file.url] = file.name;
   }
   this.setState({
     fileNameMap: fileNameMap
   }, () => {
     let strPath = pathArr.join();
     if (!util.string.isEmpty(strPath) && this.props.value !== strPath) {
       this.props.onChange && this.props.onChange(strPath)
     }
   });
 });
Ejemplo n.º 2
0
  initFileFields(value) {
    if (util.string.isEmpty(value)) value = '';

    let self = this;
    let fileArr = [];
    let fileNameMap = self.state.fileNameMap;
    let paths = value.split(',').filter(p => !util.string.isEmpty(p));
    fileArr = paths.map((p) => {
      let ext = p.substring(p.lastIndexOf('.'));
      return {
        uid: p,
        name: fileNameMap[p] || 'file' + ext,
        status: 'done',
        url: p,
        thumbUrl: p
      }
    });
    this.setState({
      fileList: fileArr
    });

    //显示文件名
    for (let path of paths) {
      if (!fileNameMap[path]) {
        request({
          url: config.api.getFileName + path,
          method: 'get'
        }).then(function (fileName) {
          let file = fileArr.find(p => p.url === path);
          file.name = fileName;
          fileNameMap[path] = fileName;
          self.setState({
            fileList: fileArr,
            fileNameMap: fileNameMap
          })
        })
      }
    }
  }
Ejemplo n.º 3
0
 }, () => {
   let strPath = pathArr.join();
   if (!util.string.isEmpty(strPath) && this.props.value !== strPath) {
     this.props.onChange && this.props.onChange(strPath)
   }
 });
Ejemplo n.º 4
0
 let paths = value.split(',').filter(p => !util.string.isEmpty(p));