反馈图片名称问题
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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
const type = "Statement of Work";
|
const type = 'Statement of Work'
|
||||||
export default {
|
export default {
|
||||||
name: "UploadImage",
|
name: 'UploadImage',
|
||||||
props: {
|
props: {
|
||||||
path: {
|
path: {
|
||||||
required: true,
|
required: true,
|
||||||
default: () => {
|
default: () => {
|
||||||
return [];
|
return []
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
|
@ -78,14 +78,14 @@ export default {
|
||||||
},
|
},
|
||||||
trialId: {
|
trialId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: '',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
fileList: [],
|
fileList: [],
|
||||||
btnDisabled: false,
|
btnDisabled: false,
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
remove(file, fileList) {
|
remove(file, fileList) {
|
||||||
|
@ -93,114 +93,113 @@ export default {
|
||||||
},
|
},
|
||||||
fileToBlob(file) {
|
fileToBlob(file) {
|
||||||
// 创建 FileReader 对象
|
// 创建 FileReader 对象
|
||||||
const reader = new FileReader();
|
const reader = new FileReader()
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// FileReader 添加 load 事件
|
// FileReader 添加 load 事件
|
||||||
reader.addEventListener("load", (e) => {
|
reader.addEventListener('load', (e) => {
|
||||||
let blob;
|
let blob
|
||||||
if (typeof e.target.result === "object") {
|
if (typeof e.target.result === 'object') {
|
||||||
blob = new Blob([e.target.result]);
|
blob = new Blob([e.target.result])
|
||||||
} else {
|
} else {
|
||||||
blob = e.target.result;
|
blob = e.target.result
|
||||||
}
|
}
|
||||||
resolve(blob);
|
resolve(blob)
|
||||||
});
|
})
|
||||||
// FileReader 以 ArrayBuffer 格式 读取 File 对象中数据
|
// FileReader 以 ArrayBuffer 格式 读取 File 对象中数据
|
||||||
reader.readAsArrayBuffer(file);
|
reader.readAsArrayBuffer(file)
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
// 上传oss
|
// 上传oss
|
||||||
async uploadToOSS(name, file) {
|
async uploadToOSS(name, file) {
|
||||||
try {
|
try {
|
||||||
let defaultPath = "/System/FeedBack/";
|
let defaultPath = '/System/FeedBack/'
|
||||||
if (this.trialId) {
|
if (this.trialId) {
|
||||||
defaultPath = `/${this.trialId}/FeedBack/`;
|
defaultPath = `/${this.trialId}/FeedBack/`
|
||||||
}
|
}
|
||||||
let res = await this.OSSclient.put(`${defaultPath}${name}`, file);
|
let res = await this.OSSclient.put(`${defaultPath}${name}`, file)
|
||||||
return res;
|
return res
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
initFileList(list) {
|
initFileList(list) {
|
||||||
if (list && list.length > 0) {
|
if (list && list.length > 0) {
|
||||||
this.fileList = [];
|
this.fileList = []
|
||||||
list.forEach((item, index) => {
|
list.forEach((item, index) => {
|
||||||
let name = item.split("/");
|
let name = item.split('/')
|
||||||
this.fileList.push({
|
this.fileList.push({
|
||||||
name: name[name.length - 1],
|
name: name[name.length - 1],
|
||||||
path: item,
|
path: item,
|
||||||
fullPath: this.OSSclientConfig.basePath + item,
|
fullPath: this.OSSclientConfig.basePath + item,
|
||||||
url: this.OSSclientConfig.basePath + item,
|
url: this.OSSclientConfig.basePath + item,
|
||||||
uid: `${name[name.length - 1]}${index}`,
|
uid: `${name[name.length - 1]}${index}`,
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async uploadFile(param) {
|
async uploadFile(param) {
|
||||||
var fileName = param.file.name;
|
var fileName = param.file.name
|
||||||
this.$emit("update:isUpload", true);
|
this.$emit('update:isUpload', true)
|
||||||
this.btnDisabled = true;
|
this.btnDisabled = true
|
||||||
this.fileList.push({
|
this.fileList.push({
|
||||||
url: param.file.url,
|
url: param.file.url,
|
||||||
path: fileName,
|
path: fileName,
|
||||||
uid: param.file.uid,
|
uid: param.file.uid,
|
||||||
});
|
})
|
||||||
let file = await this.fileToBlob(param.file);
|
let file = await this.fileToBlob(param.file)
|
||||||
let res = await this.uploadToOSS(fileName, file);
|
let res = await this.uploadToOSS(fileName, file)
|
||||||
this.btnDisabled = false;
|
this.btnDisabled = false
|
||||||
let index = this.fileList.findIndex(
|
let index = this.fileList.findIndex((item) => item.uid === param.file.uid)
|
||||||
(item) => item.uid === param.file.uid
|
|
||||||
);
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
if (index >= 0) {
|
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;
|
let name = this.$getObjectName(res.url)
|
||||||
this.fileList[index].path = res.name;
|
this.fileList[index].url = this.OSSclientConfig.basePath + name
|
||||||
this.$emit("update:path", [...this.path, res.name]);
|
this.fileList[index].path = name
|
||||||
this.$emit("update:isUpload", false);
|
this.$emit('update:path', [...this.path, res.name])
|
||||||
return false;
|
this.$emit('update:isUpload', false)
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
beforeUpload(file, fileList) {
|
beforeUpload(file, fileList) {
|
||||||
const isValidFile = this.fileValid(file.name, ["png", "jpg", "jpeg"]);
|
const isValidFile = this.fileValid(file.name, ['png', 'jpg', 'jpeg'])
|
||||||
if (isValidFile) {
|
if (isValidFile) {
|
||||||
// this.fileList = [];
|
// this.fileList = [];
|
||||||
} else {
|
} else {
|
||||||
this.$alert(this.$t("feedBack:uploadImg:format"));
|
this.$alert(this.$t('feedBack:uploadImg:format'))
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handlePreview(file) {
|
handlePreview(file) {
|
||||||
file.fullPath ? window.open(file.fullPath, "_blank") : "";
|
file.fullPath ? window.open(file.fullPath, '_blank') : ''
|
||||||
},
|
},
|
||||||
handleExceed(files, fileList) {
|
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) {
|
fileValid(fileName, typeArr) {
|
||||||
var extendName = fileName
|
var extendName = fileName
|
||||||
.substring(fileName.lastIndexOf(".") + 1)
|
.substring(fileName.lastIndexOf('.') + 1)
|
||||||
.toLocaleLowerCase();
|
.toLocaleLowerCase()
|
||||||
if (typeArr.indexOf(extendName) > -1) {
|
if (typeArr.indexOf(extendName) > -1) {
|
||||||
return true;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handlePictureCardPreview(file) {
|
handlePictureCardPreview(file) {
|
||||||
this.$refs[file.url].$viewer.show();
|
this.$refs[file.url].$viewer.show()
|
||||||
},
|
},
|
||||||
handleRemove(file) {
|
handleRemove(file) {
|
||||||
let index = this.fileList.findIndex((item) => item.uid === file.uid);
|
let index = this.fileList.findIndex((item) => item.uid === file.uid)
|
||||||
this.fileList.splice(index, 1);
|
this.fileList.splice(index, 1)
|
||||||
let arr = this.fileList.map((item) => item.path);
|
let arr = this.fileList.map((item) => item.path)
|
||||||
this.$emit("update:path", arr);
|
this.$emit('update:path', arr)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
.upload-container .el-upload--text {
|
.upload-container .el-upload--text {
|
||||||
|
|
Loading…
Reference in New Issue