mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-25 05:25:04 +00:00
fix: Improve the picture cropping component (#463)
* fix: Improve the picture cropping component * fix: component /verify/rotate text show problem
This commit is contained in:
@@ -69,9 +69,9 @@
|
||||
default: {},
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
setup(props, ctx) {
|
||||
const imgElRef = ref<ElRef<HTMLImageElement>>(null);
|
||||
const cropper = ref<Nullable<Cropper>>(null);
|
||||
const cropper: any = ref<Nullable<Cropper>>(null);
|
||||
|
||||
const isReady = ref(false);
|
||||
|
||||
@@ -106,9 +106,24 @@
|
||||
});
|
||||
}
|
||||
|
||||
// event: return base64 and width and height information after cropping
|
||||
const croppered = (): void => {
|
||||
let imgInfo = cropper.value.getData();
|
||||
cropper.value.getCroppedCanvas().toBlob(blob => {
|
||||
let fileReader: FileReader = new FileReader()
|
||||
fileReader.onloadend = (e: any) => {
|
||||
ctx.emit("cropperedInfo", {
|
||||
imgBase64: e.target.result,
|
||||
imgInfo
|
||||
})
|
||||
}
|
||||
fileReader.readAsDataURL(blob)
|
||||
}, 'image/jpeg')
|
||||
}
|
||||
|
||||
onMounted(init);
|
||||
|
||||
return { imgElRef, getWrapperStyle, getImageStyle, isReady };
|
||||
return { imgElRef, getWrapperStyle, getImageStyle, isReady, croppered };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@@ -152,7 +152,7 @@ export default defineComponent({
|
||||
</span>
|
||||
)}
|
||||
{!state.showTip && !state.draged && (
|
||||
<span class={[`ir-dv-img__tip`, 'normal']}>t('redoTip')</span>
|
||||
<span class={[`ir-dv-img__tip`, 'normal']}>{t('component.verify.redoTip')}</span>
|
||||
)}
|
||||
</div>
|
||||
<BasicDragVerify
|
||||
|
@@ -1,14 +1,17 @@
|
||||
<template>
|
||||
<PageWrapper title="图片裁剪示例" contentBackground>
|
||||
<CropperImage src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg" />
|
||||
<div class="cropper-container">
|
||||
<CropperImage ref="refCropper" src="https://fengyuanchen.github.io/cropperjs/images/picture.jpg" @cropperedInfo="cropperedInfo" style="width:40%" />
|
||||
<a-button type="primary" @click="onCropper"> 裁剪 </a-button>
|
||||
<img :src="cropperImg" class="croppered" v-if="cropperImg" />
|
||||
</div>
|
||||
<p v-if="cropperImg">裁剪后图片信息:{{ info }}</p>
|
||||
</PageWrapper>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { defineComponent, ref, onBeforeMount, getCurrentInstance } from 'vue';
|
||||
import { PageWrapper } from '/@/components/Page';
|
||||
|
||||
import { CropperImage } from '/@/components/Cropper';
|
||||
|
||||
import img from '/@/assets/images/header.jpg';
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -16,7 +19,42 @@
|
||||
CropperImage,
|
||||
},
|
||||
setup() {
|
||||
return { img };
|
||||
let vm: any;
|
||||
let info = ref("");
|
||||
let cropperImg = ref("");
|
||||
|
||||
const onCropper = (): void => {
|
||||
vm.refs.refCropper.croppered();
|
||||
}
|
||||
|
||||
onBeforeMount(()=>{
|
||||
vm = getCurrentInstance();
|
||||
})
|
||||
|
||||
function cropperedInfo({ imgBase64, imgInfo }) {
|
||||
info.value = imgInfo
|
||||
cropperImg.value = imgBase64
|
||||
}
|
||||
|
||||
return {
|
||||
img,
|
||||
info,
|
||||
cropperImg,
|
||||
onCropper,
|
||||
cropperedInfo
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.cropper-container {
|
||||
display:flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
.croppered {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user