Commit da8d679c by cwq0219

图片上传

1 parent 570f95d3
......@@ -62,7 +62,7 @@
<div v-if="!item.isDisabled" :style="{ width: item.width || defaultWidth }">
<div v-if="Array.isArray(formObj[item.name]) ? formObj[item.name].length < item.maxPhotoNum : !formObj[item.name]" class="activity-img img-w-h">
<div class="add" :style="{ top: item.maxPhotoNum == 1 ? '50%' : '40%' }">+</div>
<span v-show="item.maxPhotoNum > 1" class="number">{{ formObj[item.name].length }} / {{ item.maxPhotoNum }}</span>
<span v-if="item.maxPhotoNum > 1" class="number">{{ formObj[item.name].length }} / {{ item.maxPhotoNum }}</span>
<input v-if="item.uploadType == 'video'" type="file" style="opacity: 0;" :id="item.name + 'file'" ref="file" class="activity-img img-w-h" accept="video/mp4" @change="e => handleUploadChange(e, item)" />
<input v-else type="file" style="opacity: 0;" :id="item.name + 'file'" ref="file" class="activity-img img-w-h" accept="image/png, image/jpeg, image/gif, image/jpg" @change="e => handleUploadChange(e, item)" />
</div>
......@@ -205,16 +205,19 @@ export default {
const maxPhotoNum = targetItem.maxPhotoNum || 1
const wdithLt = targetItem.wdithLt || 300
const heightLt = targetItem.heightLt || 300
if (maxPhotoNum == this.formObj[targetItem.name].length) {
if (Array.isArray(this.formObj[targetItem.name]) && maxPhotoNum == this.formObj[targetItem.name].length) {
this.$message.error('只能上传' + maxPhotoNum + (uploadType == 'img' ? '张图片' : '个视频'))
document.getElementById(targetItem.name + 'file').value = ''
return true
}
if (!isType) {
this.$message.error(uploadType == 'img' ? '上传图片不是jpg、jpeg或png的格式!' : '上传视频不是MP4的格式!')
document.getElementById(targetItem.name + 'file').value = ''
return true
}
if (!isLt) {
this.$message.error('上传' + (uploadType == 'img' ? '图片' : '视频') + '大小不能超过' + limitSize + 'MB!')
document.getElementById(targetItem.name + 'file').value = ''
return true
}
reader.readAsDataURL(file)
......@@ -235,6 +238,7 @@ export default {
targetItem.handleUpload(e, file, targetItem)
}
}
document.getElementById(targetItem.name + 'file').value = ''
},
// 图片删除
handleImgDelete(targetItem, subIndex = -1) {
......@@ -435,10 +439,10 @@ export default {
.glsx-combi-form .el-tag.el-tag--info {
border-color: #5850ff;
}
.el-tag--plain.el-tag--info .el-tag__close:hover {
.glsx-combi-form .el-tag--plain.el-tag--info .el-tag__close:hover {
background-color: #E8E8EA;
}
.el-tag.el-tag--info .el-tag__close:hover {
.glsx-combi-form .el-tag.el-tag--info .el-tag__close:hover {
background-color: #E8E8EA;
}
</style>
......@@ -191,7 +191,7 @@ export default {
image.onload = () => {
console.log(file, targetItem)
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
let len = this.previewList.length - 1
......@@ -220,7 +220,7 @@ export default {
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
console.log(res)
......
......@@ -425,7 +425,7 @@ export default {
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm.bannerList[idx].bannerImg = res
})
......@@ -465,7 +465,7 @@ export default {
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm.bannerList[this.curBanner.idx].imgLinkUrl = res
})
......@@ -490,7 +490,7 @@ export default {
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadVideoApi({ file: base64 }).then(res => {
this.editForm.bannerList[this.curBanner.idx].videoLinkUrl = res
})
......
......@@ -69,7 +69,7 @@ export default {
maxPhotoNum: 1,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadVideoApi({ file: base64 }).then(res => {
this.editForm[targetItem.name] = res
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
......@@ -84,7 +84,7 @@ export default {
maxPhotoNum: 8,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name].push(res)
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
......
......@@ -522,7 +522,7 @@ export default {
isDisabled: false,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name] = res
this.$refs.editFormRef[0].$refs.editProRef0.validateField(targetItem.name)
......@@ -540,7 +540,7 @@ export default {
isDisabled: false,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name].push({
content: res,
......@@ -563,7 +563,7 @@ export default {
isDisabled: false,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadVideoApi({ file: base64 }).then(res => {
this.editForm[targetItem.name] = res
this.getWechatImgList()
......@@ -1214,7 +1214,7 @@ export default {
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm.descImgList[idx].content = res
})
......
......@@ -175,9 +175,9 @@ export default {
maxPhotoNum: 1,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
console.log(res)
// console.log(res)
this.editForm[targetItem.name] = res
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
})
......
......@@ -60,7 +60,7 @@ export default {
maxPhotoNum: 1,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name] = res
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
......
......@@ -86,7 +86,7 @@ export default {
maxPhotoNum: 1,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
this.$apis.common.uploadImgApi({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name] = res
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!