mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 04:10:20 +08:00
perf(cropper-avatar): code optimization
This commit is contained in:
parent
b7c7c46853
commit
6dbbdbac76
@ -16,7 +16,7 @@
|
||||
import Cropper from 'cropperjs';
|
||||
import 'cropperjs/dist/cropper.css';
|
||||
import { useDesign } from '/@/hooks/web/useDesign';
|
||||
import { useThrottleFn } from '@vueuse/shared';
|
||||
import { useDebounceFn } from '@vueuse/shared';
|
||||
|
||||
type Options = Cropper.Options;
|
||||
|
||||
@ -47,7 +47,6 @@
|
||||
src: { type: String, required: true },
|
||||
alt: { type: String },
|
||||
circled: { type: Boolean, default: false },
|
||||
|
||||
realTimePreview: { type: Boolean, default: true },
|
||||
height: { type: [String, Number], default: '360px' },
|
||||
crossorigin: {
|
||||
@ -68,7 +67,7 @@
|
||||
const isReady = ref(false);
|
||||
|
||||
const { prefixCls } = useDesign('cropper-image');
|
||||
const throttleRealTimeCroppered = useThrottleFn(realTimeCroppered, 80);
|
||||
const debounceRealTimeCroppered = useDebounceFn(realTimeCroppered, 80);
|
||||
|
||||
const getImageStyle = computed((): CSSProperties => {
|
||||
return {
|
||||
@ -107,13 +106,13 @@
|
||||
emit('ready', cropper.value);
|
||||
},
|
||||
crop() {
|
||||
throttleRealTimeCroppered();
|
||||
debounceRealTimeCroppered();
|
||||
},
|
||||
zoom() {
|
||||
throttleRealTimeCroppered();
|
||||
debounceRealTimeCroppered();
|
||||
},
|
||||
cropmove() {
|
||||
throttleRealTimeCroppered();
|
||||
debounceRealTimeCroppered();
|
||||
},
|
||||
...props.options,
|
||||
});
|
||||
|
@ -18,9 +18,8 @@
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
|
||||
const props = {
|
||||
src: { type: String, required: true },
|
||||
width: { type: [String, Number], default: '200px' },
|
||||
uploadApi: { type: Function as PropType<({ file: Blob, name: stirng }) => Promise<void>> },
|
||||
uploadApi: { type: Function as PropType<({ file: Blob, name: string }) => Promise<void>> },
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<PageWrapper title="图片裁剪示例" content="需要开启测试接口服务才能进行上传测试!">
|
||||
<CollapseContainer title="头像裁剪">
|
||||
<CropperAvatar :src="cropperImg" :uploadApi="uploadApi" />
|
||||
<CropperAvatar :uploadApi="uploadApi" />
|
||||
</CollapseContainer>
|
||||
|
||||
<CollapseContainer title="矩形裁剪" class="my-4">
|
||||
|
Loading…
Reference in New Issue
Block a user