文件上传

This commit is contained in:
jjLv 2024-10-30 16:49:20 +08:00
parent a1eb8e0f0d
commit ecedc86725
2 changed files with 49 additions and 3 deletions

View File

@ -57,9 +57,10 @@ export function addFacturer(data) {
//删除服务器中的文件 //删除服务器中的文件
export function deleteFile(objectKey) { export function deleteFile(objectKey) {
return request({ return request({
url: '/file/deleteFile', url: '/file/deleteFile/',
method: 'delete', method: 'delete',
params:{objectKey} params:{"objectKey":objectKey},
}) })
} }

View File

@ -231,7 +231,7 @@
</template> </template>
<script> <script>
import { getListFacturer,getFacturerDetail,editFacturer,addFacturer,delFacturer } from "@/api/ma/supplier"; import { getListFacturer,getFacturerDetail,editFacturer,addFacturer,delFacturer,deleteFile } from "@/api/ma/supplier";
import { imgUpLoadThree, fileUpLoad } from '@/api/system/upload' import { imgUpLoadThree, fileUpLoad } from '@/api/system/upload'
import { downloadFile,downloadFileData } from '@/utils/download' import { downloadFile,downloadFileData } from '@/utils/download'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
@ -298,6 +298,7 @@
businessLicenseListTemp:[], businessLicenseListTemp:[],
delBusinessFileIdList:[], delBusinessFileIdList:[],
modelIdTemp:undefined, modelIdTemp:undefined,
base64Data:undefined,
// //
dialogImageUrl: '', dialogImageUrl: '',
dialogVisible: false, dialogVisible: false,
@ -388,6 +389,10 @@
} }
}) })
this.businessLicenseListTemp.splice(sum, 1) this.businessLicenseListTemp.splice(sum, 1)
if(file.status=='success'){
this.delBusinessFileIdList.push(file.url);
}
console.log('delBusinessFileIdList',this.delBusinessFileIdList)
}, },
isImage(file){ isImage(file){
@ -484,6 +489,7 @@
handleAdd() { handleAdd() {
this.reset() this.reset()
this.uploadKey = Date.now(); this.uploadKey = Date.now();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[]; this.businessLicenseListTemp=[];
this.businessLicenseFileList=[]; this.businessLicenseFileList=[];
this.showHouse = true this.showHouse = true
@ -493,6 +499,7 @@
handleUpdate(row){ handleUpdate(row){
this.reset() this.reset()
this.uploadKey = Date.now(); this.uploadKey = Date.now();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[]; this.businessLicenseListTemp=[];
this.businessLicenseFileList=[]; this.businessLicenseFileList=[];
const supplierId = row.supplierId; const supplierId = row.supplierId;
@ -539,8 +546,10 @@
if(this.businessLicenseListTemp.length!=0){ if(this.businessLicenseListTemp.length!=0){
await this.getImaUploadEdit(), await this.getImaUploadEdit(),
await this.editFacturerTemp(this.form); await this.editFacturerTemp(this.form);
await this.deleteFile();
}else{ }else{
await this.editFacturerTemp(this.form); await this.editFacturerTemp(this.form);
await this.deleteFile();
} }
} else { } else {
@ -602,6 +611,7 @@
this.$modal.msgSuccess("新增成功"); this.$modal.msgSuccess("新增成功");
this.showHouse = false; this.showHouse = false;
this.getList(); this.getList();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[]; this.businessLicenseListTemp=[];
this.businessLicenseFileList=[]; this.businessLicenseFileList=[];
@ -614,14 +624,49 @@
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
this.showHouse = false; this.showHouse = false;
this.getList(); this.getList();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[]; this.businessLicenseListTemp=[];
this.businessLicenseFileList=[]; this.businessLicenseFileList=[];
}); });
}, },
async deleteFile(){
if(this.delBusinessFileIdList.length>0){
this.delBusinessFileIdList.forEach(async item=>{
const urlCode = encodeURIComponent(item)
await deleteFile(btoa(urlCode));
})
}
},
async convertToBase64(data) {
const url = data;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('网络响应不正常');
}
const blob = await response.blob();
const reader = new FileReader();
reader.onloadend = () => {
this.base64Data = reader.result; // Base64
};
reader.readAsDataURL(blob); // Blob Data URL
} catch (error) {
console.error('获取文件失败:', error);
}
},
// //
cancel() { cancel() {
this.showHouse = false; this.showHouse = false;
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[] this.businessLicenseListTemp=[]
this.businessLicenseFileList=[]; this.businessLicenseFileList=[];
this.uploadKey = Date.now(); this.uploadKey = Date.now();