文件上传
This commit is contained in:
parent
a1eb8e0f0d
commit
ecedc86725
|
|
@ -57,9 +57,10 @@ export function addFacturer(data) {
|
|||
//删除服务器中的文件
|
||||
export function deleteFile(objectKey) {
|
||||
return request({
|
||||
url: '/file/deleteFile',
|
||||
url: '/file/deleteFile/',
|
||||
method: 'delete',
|
||||
params:{objectKey}
|
||||
params:{"objectKey":objectKey},
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@
|
|||
</template>
|
||||
|
||||
<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 { downloadFile,downloadFileData } from '@/utils/download'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
|
@ -298,6 +298,7 @@
|
|||
businessLicenseListTemp:[],
|
||||
delBusinessFileIdList:[],
|
||||
modelIdTemp:undefined,
|
||||
base64Data:undefined,
|
||||
//图片查看弹窗
|
||||
dialogImageUrl: '',
|
||||
dialogVisible: false,
|
||||
|
|
@ -388,6 +389,10 @@
|
|||
}
|
||||
})
|
||||
this.businessLicenseListTemp.splice(sum, 1)
|
||||
if(file.status=='success'){
|
||||
this.delBusinessFileIdList.push(file.url);
|
||||
}
|
||||
console.log('delBusinessFileIdList',this.delBusinessFileIdList)
|
||||
},
|
||||
|
||||
isImage(file){
|
||||
|
|
@ -484,6 +489,7 @@
|
|||
handleAdd() {
|
||||
this.reset()
|
||||
this.uploadKey = Date.now();
|
||||
this.delBusinessFileIdList=[];
|
||||
this.businessLicenseListTemp=[];
|
||||
this.businessLicenseFileList=[];
|
||||
this.showHouse = true
|
||||
|
|
@ -493,6 +499,7 @@
|
|||
handleUpdate(row){
|
||||
this.reset()
|
||||
this.uploadKey = Date.now();
|
||||
this.delBusinessFileIdList=[];
|
||||
this.businessLicenseListTemp=[];
|
||||
this.businessLicenseFileList=[];
|
||||
const supplierId = row.supplierId;
|
||||
|
|
@ -539,8 +546,10 @@
|
|||
if(this.businessLicenseListTemp.length!=0){
|
||||
await this.getImaUploadEdit(),
|
||||
await this.editFacturerTemp(this.form);
|
||||
await this.deleteFile();
|
||||
}else{
|
||||
await this.editFacturerTemp(this.form);
|
||||
await this.deleteFile();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -602,6 +611,7 @@
|
|||
this.$modal.msgSuccess("新增成功");
|
||||
this.showHouse = false;
|
||||
this.getList();
|
||||
this.delBusinessFileIdList=[];
|
||||
this.businessLicenseListTemp=[];
|
||||
this.businessLicenseFileList=[];
|
||||
|
||||
|
|
@ -614,14 +624,49 @@
|
|||
this.$modal.msgSuccess("修改成功");
|
||||
this.showHouse = false;
|
||||
this.getList();
|
||||
this.delBusinessFileIdList=[];
|
||||
this.businessLicenseListTemp=[];
|
||||
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() {
|
||||
this.showHouse = false;
|
||||
this.delBusinessFileIdList=[];
|
||||
this.businessLicenseListTemp=[]
|
||||
this.businessLicenseFileList=[];
|
||||
this.uploadKey = Date.now();
|
||||
|
|
|
|||
Loading…
Reference in New Issue