Vben
authored
|
1
|
<template>
|
Vben
authored
|
2
3
|
<PageWrapper title="图片裁剪示例" content="需要开启测试接口服务才能进行上传测试!">
<CollapseContainer title="头像裁剪">
|
|
4
|
<CropperAvatar :uploadApi="uploadApi" :value="avatar" />
|
Vben
authored
|
5
6
7
8
9
10
11
|
</CollapseContainer>
<CollapseContainer title="矩形裁剪" class="my-4">
<div class="container p-4">
<div class="cropper-container mr-10">
<CropperImage ref="refCropper" :src="img" @cropend="handleCropend" style="width: 40vw" />
</div>
|
|
12
|
<img :src="cropperImg" class="croppered" v-if="cropperImg" alt="" />
|
Vben
authored
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
</div>
<p v-if="cropperImg">裁剪后图片信息:{{ info }}</p>
</CollapseContainer>
<CollapseContainer title="圆形裁剪">
<div class="container p-4">
<div class="cropper-container mr-10">
<CropperImage
ref="refCropper"
:src="img"
@cropend="handleCircleCropend"
style="width: 40vw"
circled
/>
</div>
<img :src="circleImg" class="croppered" v-if="circleImg" />
|
|
29
|
</div>
|
Vben
authored
|
30
31
|
<p v-if="circleImg">裁剪后图片信息:{{ circleInfo }}</p>
</CollapseContainer>
|
Vben
authored
|
32
33
34
|
</PageWrapper>
</template>
<script lang="ts">
|
Vben
authored
|
35
|
import { defineComponent, ref } from 'vue';
|
Vben
authored
|
36
|
import { PageWrapper } from '/@/components/Page';
|
|
37
|
import { CollapseContainer } from '/@/components/Container';
|
Vben
authored
|
38
39
|
import { CropperImage, CropperAvatar } from '/@/components/Cropper';
import { uploadApi } from '/@/api/sys/upload';
|
Vben
authored
|
40
|
import img from '/@/assets/images/header.jpg';
|
|
41
|
import { useUserStore } from '/@/store/modules/user';
|
|
42
|
|
Vben
authored
|
43
44
45
46
|
export default defineComponent({
components: {
PageWrapper,
CropperImage,
|
Vben
authored
|
47
48
|
CollapseContainer,
CropperAvatar,
|
Vben
authored
|
49
50
|
},
setup() {
|
Vben
authored
|
51
52
53
54
|
const info = ref('');
const cropperImg = ref('');
const circleInfo = ref('');
const circleImg = ref('');
|
|
55
56
|
const userStore = useUserStore();
const avatar = ref(userStore.getUserInfo?.avatar || '');
|
Vben
authored
|
57
|
function handleCropend({ imgBase64, imgInfo }) {
|
Vben
authored
|
58
59
60
|
info.value = imgInfo;
cropperImg.value = imgBase64;
}
|
|
61
|
|
Vben
authored
|
62
63
64
65
66
|
function handleCircleCropend({ imgBase64, imgInfo }) {
circleInfo.value = imgInfo;
circleImg.value = imgBase64;
}
|
|
67
68
69
|
return {
img,
info,
|
Vben
authored
|
70
|
circleInfo,
|
|
71
|
cropperImg,
|
Vben
authored
|
72
73
74
|
circleImg,
handleCropend,
handleCircleCropend,
|
|
75
|
avatar,
|
vben
authored
|
76
|
uploadApi: uploadApi as any,
|
|
77
|
};
|
Vben
authored
|
78
79
80
|
},
});
</script>
|
|
81
82
|
<style scoped>
|
|
83
|
.container {
|
Vben
authored
|
84
|
display: flex;
|
|
85
|
width: 100vw;
|
Vben
authored
|
86
87
88
|
align-items: center;
}
|
|
89
90
91
92
|
.cropper-container {
width: 40vw;
}
|
Vben
authored
|
93
|
.croppered {
|
|
94
95
96
97
98
|
height: 360px;
}
p {
margin: 10px;
|
Vben
authored
|
99
|
}
|
|
100
|
</style>
|