commonUploadFile.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const getFileName=(path)=>{
  2. if(path.lastIndexOf("\\")>=0){
  3. let reg=new RegExp("\\\\","g");
  4. path = path.replace(reg,"/");
  5. }
  6. return path.substring(path.lastIndexOf("/")+1);
  7. }
  8. const uidGenerator=()=>{
  9. return '-'+parseInt(Math.random()*10000+1,10);
  10. }
  11. const getFilePaths=(uploadFiles)=>{
  12. let arr = [];
  13. if(!uploadFiles){
  14. return ""
  15. }
  16. for(var a=0;a<uploadFiles.length;a++){
  17. arr.push(uploadFiles[a].response.message)
  18. }
  19. if(arr && arr.length>0){
  20. return arr.join(",")
  21. }
  22. return ""
  23. }
  24. const getUploadFileList=(paths)=>{
  25. if(!paths){
  26. return [];
  27. }
  28. let fileList = [];
  29. let arr = paths.split(",")
  30. for(var a=0;a<arr.length;a++){
  31. if(!arr[a]){
  32. continue
  33. }else{
  34. fileList.push({
  35. uid:uidGenerator(),
  36. name:getFileName(arr[a]),
  37. status: 'done',
  38. url: window._CONFIG['staticDomainURL']+"/"+arr[a],
  39. response:{
  40. status:"history",
  41. message:arr[a]
  42. }
  43. })
  44. }
  45. }
  46. return fileList;
  47. }
  48. export {getFilePaths,getUploadFileList}