Commit 7dc45923 by cwq0219

表单-视频

1 parent d1381c1e
...@@ -34,6 +34,17 @@ const uploadImgApi = params => { ...@@ -34,6 +34,17 @@ const uploadImgApi = params => {
}) })
} }
const uploadVideoApi = params => {
params.method = `${defaultPath}common.uploadVideo`
return http({
url: 'rop-scrm-carlife/router',
method: 'POST',
data: params,
sign: true,
noSignAttr: ['file']
})
}
const getMerchantList = params => { const getMerchantList = params => {
params.method = `${defaultPath}merchant.listWithPageByCurMerchant` params.method = `${defaultPath}merchant.listWithPageByCurMerchant`
return http({ return http({
...@@ -54,4 +65,4 @@ const getZoneListApi = params => { ...@@ -54,4 +65,4 @@ const getZoneListApi = params => {
}) })
} }
export default { getMerchantGoodsListApi, getGoodsListApi, uploadImgApi, getMerchantList, getZoneListApi } export default { getMerchantGoodsListApi, getGoodsListApi, uploadImgApi, uploadVideoApi, getMerchantList, getZoneListApi }
...@@ -57,28 +57,31 @@ ...@@ -57,28 +57,31 @@
<div v-if="Array.isArray(formObj[item.name]) ? formObj[item.name].length < item.maxPhotoNum : !formObj[item.name]" class="activity-img img-w-h"> <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">+</div> <div class="add">+</div>
<span class="number">{{ formObj[item.name].length }} / {{ item.maxPhotoNum }}</span> <span class="number">{{ formObj[item.name].length }} / {{ item.maxPhotoNum }}</span>
<input 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 => handleImgChange(e, item)" /> <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> </div>
</div> </div>
<template> <template>
<div v-if="Array.isArray(formObj[item.name]) ? formObj[item.name].length : formObj[item.name]"> <div v-if="Array.isArray(formObj[item.name]) ? formObj[item.name].length : formObj[item.name]">
<span v-if="Array.isArray(formObj[item.name])"> <span v-if="Array.isArray(formObj[item.name])">
<span v-for="(subItem, subIndex) in formObj[item.name]" :key="subIndex" class="muti-imgs img-w-h"> <span v-for="(subItem, subIndex) in formObj[item.name]" :key="subIndex" class="muti-imgs img-w-h">
<img class="img-w-h" :src="typeof subItem == 'object' ? subItem.content : subItem" /> <video v-if="item.uploadType == 'video'" class="img-w-h activity-img" :src="typeof subItem == 'object' ? subItem.content : subItem"></video>
<img v-else class="img-w-h" :src="typeof subItem == 'object' ? subItem.content : subItem" />
<span class="img-btns"> <span class="img-btns">
<span class="btn-item"> <span class="btn-item">
<i v-show="!item.isDisabled" class="el-icon-delete" @click="handleImgDelete(item, subIndex)"></i> <i v-show="!item.isDisabled" class="el-icon-delete" @click="handleImgDelete(item, subIndex)"></i>
<i class="el-icon-zoom-in" @click="handleImgLook(typeof subItem == 'object' ? subItem.content : subItem)"></i> <i class="el-icon-zoom-in" @click="handleImgLook(typeof subItem == 'object' ? subItem.content : subItem, item)"></i>
</span> </span>
</span> </span>
</span> </span>
</span> </span>
<span v-else class="muti-imgs"> <span v-else class="muti-imgs">
<img class="img-w-h" :src="formObj[item.name]" /> <video v-if="item.uploadType == 'video'" class="img-w-h activity-img" :src="formObj[item.name]"></video>
<img v-else class="img-w-h" :src="formObj[item.name]" />
<span class="img-btns"> <span class="img-btns">
<span class="btn-item"> <span class="btn-item">
<i v-show="!item.isDisabled" class="el-icon-delete" @click="handleImgDelete(item)"></i> <i v-show="!item.isDisabled" class="el-icon-delete" @click="handleImgDelete(item)"></i>
<i class="el-icon-zoom-in" @click="handleImgLook(formObj[item.name])"></i> <i class="el-icon-zoom-in" @click="handleImgLook(formObj[item.name], item)"></i>
</span> </span>
</span> </span>
</span> </span>
...@@ -89,8 +92,11 @@ ...@@ -89,8 +92,11 @@
</template> </template>
<slot name="footer"></slot> <slot name="footer"></slot>
</el-form> </el-form>
<el-dialog :visible.sync="isImgVisible"> <el-dialog :visible.sync="isImgVisible" class="dialog-look">
<img class="dialog-img" width="100%" :src="dialogImageUrl" alt="" /> <video v-if="dialogObj.uploadType == 'video'" class="dialog-video" controls>
<source :src="dialogObj.url" type="video/mp4">
</video>
<img v-else class="dialog-img" width="100%" :src="dialogObj.url" alt="" />
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
...@@ -106,7 +112,10 @@ export default { ...@@ -106,7 +112,10 @@ export default {
afterRangePickerOptions: afterRangePickerOptions afterRangePickerOptions: afterRangePickerOptions
}, },
isImgVisible: false, isImgVisible: false,
dialogImageUrl: '' dialogObj: {
url: '',
uploadType: 'img'
}
} }
}, },
...@@ -159,41 +168,46 @@ export default { ...@@ -159,41 +168,46 @@ export default {
} }
}, },
// 图片 // 图片
handleImgChange(e, targetItem) { handleUploadChange(e, targetItem) {
var reader = new FileReader() var reader = new FileReader()
var file = e.srcElement.files[0] var file = e.srcElement.files[0]
var uploadType = targetItem.uploadType || 'img'
// console.log(file) // console.log(file)
// 默认1MB // 默认1MB
const limitSize = targetItem.limitSize || 1 const limitSize = targetItem.limitSize || 1
const isLt = file.size / 1024 / 1024 < limitSize const isLt = file.size / 1024 / 1024 < limitSize
const isType = ['image/jpeg', 'image/png', 'image/jpg'].includes(file.type) const isType = uploadType == 'img' ? ['image/jpeg', 'image/png', 'image/jpg'].includes(file.type) : ['video/mp4'].includes(file.type)
const maxPhotoNum = targetItem.maxPhotoNum || 1 const maxPhotoNum = targetItem.maxPhotoNum || 1
const wdithLt = targetItem.wdithLt || 300 const wdithLt = targetItem.wdithLt || 300
const heightLt = targetItem.heightLt || 300 const heightLt = targetItem.heightLt || 300
if (maxPhotoNum == this.formObj[targetItem.name].length) { if (maxPhotoNum == this.formObj[targetItem.name].length) {
this.$message.error('只能上传' + maxPhotoNum + '张图片') this.$message.error('只能上传' + maxPhotoNum + (uploadType == 'img' ? '张图片' : '个视频'))
return true return true
} }
if (!isType) { if (!isType) {
this.$message.error('上传图片不是jpg、jpeg或png的格式!') this.$message.error(uploadType == 'img' ? '上传图片不是jpg、jpeg或png的格式!' : '上传视频不是MP4的格式!')
return true return true
} }
if (!isLt) { if (!isLt) {
this.$message.error('上传图片大小不能超过' + limitSize + 'MB!') this.$message.error('上传' + (uploadType == 'img' ? '图片' : '视频') + '大小不能超过' + limitSize + 'MB!')
return true return true
} }
reader.readAsDataURL(file) reader.readAsDataURL(file)
reader.onload = e => { reader.onload = e => {
var image = new Image() if (uploadType == 'img') {
image.src = e.target.result var image = new Image()
image.onload = () => { image.src = e.target.result
var imgWidth = image.width image.onload = () => {
var imgHeight = image.height var imgWidth = image.width
if (targetItem.hasPixel && (imgWidth > wdithLt || imgHeight > heightLt)) { var imgHeight = image.height
this.$message.error('图片尺寸最大为' + wdithLt + '像素*' + heightLt + '像素') if (targetItem.hasPixel && (imgWidth > wdithLt || imgHeight > heightLt)) {
} else { this.$message.error('图片尺寸最大为' + wdithLt + '像素*' + heightLt + '像素')
targetItem.handleUpload(e, file, targetItem) } else {
targetItem.handleUpload(e, file, targetItem)
}
} }
} else {
targetItem.handleUpload(e, file, targetItem)
} }
} }
}, },
...@@ -203,9 +217,12 @@ export default { ...@@ -203,9 +217,12 @@ export default {
this.$emit('handleImgDelete', targetItem) this.$emit('handleImgDelete', targetItem)
}, },
// 图片查看 // 图片查看
handleImgLook(src) { handleImgLook(src, targetItem) {
this.isImgVisible = true this.isImgVisible = true
this.dialogImageUrl = src this.dialogObj = {
url: src,
uploadType: targetItem.uploadType || 'img'
}
} }
} }
} }
...@@ -362,5 +379,14 @@ export default { ...@@ -362,5 +379,14 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.glsx-combi-form .dialog-look {
text-align: center;
}
.glsx-combi-form .dialog-video {
width: 50%;
height: 50%;
}
/* 图片上传 */ /* 图片上传 */
</style> </style>
...@@ -32,6 +32,7 @@ export default { ...@@ -32,6 +32,7 @@ export default {
id: '' id: ''
}, },
editForm: { editForm: {
videoUrl: '',
imgUrls: [], imgUrls: [],
shareContent: '' shareContent: ''
}, },
...@@ -42,6 +43,22 @@ export default { ...@@ -42,6 +43,22 @@ export default {
}, },
editFormData: [ editFormData: [
{ {
label: '视频',
name: 'videoUrl',
type: 'upload',
uploadType: 'video',
limitSize: 50,
maxPhotoNum: 1,
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[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)
})
}
},
{
label: '照片上传', label: '照片上传',
name: 'imgUrls', name: 'imgUrls',
type: 'upload', type: 'upload',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!