| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="iconShot"> |
| | | <div class="icon-dialog"> |
| | | <div class="clip"> |
| | | <div class="img" ref="img"> |
| | | <vue-cropper |
| | | ref="cropper" |
| | | :img="imgSrc" |
| | | :width="options.width" |
| | | :height="options.height" |
| | | :canScale="options.canScale" |
| | | :autoCrop="options.autoCrop" |
| | | :canMove="options.canMove" |
| | | :output-size="options.outputSize" |
| | | :centerBox="options.centerBox" |
| | | :autoCropWidth="options.autoCropWidth" |
| | | :autoCropHeight="options.autoCropHeight" |
| | | @realTime="realTime" |
| | | ></vue-cropper> |
| | | </div> |
| | | <div class="previews"> |
| | | <img style="width: 150px;height: 150px;border-radius1: 50%;object-fit: cover" :src="cutImgSrc" alt="å¾ç"> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import { VueCropper } from 'vue-cropper' |
| | | import {upload} from "@/api/system/common"; |
| | | export default { |
| | | name: 'ImageCropper', |
| | | components: { VueCropper }, |
| | | props: { |
| | | imgSrc: { |
| | | type: String, |
| | | default: '' |
| | | }, |
| | | // 忾䏿¬¡ä¿åçæªå¾çä½ç½® |
| | | location: { |
| | | type: Object, |
| | | default () { |
| | | return {} |
| | | } |
| | | } |
| | | // iconItem:{ |
| | | // type:Object, |
| | | // default(){ |
| | | // return {}; |
| | | // } |
| | | // } |
| | | }, |
| | | data () { |
| | | return { |
| | | // å¦ä¹ æªå¾é项 |
| | | iconForm: { |
| | | originImgBase64: '', |
| | | imgBase64: '' |
| | | // location: "", |
| | | // matchingName: "", |
| | | // matchingType: "", |
| | | // note: "", |
| | | // picGroupId: "0", |
| | | // tsId: "", |
| | | }, |
| | | // å¨åæªå¾åºåçå¾ç,èªå·±ä¼ |
| | | // imgSrc:'', |
| | | // å¨åæªå¾åççæçbase64å¾ç |
| | | cutImgSrc: '', |
| | | // cropperæä»¶çé
ç½® |
| | | options: { |
| | | canScale: false, |
| | | autoCrop: true, |
| | | canMove: false, |
| | | centerBox: true, |
| | | height: 500, |
| | | width: 500, |
| | | outputSize:{width: 500, height: 500 }, |
| | | autoCropWidth: 500, |
| | | autoCropHeight: 500, |
| | | fixed: true, |
| | | fixedNumber: [1, 1] |
| | | }, |
| | | // æªå¾æ¡ç¸å¯¹å¾ççä½ç½® |
| | | clipAxis: {}, |
| | | // æªå¾åæ¾æ å¿,åªè§¦å䏿¬¡å®ç°åæ¾ï¼ |
| | | flag: true |
| | | } |
| | | }, |
| | | mounted () { |
| | | |
| | | }, |
| | | watch: { |
| | | }, |
| | | methods: { |
| | | getImagecropper(){ |
| | | return this.$refs.cropper |
| | | }, |
| | | // å¦ä¹ æªå¾æ¡ååäºä»¶ |
| | | realTime (data) { |
| | | if (data.h) { |
| | | // è·åå¾çç¸å¯¹å®¹å¨çä½ç½® |
| | | const img = this.$refs.cropper.getImgAxis() |
| | | // è·åæªå¾æ¡ç¸å¯¹å®¹å¨çä½ç½® |
| | | const clip = this.$refs.cropper.getCropAxis() |
| | | this.clipAxis.x = clip.x1 - img.x1 |
| | | this.clipAxis.y = clip.y1 - img.y1 |
| | | // è·åæªå¾å¾ç |
| | | this.$refs.cropper.getCropData(img => { |
| | | this.clipAxis.width = data.w |
| | | this.clipAxis.height = data.h |
| | | this.cutImgSrc = img |
| | | }) |
| | | // è·ååå¾base64çå¾ç |
| | | // this.imageUrlToBase64(data.url); |
| | | |
| | | // 徿 å表ç¼è¾åæ¾(åå§ååªè§¦å䏿¬¡) |
| | | if (this.location.height != undefined && this.flag) { |
| | | this.$nextTick(() => { |
| | | // auto crop |
| | | this.$refs.cropper.goAutoCrop() |
| | | this.$nextTick(() => { |
| | | // if cropped and has position message, update crop box |
| | | this.$refs.cropper.cropOffsertX = this.location.x + img.x1 |
| | | this.$refs.cropper.cropOffsertY = this.location.y + img.y1 |
| | | this.$refs.cropper.cropW = this.location.width |
| | | this.$refs.cropper.cropH = this.location.height |
| | | |
| | | // this.iconForm.location=this.iconItem.location; |
| | | // this.iconForm.matchingName=this.iconItem.matchingName; |
| | | // this.iconForm.matchingType=this.iconItem.matchingType; |
| | | // this.iconForm.note=this.iconItem.note; |
| | | // this.picGroupId=this.iconItem.picGroupId.split(','); |
| | | // this.iconForm.id=this.iconItem.id; |
| | | // this.iconForm.tsId=this.iconItem.tsId; |
| | | this.flag = false |
| | | }) |
| | | }) |
| | | } |
| | | } |
| | | }, |
| | | // åå¾éè¿canvas转为base64çæ ¼å¼ |
| | | imageUrlToBase64 (src) { |
| | | // ä¸å®è¦è®¾ç½®ä¸ºletï¼ä¸ç¶å¾ç䏿¾ç¤º |
| | | const image = new Image() |
| | | // è§£å³è·¨åé®é¢ |
| | | image.setAttribute('crossOrigin', 'anonymous') |
| | | const imageUrl = src |
| | | image.src = imageUrl |
| | | |
| | | // image.onloadä¸ºå¼æ¥å è½½ |
| | | image.onload = () => { |
| | | var canvas = document.createElement('canvas') |
| | | canvas.width = image.width |
| | | canvas.height = image.height |
| | | var context = canvas.getContext('2d') |
| | | context.drawImage(image, 0, 0, image.width, image.height) |
| | | |
| | | // var quality = 0.8; |
| | | // è¿éçdataurlå°±æ¯base64ç±»å |
| | | const dataURL = canvas.toDataURL('image/jpeg')// 使ç¨toDataUrlå°å¾çè½¬æ¢æjpegçæ ¼å¼ |
| | | this.iconForm.originImgBase64 = dataURL |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | .iconShot { |
| | | .icon-dialog { |
| | | .clip { |
| | | display: flex; |
| | | .img { |
| | | flex: 7.5; |
| | | height: 500px; |
| | | //float: left; |
| | | // display: inline-block; |
| | | .vue-cropper { |
| | | background-image: none; |
| | | } |
| | | .cropper-move { |
| | | cursor: default; |
| | | } |
| | | .cropper-face.cropper-move { |
| | | cursor: move; |
| | | } |
| | | |
| | | } |
| | | .previews { |
| | | //width: 100px; |
| | | flex: 2.5; |
| | | //float: right; |
| | | height: 200px; |
| | | //position: relative; |
| | | >img { |
| | | //position: absolute; |
| | | //left: 50%; |
| | | transform: translate(35%, 50px); |
| | | max-height: 100%; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | .icon-options { |
| | | font-size: 12px; |
| | | font-weight: 200; |
| | | >.el-row { |
| | | >.el-col { |
| | | >.el-row { |
| | | height: 36px; |
| | | line-height: 36px; |
| | | >.el-col:nth-child(1) { |
| | | font-weight: 600; |
| | | text-align: right; |
| | | } |
| | | .el-col:nth-child(2) { |
| | | .el-input,.el-select { |
| | | width: 185px !important; |
| | | } |
| | | } |
| | | >.el-col { |
| | | padding: 0 10px; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </style> |