石广澎
2023-12-13 8db5b7ff317abcfd6905a2722850944d8574eafa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Message} from 'element-ui'
import SettingIplatform from "../../public/static/config";
import axios from "axios";
import store from "@/store";
 
// Base Url
export function getBaseUrl() {
  return SettingIplatform.apiBaseURL
}
 
// Ftp Url
export function getFtpUrl() {
  return SettingIplatform.ftpUrl
}
 
// Ftp 下载地址
export function getDownUrl() {
  return getBaseUrl() + '/file/'
}
 
// Ftp 上传地址
export function getUploadUrl() {
  return getBaseUrl() + '/pc/fin/file/uploadMore'
}
 
 
// 下载文件
export function downLoad(url) {
  let link = url
  if (link.indexOf('http') !== 0) {
    link = SettingIplatform.ftpUrl + url
  }
   var doc = document.createElement('a')
  doc.href = link
  doc.target = '_blank'
  doc.rel = "noreferrer noopener"
  doc.click()
  document.body.removeChild(doc);
}
 
// 上传文件
export function upLoadFile(formData) {
  const token = !store.getters.token ? sessionStorage.getItem('token') : store.getters.token;
  return new Promise((resolve, reject) => {
    axios.post(
      getUploadUrl(),
      formData,
      {
        headers: {
          'Authorization': token
        },
        dataType: 'json',
        crossDomain: true,
        processData: false,
        contentType: false,
      }
    ).then(res => {
      if (res.data.code === 1) {
        resolve(res.data.data)
      } else {
        reject()
      }
    }).catch(err => {
      reject(err)
    })
  })
}