反馈图片名称问题
continuous-integration/drone/push Build is passing Details

uat_us
DESKTOP-6C3NK6N\WXS 2024-09-29 10:56:51 +08:00
parent 3bb0250699
commit 49241bacfa
1 changed files with 56 additions and 57 deletions

View File

@ -58,14 +58,14 @@
</div>
</template>
<script>
const type = "Statement of Work";
const type = 'Statement of Work'
export default {
name: "UploadImage",
name: 'UploadImage',
props: {
path: {
required: true,
default: () => {
return [];
return []
},
},
disabled: {
@ -78,14 +78,14 @@ export default {
},
trialId: {
type: String,
default: "",
default: '',
},
},
data() {
return {
fileList: [],
btnDisabled: false,
};
}
},
methods: {
remove(file, fileList) {
@ -93,114 +93,113 @@ export default {
},
fileToBlob(file) {
// FileReader
const reader = new FileReader();
const reader = new FileReader()
return new Promise((resolve) => {
// FileReader load
reader.addEventListener("load", (e) => {
let blob;
if (typeof e.target.result === "object") {
blob = new Blob([e.target.result]);
reader.addEventListener('load', (e) => {
let blob
if (typeof e.target.result === 'object') {
blob = new Blob([e.target.result])
} else {
blob = e.target.result;
blob = e.target.result
}
resolve(blob);
});
resolve(blob)
})
// FileReader ArrayBuffer File
reader.readAsArrayBuffer(file);
});
reader.readAsArrayBuffer(file)
})
},
// oss
async uploadToOSS(name, file) {
try {
let defaultPath = "/System/FeedBack/";
let defaultPath = '/System/FeedBack/'
if (this.trialId) {
defaultPath = `/${this.trialId}/FeedBack/`;
defaultPath = `/${this.trialId}/FeedBack/`
}
let res = await this.OSSclient.put(`${defaultPath}${name}`, file);
return res;
let res = await this.OSSclient.put(`${defaultPath}${name}`, file)
return res
} catch (err) {
console.log(err);
return false;
console.log(err)
return false
}
},
initFileList(list) {
if (list && list.length > 0) {
this.fileList = [];
this.fileList = []
list.forEach((item, index) => {
let name = item.split("/");
let name = item.split('/')
this.fileList.push({
name: name[name.length - 1],
path: item,
fullPath: this.OSSclientConfig.basePath + item,
url: this.OSSclientConfig.basePath + item,
uid: `${name[name.length - 1]}${index}`,
});
});
})
})
}
},
async uploadFile(param) {
var fileName = param.file.name;
this.$emit("update:isUpload", true);
this.btnDisabled = true;
var fileName = param.file.name
this.$emit('update:isUpload', true)
this.btnDisabled = true
this.fileList.push({
url: param.file.url,
path: fileName,
uid: param.file.uid,
});
let file = await this.fileToBlob(param.file);
let res = await this.uploadToOSS(fileName, file);
this.btnDisabled = false;
let index = this.fileList.findIndex(
(item) => item.uid === param.file.uid
);
})
let file = await this.fileToBlob(param.file)
let res = await this.uploadToOSS(fileName, file)
this.btnDisabled = false
let index = this.fileList.findIndex((item) => item.uid === param.file.uid)
if (!res) {
if (index >= 0) {
this.fileList.splice(index, 1);
this.fileList.splice(index, 1)
}
return this.$emit("update:isUpload", false);
return this.$emit('update:isUpload', false)
}
this.fileList[index].url = this.OSSclientConfig.basePath + res.name;
this.fileList[index].path = res.name;
this.$emit("update:path", [...this.path, res.name]);
this.$emit("update:isUpload", false);
return false;
let name = this.$getObjectName(res.url)
this.fileList[index].url = this.OSSclientConfig.basePath + name
this.fileList[index].path = name
this.$emit('update:path', [...this.path, res.name])
this.$emit('update:isUpload', false)
return false
},
beforeUpload(file, fileList) {
const isValidFile = this.fileValid(file.name, ["png", "jpg", "jpeg"]);
const isValidFile = this.fileValid(file.name, ['png', 'jpg', 'jpeg'])
if (isValidFile) {
// this.fileList = [];
} else {
this.$alert(this.$t("feedBack:uploadImg:format"));
return false;
this.$alert(this.$t('feedBack:uploadImg:format'))
return false
}
},
handlePreview(file) {
file.fullPath ? window.open(file.fullPath, "_blank") : "";
file.fullPath ? window.open(file.fullPath, '_blank') : ''
},
handleExceed(files, fileList) {
this.$message.warning(`Upload is currently limited to 1 file`);
this.$message.warning(`Upload is currently limited to 1 file`)
},
fileValid(fileName, typeArr) {
var extendName = fileName
.substring(fileName.lastIndexOf(".") + 1)
.toLocaleLowerCase();
.substring(fileName.lastIndexOf('.') + 1)
.toLocaleLowerCase()
if (typeArr.indexOf(extendName) > -1) {
return true;
return true
} else {
return false;
return false
}
},
handlePictureCardPreview(file) {
this.$refs[file.url].$viewer.show();
this.$refs[file.url].$viewer.show()
},
handleRemove(file) {
let index = this.fileList.findIndex((item) => item.uid === file.uid);
this.fileList.splice(index, 1);
let arr = this.fileList.map((item) => item.path);
this.$emit("update:path", arr);
let index = this.fileList.findIndex((item) => item.uid === file.uid)
this.fileList.splice(index, 1)
let arr = this.fileList.map((item) => item.path)
this.$emit('update:path', arr)
},
},
};
}
</script>
<style>
.upload-container .el-upload--text {