图片上传前端逻辑修改

master
maxw@mesnac.com 8 months ago
parent 806e739ac2
commit 18e677ee36

@ -268,7 +268,7 @@ export default {
this.isCommonName = true; this.isCommonName = true;
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'; // JPGPNG const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'; // JPGPNG
const isLt2M = file.size / 1024 / 1024 < 2; const isLt2M = file.size / 1024 / 1024 < 2;
// //
if(this.fileListPut.length > 0){ if(this.fileListPut.length > 0){
this.fileListPut.forEach((item,index)=>{ this.fileListPut.forEach((item,index)=>{
if(item.name == file.name){ if(item.name == file.name){
@ -287,6 +287,11 @@ export default {
}, },
// //
handleRemove(file, fileList) { handleRemove(file, fileList) {
const url = file.url;
console.log(url);
const i = this.imgAddress.findIndex((x)=> x.url === url);
this.imgAddress.splice(i,1);
console.log(this.imgAddress)
//filefileListPut //filefileListPut
if(this.fileListPut.length > 0){ if(this.fileListPut.length > 0){
this.fileListPut = this.fileListPut.filter((item, index)=>{ this.fileListPut = this.fileListPut.filter((item, index)=>{
@ -311,6 +316,7 @@ export default {
// //
this.fileListPut.push(currentFile); this.fileListPut.push(currentFile);
console.log(this.fileListPut) console.log(this.fileListPut)
console.log(this.imgAddress)
}, },
@ -372,6 +378,9 @@ export default {
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
console.log(this.imgAddress.length)
this.imgAddress.length=0;
// this.form.fileUrls.length=0;
this.fileListShow = []; this.fileListShow = [];
this.reset(); this.reset();
this.open = true; this.open = true;
@ -379,9 +388,14 @@ export default {
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
this.reset(); this.reset();
const knowledgeRepairId = row.knowledgeRepairId || this.ids const knowledgeRepairId = row.knowledgeRepairId || this.ids
getKnowledgeRepair(knowledgeRepairId).then(response => { getKnowledgeRepair(knowledgeRepairId).then(response => {
console.log(response.data.systemFiles)
for (let element of response.data.systemFiles) {
this.imgAddress.push(element.url)
}
this.form = response.data; this.form = response.data;
this.fileListShow = response.data.systemFiles this.fileListShow = response.data.systemFiles
console.log(this.fileListShow) console.log(this.fileListShow)
@ -394,13 +408,18 @@ export default {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
if (this.form.knowledgeRepairId != null) { if (this.form.knowledgeRepairId != null) {
this.form.fileUrls = [];
this.form.fileUrls = this.imgAddress; this.form.fileUrls = this.imgAddress;
console.log(this.form.fileUrls)
updateKnowledgeRepair(this.form).then(response => { updateKnowledgeRepair(this.form).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
this.imgAddress.length = 0;
this.form.fileUrls.length=0;
this.open = false; this.open = false;
this.getList(); this.getList();
}); });
} else { } else {
// this.form.fileUrls.length=0;
this.form.fileUrls = this.imgAddress; this.form.fileUrls = this.imgAddress;
addKnowledgeRepair(this.form).then(response => { addKnowledgeRepair(this.form).then(response => {
this.$modal.msgSuccess("新增成功"); this.$modal.msgSuccess("新增成功");

@ -329,6 +329,11 @@ export default {
}, },
// //
handleRemove(file, fileList) { handleRemove(file, fileList) {
const url = file.url;
console.log(url);
const i = this.imgAddress.findIndex((x)=> x.url === url);
this.imgAddress.splice(i,1);
console.log(this.imgAddress)
//filefileListPut //filefileListPut
if(this.fileListPut.length > 0){ if(this.fileListPut.length > 0){
this.fileListPut = this.fileListPut.filter((item, index)=>{ this.fileListPut = this.fileListPut.filter((item, index)=>{
@ -353,6 +358,7 @@ export default {
// //
this.fileListPut.push(currentFile); this.fileListPut.push(currentFile);
console.log(this.fileListPut) console.log(this.fileListPut)
console.log(this.imgAddress)
}, },
@ -427,6 +433,8 @@ export default {
}, },
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
console.log(this.imgAddress.length)
this.imgAddress.length=0;
this.reset(); this.reset();
this.fileListShow = []; this.fileListShow = [];
this.open = true; this.open = true;
@ -437,8 +445,13 @@ export default {
this.reset(); this.reset();
const knowledgeMaintId = row.knowledgeMaintId || this.ids const knowledgeMaintId = row.knowledgeMaintId || this.ids
getKonwledgeMaint(knowledgeMaintId).then(response => { getKonwledgeMaint(knowledgeMaintId).then(response => {
console.log(response.data.systemFiles)
for (let element of response.data.systemFiles) {
this.imgAddress.push(element.url)
}
this.form = response.data; this.form = response.data;
this.fileListShow = response.data.systemFiles this.fileListShow = response.data.systemFiles
console.log(this.fileListShow)
this.open = true; this.open = true;
this.title = "修改保养知识库"; this.title = "修改保养知识库";
}); });
@ -448,21 +461,23 @@ export default {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
if (this.form.knowledgeMaintId != null) { if (this.form.knowledgeMaintId != null) {
this.form.fileUrls = [];
this.form.fileUrls = this.imgAddress; this.form.fileUrls = this.imgAddress;
updateKonwledgeMaint(this.form).then(response => { updateKonwledgeMaint(this.form).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
this.imgAddress.length = 0;
this.form.fileUrls.length=0;
this.open = false; this.open = false;
// this.imgAddress.length = 0;
this.getList(); this.getList();
}); });
} else { } else {
this.form.fileUrls = this.imgAddress; this.form.fileUrls = this.imgAddress;
addKonwledgeMaint(this.form).then(response => { addKonwledgeMaint(this.form).then(response => {
this.$modal.msgSuccess("新增成功"); this.$modal.msgSuccess("新增成功");
this.imgAddress.length = 0;
this.open = false; this.open = false;
console.log(this.imgAddress) console.log(this.imgAddress)
this.imgAddress.length = 0;
this.getList(); this.getList();
}); });
} }

Loading…
Cancel
Save