25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commonUploadFile.js 1.0 KiB

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