import {request} from '@/plugins';
|
import axios from 'axios';
|
|
import {auth} from '@/plugins';
|
import config from '/config';
|
|
|
const getFileText = async (id) => {
|
const {data} = await request({
|
url: `/root/file/download?id=${id}`,
|
method: 'get',
|
responseType: 'blob'
|
})
|
|
const reader = new FileReader();
|
reader.readAsText(data, 'UTF-8');
|
return new Promise((resolve) => {
|
reader.onload = ({target}) => {
|
resolve(target.result);
|
};
|
});
|
|
}
|
|
const downloadFile = async (id) => {
|
const {data} = await request({
|
url: `/root/file/download?id=${id}&&isSrc=true`,
|
})
|
return data.path.replace('root',`${config.baseUrl}source`);
|
}
|
|
const uploadFile = async (formData) => {
|
const {data} = await axios.post(`${config.baseUrl}worder/file/exec?userId=${auth.getToken()}`, formData, {
|
headers: {
|
'Content-Type': 'multipart/form-data'
|
}
|
});
|
return data.data.ids;
|
}
|
|
|
export default {
|
getFileText,
|
uploadFile,
|
downloadFile
|
}
|