反馈图片名称问题
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
3bb0250699
commit
49241bacfa
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue