文件上传备份

This commit is contained in:
XaoLi717 2024-09-25 08:46:46 +08:00
parent db7d055392
commit 2ff8204189

View File

@ -48,19 +48,32 @@
import { ref, onMounted } from 'vue';
import axios from 'axios';
import { getAccessToken } from '@/utils/auth'
// import {onlyofApi} from "@/api/only/only";
import {onlyofApi} from "@/api/only/only";
import {pjVO} from "@/api/home/homepj";
//
const fileList = ref([]);
// const fileList = ref([]);
const fileList = ref<pjVO[]>([]) //
const myfile = ref(null);
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
fileName: undefined,
fileSize: undefined,
fileType: undefined,
filePath: undefined,
uploadDate: [],
status: undefined,
createTime: [],
})
//
const getFileList = async () => {
const token = getAccessToken();
// const token = getAccessToken();
try {
const response = await axios.get(`http://192.168.1.3:48080/admin-api/only/onlyof/filelist?token=${token}`);
// const response = await onlyofApi.getOnlyOfList();
fileList.value = response.data;
// const response = await axios.get(`http://192.168.1.15:48080/admin-api/only/onlyof/filelist?token=${token}`);
const data = await onlyofApi.getonlyofPage(queryParams);
fileList.value = data.list;
} catch (error) {
console.error('Failed to fetch file list:', error);
}
@ -68,21 +81,25 @@ const getFileList = async () => {
//
const upload = async () => {
console.log("myFile: ",myfile)
console.log("myFile: ",myfile.value)
const fileInput = myfile.value;
const file = fileInput.files[0];
console.log("file",file)
const formData = new FormData();
const token = getAccessToken();
const configs = {
headers: { 'Authorization': `Bearer ${token}`,'Content-Type': 'multipart/form-data' }
}
formData.append('file', file);
console.log("configs",configs)
try {
const response = await axios.post('http://192.168.1.3:48080/admin-api/only/onlyof/update', formData, configs);
const response = await axios.post('http://192.168.1.15:48080/admin-api/only/onlyof/update', formData, configs);
console.log(response);
} catch (error) {
console.error('Upload failed:', error);
}
await getFileList();
};
const editvo = ({
@ -96,7 +113,7 @@ const edit = async (row) => {
editvo.name=row.fileName
editvo.username="admin"
editvo.userid="1"
window.open(`http://192.168.1.3:48080/admin-api/only/onlyof/edit?name=${row.fileName}&userName=admin&userId=1&token=${token}`);
window.open(`http://192.168.1.15:48080/admin-api/only/onlyof/edit?name=${row.fileName}&userName=admin&userId=1&token=${token}`);
};
//
@ -107,14 +124,14 @@ const review = () => {
const download = async (row) => {
try {
const token = getAccessToken();
const response = await axios.get(`http://192.168.1.3:48080/admin-api/only/onlyof/editStatus?name=${row.fileName}&token=${token}`);
const response = await axios.get(`http://192.168.1.15:48080/admin-api/only/onlyof/editStatus?name=${row.fileName}&token=${token}`);
if (response.data.error === 0) {
alert('文档正在编辑5秒后开始下载最新版');
setTimeout(() => {
window.location.href = `http://192.168.1.3:48080/admin-api/only/onlyof/download?name=v1${row.fileName}&token=${token}`;
window.location.href = `http://192.168.1.15:48080/admin-api/only/onlyof/download?name=v1${row.fileName}&token=${token}`;
}, 5000);
} else {
window.location.href = `http://192.168.1.3:48080/admin-api/only/onlyof/download?name=${row.fileName}&token=${token}`;
window.location.href = `http://192.168.1.15:48080/admin-api/only/onlyof/download?name=${row.fileName}&token=${token}`;
}
} catch (error) {
console.error('Download failed:', error);