feat:【antd/ele】【组件】cropper 封装的代码统一评审
This commit is contained in:
@@ -284,7 +284,6 @@ async function handleOk() {
|
|||||||
class="h-full w-full object-cover"
|
class="h-full w-full object-cover"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 头像组合预览 -->
|
<!-- 头像组合预览 -->
|
||||||
<template v-if="previewSource">
|
<template v-if="previewSource">
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const props = withDefaults(defineProps<CropperAvatarProps>(), {
|
|||||||
const emit = defineEmits(['update:value', 'change']);
|
const emit = defineEmits(['update:value', 'change']);
|
||||||
|
|
||||||
const sourceValue = ref(props.value || '');
|
const sourceValue = ref(props.value || '');
|
||||||
|
// TODO @puhui999:这个有办法去掉么?
|
||||||
const prefixCls = 'cropper-avatar';
|
const prefixCls = 'cropper-avatar';
|
||||||
const [CropperModal, modalApi] = useVbenModal({
|
const [CropperModal, modalApi] = useVbenModal({
|
||||||
connectedComponent: cropperModal,
|
connectedComponent: cropperModal,
|
||||||
@@ -73,12 +74,16 @@ defineExpose({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<!-- TODO @puhui999:html 部分,看看有没办法和 web-antd/src/components/cropper/cropper-avatar.vue 风格更接近 -->
|
||||||
|
<!-- 头像容器 -->
|
||||||
<div :class="getClass" :style="getStyle">
|
<div :class="getClass" :style="getStyle">
|
||||||
|
<!-- 图片包装器 -->
|
||||||
<div
|
<div
|
||||||
:class="`${prefixCls}-image-wrapper`"
|
:class="`${prefixCls}-image-wrapper`"
|
||||||
:style="getImageWrapperStyle"
|
:style="getImageWrapperStyle"
|
||||||
@click="openModal"
|
@click="openModal"
|
||||||
>
|
>
|
||||||
|
<!-- 遮罩层 -->
|
||||||
<div :class="`${prefixCls}-image-mask`" :style="getImageWrapperStyle">
|
<div :class="`${prefixCls}-image-mask`" :style="getImageWrapperStyle">
|
||||||
<span
|
<span
|
||||||
:style="{
|
:style="{
|
||||||
@@ -90,8 +95,10 @@ defineExpose({
|
|||||||
class="icon-[ant-design--cloud-upload-outlined] text-[#d6d6d6]"
|
class="icon-[ant-design--cloud-upload-outlined] text-[#d6d6d6]"
|
||||||
></span>
|
></span>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 头像图片 -->
|
||||||
<img v-if="sourceValue" :src="sourceValue" alt="avatar" />
|
<img v-if="sourceValue" :src="sourceValue" alt="avatar" />
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 上传按钮 -->
|
||||||
<ElButton
|
<ElButton
|
||||||
v-if="showBtn"
|
v-if="showBtn"
|
||||||
:class="`${prefixCls}-upload-btn`"
|
:class="`${prefixCls}-upload-btn`"
|
||||||
@@ -111,6 +118,7 @@ defineExpose({
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
/* TODO @puhui999:要类似 web-antd/src/components/cropper/cropper-avatar.vue 减少 scss,通过 tindwind 么? */
|
||||||
.cropper-avatar {
|
.cropper-avatar {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -121,7 +121,9 @@ async function handleOk() {
|
|||||||
class="w-[800px]"
|
class="w-[800px]"
|
||||||
>
|
>
|
||||||
<div :class="prefixCls">
|
<div :class="prefixCls">
|
||||||
|
<!-- 左侧区域 -->
|
||||||
<div :class="`${prefixCls}-left`" class="w-full">
|
<div :class="`${prefixCls}-left`" class="w-full">
|
||||||
|
<!-- 裁剪器容器 -->
|
||||||
<div :class="`${prefixCls}-cropper`">
|
<div :class="`${prefixCls}-cropper`">
|
||||||
<CropperImage
|
<CropperImage
|
||||||
v-if="src"
|
v-if="src"
|
||||||
@@ -133,6 +135,7 @@ async function handleOk() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 工具栏 -->
|
||||||
<div :class="`${prefixCls}-toolbar`">
|
<div :class="`${prefixCls}-toolbar`">
|
||||||
<ElUpload
|
<ElUpload
|
||||||
:before-upload="handleBeforeUpload"
|
:before-upload="handleBeforeUpload"
|
||||||
@@ -276,7 +279,10 @@ async function handleOk() {
|
|||||||
</ElSpace>
|
</ElSpace>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧区域 -->
|
||||||
<div :class="`${prefixCls}-right`">
|
<div :class="`${prefixCls}-right`">
|
||||||
|
<!-- 预览区域 -->
|
||||||
<div :class="`${prefixCls}-preview`">
|
<div :class="`${prefixCls}-preview`">
|
||||||
<img
|
<img
|
||||||
v-if="previewSource"
|
v-if="previewSource"
|
||||||
@@ -284,6 +290,7 @@ async function handleOk() {
|
|||||||
:src="previewSource"
|
:src="previewSource"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 头像组合预览 -->
|
||||||
<template v-if="previewSource">
|
<template v-if="previewSource">
|
||||||
<div :class="`${prefixCls}-group`">
|
<div :class="`${prefixCls}-group`">
|
||||||
<ElAvatar :src="previewSource" size="large" />
|
<ElAvatar :src="previewSource" size="large" />
|
||||||
@@ -298,6 +305,7 @@ async function handleOk() {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
/* TODO @puhui999:要类似 web-antd/src/components/cropper/cropper-avatar.vue 减少 scss,通过 tindwind 么? */
|
||||||
.cropper-am {
|
.cropper-am {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const imgElRef = ref<ElRef<HTMLImageElement>>();
|
|||||||
const cropper = ref<Cropper | null>();
|
const cropper = ref<Cropper | null>();
|
||||||
const isReady = ref(false);
|
const isReady = ref(false);
|
||||||
|
|
||||||
|
// TODO @puhui999:这个有办法去掉么?
|
||||||
const prefixCls = 'cropper-image';
|
const prefixCls = 'cropper-image';
|
||||||
const debounceRealTimeCropped = useDebounceFn(realTimeCropped, 80);
|
const debounceRealTimeCropped = useDebounceFn(realTimeCropped, 80);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user