Signed-off-by: 吴文峰 <kevin@lmve.net>
This commit is contained in:
@@ -4,27 +4,75 @@ import { onMounted, ref } from "vue";
|
|||||||
|
|
||||||
import "cropperjs";
|
import "cropperjs";
|
||||||
|
|
||||||
const cro_sele=ref()
|
const cro_sele = ref();
|
||||||
const cro_canv=ref()
|
const cro_canv = ref();
|
||||||
|
const cro_imag = ref();
|
||||||
|
|
||||||
var cor_size_width=400
|
var cor_size_width = 300;
|
||||||
var cor_size_height=400
|
var cor_size_height = 300;
|
||||||
|
|
||||||
|
const is_have_URL = ref(false);
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
initCropper(reader.result);
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
cro_sele.value.$change(0,0,cor_size_width,cor_size_height)
|
cro_sele.value.$change(0, 0, cor_size_width, cor_size_height);
|
||||||
cro_canv.value.style.width=cor_size_width.toString()+"px"
|
cro_canv.value.style.width = cor_size_width.toString() + "px";
|
||||||
cro_canv.value.style.height=cor_size_height.toString()+"px"
|
cro_canv.value.style.height = cor_size_height.toString() + "px";
|
||||||
|
|
||||||
|
cro_imag.value.src = "https://wnfed.com/usr/uploads/2020/07/736937178.jpg";
|
||||||
|
|
||||||
//console.log(cro_canv.value.clientHeight)
|
//console.log(cro_canv.value.clientHeight)
|
||||||
});
|
});
|
||||||
|
|
||||||
function getsele() {}
|
function initCropper(imageSrc){
|
||||||
|
|
||||||
|
is_have_URL.value = true;
|
||||||
|
cro_imag.value.src=imageSrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
function inputfile(e){
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file){
|
||||||
|
e.target.value=""
|
||||||
|
is_have_URL.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.type.startsWith('image/')) {
|
||||||
|
e.target.value=""
|
||||||
|
is_have_URL.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function getsele() {
|
||||||
|
console.log(cro_canv.value.$toCanvas())
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<cropper-canvas ref="cro_canv" class="cropper-container" background scale-step="0.2">
|
<div>
|
||||||
|
<div class="col-6 col-sm-4 col-md-2 col-xl py-3">
|
||||||
|
<input class="btn btn-outline-primary" type="file" accept="image/*" @change="inputfile">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<cropper-canvas
|
||||||
|
ref="cro_canv"
|
||||||
|
class="cropper-container"
|
||||||
|
:hidden="!is_have_URL"
|
||||||
|
background
|
||||||
|
scale-step="0.1"
|
||||||
|
>
|
||||||
<cropper-image
|
<cropper-image
|
||||||
src="https://wnfed.com/usr/uploads/2020/07/736937178.jpg"
|
ref="cro_imag"
|
||||||
|
src=""
|
||||||
alt="Picture"
|
alt="Picture"
|
||||||
initialCenterSize="cover"
|
initialCenterSize="cover"
|
||||||
rotatable
|
rotatable
|
||||||
@@ -34,25 +82,24 @@ function getsele() {}
|
|||||||
></cropper-image>
|
></cropper-image>
|
||||||
<cropper-shade hidden></cropper-shade>
|
<cropper-shade hidden></cropper-shade>
|
||||||
<cropper-handle action="move" plain></cropper-handle>
|
<cropper-handle action="move" plain></cropper-handle>
|
||||||
<cropper-selection
|
<cropper-selection ref="cro_sele">
|
||||||
ref="cro_sele"
|
|
||||||
>
|
|
||||||
<cropper-grid role="grid" covered></cropper-grid>
|
<cropper-grid role="grid" covered></cropper-grid>
|
||||||
<cropper-crosshair centered></cropper-crosshair>
|
<cropper-crosshair centered></cropper-crosshair>
|
||||||
<cropper-handle
|
<cropper-handle
|
||||||
action="move"
|
action="move"
|
||||||
theme-color="rgba(255, 255, 255, 0)"
|
theme-color="rgba(255, 255, 255, 0)"
|
||||||
></cropper-handle>
|
></cropper-handle>
|
||||||
|
|
||||||
</cropper-selection>
|
</cropper-selection>
|
||||||
</cropper-canvas>
|
</cropper-canvas>
|
||||||
<button @click="getsele">getsele</button>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-6 col-sm-4 col-md-2 col-xl py-3">
|
||||||
|
<button class="btn btn-outline-primary" @click="getsele">getsele</button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.cropper-container {
|
.cropper-container {
|
||||||
|
|
||||||
|
|
||||||
/* 四个角相同圆角 */
|
/* 四个角相同圆角 */
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
/* 基本描边 */
|
/* 基本描边 */
|
||||||
|
|||||||
Reference in New Issue
Block a user