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(obj) {
|
let url = obj.url
|
if (obj.url.indexOf('http') !== 0) {
|
url = SettingIplatform.ftpUrl + obj.url
|
}
|
window.open(decodeURI(url))
|
/* var doc = document.createElement('a')
|
doc.href = url
|
doc.download = filename
|
doc.target = '_blank'
|
doc.click()*/
|
/* const loading = Loading.service({
|
lock: true,
|
text: '正在下载...',
|
spinner: 'el-icon-loading',
|
background: 'rgba(0, 0, 0, 0.7)'
|
})
|
download(obj.url, obj.name, null, loading)*/
|
}
|
|
// 上传文件
|
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)
|
})
|
})
|
}
|