|
|
@ -9,10 +9,11 @@ |
|
|
|
<el-upload |
|
|
|
<el-upload |
|
|
|
v-if="item.type === 'upload'" |
|
|
|
v-if="item.type === 'upload'" |
|
|
|
class="uploader" |
|
|
|
class="uploader" |
|
|
|
accept=".jpg,.png,.jpeg" |
|
|
|
accept=".jpg,.png,.jpeg,.gif" |
|
|
|
:on-success="res => uploadSuccess(res, data.form)" |
|
|
|
:on-change="res => changeFile(res, data.form)" |
|
|
|
:show-file-list="false" |
|
|
|
:show-file-list="false" |
|
|
|
:action="api.upload"> |
|
|
|
:action="api.upload" |
|
|
|
|
|
|
|
:auto-upload="false"> |
|
|
|
<img v-if="data.form[item.prop]" :src="data.form[item.prop]" class="avatar"> |
|
|
|
<img v-if="data.form[item.prop]" :src="data.form[item.prop]" class="avatar"> |
|
|
|
<div class="uploader-default" v-else> |
|
|
|
<div class="uploader-default" v-else> |
|
|
|
<i class="el-icon-plus"></i> |
|
|
|
<i class="el-icon-plus"></i> |
|
|
@ -39,17 +40,32 @@ |
|
|
|
<el-button type="primary" @click="contentSubmit">确定</el-button> |
|
|
|
<el-button type="primary" @click="contentSubmit">确定</el-button> |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</el-dialog> |
|
|
|
</el-dialog> |
|
|
|
|
|
|
|
|
|
|
|
<Link ref="link" :visible.sync="linkVisible" :data.sync="linkForm" @linkSubmit="linkSubmit" /> |
|
|
|
<Link ref="link" :visible.sync="linkVisible" :data.sync="linkForm" @linkSubmit="linkSubmit" /> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 剪裁组件弹窗 --> |
|
|
|
|
|
|
|
<el-dialog title="图片裁剪" append-to-body :visible.sync="cropperModel" width="1100px" :close-on-click-modal="false"> |
|
|
|
|
|
|
|
<Cropper |
|
|
|
|
|
|
|
ref="cropper" |
|
|
|
|
|
|
|
:img-file.sync="file" |
|
|
|
|
|
|
|
:is-upload="isUpload" |
|
|
|
|
|
|
|
:fixed="fixed" |
|
|
|
|
|
|
|
:fixedNumber.sync="fixedNumber" |
|
|
|
|
|
|
|
@upload="customUpload" /> |
|
|
|
|
|
|
|
</el-dialog> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import Link from '@/components/modules/link' |
|
|
|
import Link from '@/components/modules/link' |
|
|
|
import Util from '@/libs/util' |
|
|
|
import Util from '@/libs/util' |
|
|
|
|
|
|
|
import Cropper from '@/components/img-upload/Cropper' |
|
|
|
|
|
|
|
import Axios from 'axios' |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
props: ['data', 'visible'], |
|
|
|
props: ['data', 'visible'], |
|
|
|
components: { |
|
|
|
components: { |
|
|
|
Link |
|
|
|
Link, |
|
|
|
|
|
|
|
Cropper |
|
|
|
}, |
|
|
|
}, |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
@ -57,6 +73,13 @@ export default { |
|
|
|
linkVisible: false, |
|
|
|
linkVisible: false, |
|
|
|
linkForm: {}, |
|
|
|
linkForm: {}, |
|
|
|
curIndex: 0, |
|
|
|
curIndex: 0, |
|
|
|
|
|
|
|
cropperModel: false, |
|
|
|
|
|
|
|
isUpload: false, |
|
|
|
|
|
|
|
file: {}, // 当前被选择的图片文件 |
|
|
|
|
|
|
|
fileId: '', |
|
|
|
|
|
|
|
curForm: {}, |
|
|
|
|
|
|
|
fixed: false, |
|
|
|
|
|
|
|
fixedNumber: [0.88, 1] |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
watch: { |
|
|
@ -75,6 +98,14 @@ export default { |
|
|
|
// 这两张类型的模块才需要处理参数 |
|
|
|
// 这两张类型的模块才需要处理参数 |
|
|
|
if (type === 'form' || type === 'introduce') { |
|
|
|
if (type === 'form' || type === 'introduce') { |
|
|
|
forms.map(e => { |
|
|
|
forms.map(e => { |
|
|
|
|
|
|
|
if (e.type === 'upload') { |
|
|
|
|
|
|
|
if (e.fixedNumber) { |
|
|
|
|
|
|
|
this.fixed = true |
|
|
|
|
|
|
|
this.fixedNumber = e.fixedNumber |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.fixed = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (e.required) { |
|
|
|
if (e.required) { |
|
|
|
this.rules[e.prop] = [ |
|
|
|
this.rules[e.prop] = [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -90,12 +121,88 @@ export default { |
|
|
|
close() { |
|
|
|
close() { |
|
|
|
this.$emit('update:visible', false) |
|
|
|
this.$emit('update:visible', false) |
|
|
|
}, |
|
|
|
}, |
|
|
|
// 上传成功 |
|
|
|
// 图片裁剪上传事件 |
|
|
|
uploadSuccess(res, row) { |
|
|
|
customUpload(data) { |
|
|
|
// let url = this.form.columnBanner |
|
|
|
const blob = this.dataURItoBlob(data) |
|
|
|
// url && this.$del(this.api.delFile, [url.split('/').pop()]).then(res => {}).catch(e => {}) |
|
|
|
const formData = new FormData() |
|
|
|
this.$set(row, 'pic', res.url) |
|
|
|
formData.append('file', blob, this.file.name) |
|
|
|
// row.pic = res.url |
|
|
|
this.imgUpload(formData) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 压缩图片 |
|
|
|
|
|
|
|
compress(img) { |
|
|
|
|
|
|
|
const canvas = document.createElement('canvas') |
|
|
|
|
|
|
|
const ctx = canvas.getContext('2d') |
|
|
|
|
|
|
|
// let initSize = img.src.length; |
|
|
|
|
|
|
|
const width = img.width |
|
|
|
|
|
|
|
const height = img.height |
|
|
|
|
|
|
|
canvas.width = width |
|
|
|
|
|
|
|
canvas.height = height |
|
|
|
|
|
|
|
// 铺底色 |
|
|
|
|
|
|
|
ctx.fillStyle = '#fff' |
|
|
|
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height) |
|
|
|
|
|
|
|
ctx.drawImage(img, 0, 0, width, height) |
|
|
|
|
|
|
|
// 进行压缩 |
|
|
|
|
|
|
|
const ndata = canvas.toDataURL('image/jpeg', 0.8) |
|
|
|
|
|
|
|
return ndata |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// base64转成bolb对象 |
|
|
|
|
|
|
|
dataURItoBlob(base64Data) { |
|
|
|
|
|
|
|
let byteString |
|
|
|
|
|
|
|
if (base64Data.split(',')[0].indexOf('base64') >= 0) { |
|
|
|
|
|
|
|
byteString = atob(base64Data.split(',')[1]) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
byteString = unescape(base64Data.split(',')[1]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const mimeString = base64Data |
|
|
|
|
|
|
|
.split(',')[0] |
|
|
|
|
|
|
|
.split(':')[1] |
|
|
|
|
|
|
|
.split(';')[0] |
|
|
|
|
|
|
|
const ia = new Uint8Array(byteString.length) |
|
|
|
|
|
|
|
for (let i = 0; i < byteString.length; i++) { |
|
|
|
|
|
|
|
ia[i] = byteString.charCodeAt(i) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new Blob([ia], { |
|
|
|
|
|
|
|
type: mimeString |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 图片上传到服务器 |
|
|
|
|
|
|
|
imgUpload(formData) { |
|
|
|
|
|
|
|
this.isUpload = true |
|
|
|
|
|
|
|
Axios({ |
|
|
|
|
|
|
|
method: 'post', |
|
|
|
|
|
|
|
url: this.api.upload, |
|
|
|
|
|
|
|
data: formData, |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
'Content-Type': 'multipart/form-data' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}).then(({ data }) => { |
|
|
|
|
|
|
|
this.$set(this.curForm, 'pic', data.url) |
|
|
|
|
|
|
|
}).catch(res => {}) |
|
|
|
|
|
|
|
this.$refs.cropper.isDisabled = false |
|
|
|
|
|
|
|
this.isUpload = false |
|
|
|
|
|
|
|
this.cropperModel = false |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 图片改变钩子 |
|
|
|
|
|
|
|
changeFile(file, form) { |
|
|
|
|
|
|
|
const { size, name } = file |
|
|
|
|
|
|
|
const ext = name.substring(name.lastIndexOf('.') + 1) |
|
|
|
|
|
|
|
if (!Util.isImg(ext)) { |
|
|
|
|
|
|
|
this.$message.error('请上传图片!') |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (size / 1024 / 1024 > 5) { |
|
|
|
|
|
|
|
this.$message.error('请上传5M以内的图片!') |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.file = file |
|
|
|
|
|
|
|
this.curForm = form |
|
|
|
|
|
|
|
this.cropperModel = true |
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
|
|
this.$refs.cropper.updateImg({ |
|
|
|
|
|
|
|
url: window.URL.createObjectURL(file.raw), |
|
|
|
|
|
|
|
size: file.size |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
// 展示链接设置 |
|
|
|
// 展示链接设置 |
|
|
|
toLink(row, i = 0) { |
|
|
|
toLink(row, i = 0) { |
|
|
|