Blame view

ant-design-vue-jeecg/src/utils/commonUploadFile.js 1.05 KB
1
import { getFileAccessHttpUrl } from '@/api/manage'
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const getFileName=(path)=>{
  if(path.lastIndexOf("\\")>=0){
    let reg=new RegExp("\\\\","g");
    path = path.replace(reg,"/");
  }
  return path.substring(path.lastIndexOf("/")+1);
}

const uidGenerator=()=>{
  return '-'+parseInt(Math.random()*10000+1,10);
}

const getFilePaths=(uploadFiles)=>{
  let arr = [];
  if(!uploadFiles){
    return ""
  }
19
  for(let a=0;a<uploadFiles.length;a++){
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    arr.push(uploadFiles[a].response.message)
  }
  if(arr && arr.length>0){
    return arr.join(",")
  }
  return ""
}

const getUploadFileList=(paths)=>{
  if(!paths){
    return [];
  }
  let fileList = [];
  let arr = paths.split(",")
34
  for(let a=0;a<arr.length;a++){
35
36
37
38
39
40
41
    if(!arr[a]){
      continue
    }else{
      fileList.push({
        uid:uidGenerator(),
        name:getFileName(arr[a]),
        status: 'done',
42
        url: getFileAccessHttpUrl(arr[a]),
43
44
45
46
47
48
49
50
51
52
        response:{
          status:"history",
          message:arr[a]
        }
      })
    }
  }
  return fileList;
}
export {getFilePaths,getUploadFileList}