Skip to content

Commit 0df8734

Browse files
committed
remove redundant code
1 parent 29443ae commit 0df8734

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

components/vc-image/src/Image.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ const ImageInternal = defineComponent({
107107
value: previewVisible,
108108
onChange: onPreviewVisibleChange,
109109
});
110-
watch(previewVisible, val => {
111-
setShowPreview(Boolean(val));
112-
});
110+
113111
watch(isShowPreview, (val, preVal) => {
114112
onPreviewVisibleChange(val, preVal);
115113
});

components/vc-image/src/PreviewGroup.tsx

+10-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ref, provide, defineComponent, inject, watch, reactive, computed, watch
33
import { type ImagePreviewType, mergeDefaultValue } from './Image';
44
import Preview from './Preview';
55
import type { PreviewProps } from './Preview';
6+
import useMergedState from '../../_util/hooks/useMergedState';
67

78
export interface PreviewGroupPreview
89
extends Omit<ImagePreviewType, 'icons' | 'mask' | 'maskClassName'> {
@@ -85,10 +86,14 @@ const Group = defineComponent({
8586
const current = ref<number>();
8687

8788
const previewVisible = computed(() => preview.value.visible);
88-
const onPreviewVisibleChange = computed(() => preview.value.onVisibleChange);
8989
const getPreviewContainer = computed(() => preview.value.getContainer);
90-
91-
const isShowPreview = ref(!!previewVisible.value);
90+
const onPreviewVisibleChange = (val, preval) => {
91+
preview.value.onVisibleChange?.(val, preval);
92+
};
93+
const [isShowPreview, setShowPreview] = useMergedState(!!previewVisible.value, {
94+
value: previewVisible,
95+
onChange: onPreviewVisibleChange,
96+
});
9297

9398
const mousePosition = ref<{ x: number; y: number }>(null);
9499
const isControlled = computed(() => previewVisible.value !== undefined);
@@ -115,9 +120,6 @@ const Group = defineComponent({
115120
const setMousePosition = (val: null | { x: number; y: number }) => {
116121
mousePosition.value = val;
117122
};
118-
const setShowPreview = (val: boolean) => {
119-
isShowPreview.value = val;
120-
};
121123

122124
const registerImage = (id: number, url: string, canPreview = true) => {
123125
const unRegister = () => {
@@ -132,16 +134,10 @@ const Group = defineComponent({
132134

133135
const onPreviewClose = (e: any) => {
134136
e?.stopPropagation();
135-
isShowPreview.value = false;
136-
mousePosition.value = null;
137+
setShowPreview(false);
138+
setMousePosition(null);
137139
};
138140

139-
watch(previewVisible, () => {
140-
isShowPreview.value = !!previewVisible.value;
141-
});
142-
watch(isShowPreview, (val, preVal) => {
143-
onPreviewVisibleChange.value(val, preVal);
144-
});
145141
watch(
146142
currentControlledKey,
147143
val => {

0 commit comments

Comments
 (0)