Blame view

ant-design-vue-jeecg/src/utils/commonUploadFile.js 1.11 KB
肖超群 authored
1
2
3
4
5
6
import {getFileAccessHttpUrl} from '@/api/manage'

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