-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathImageViewerUtils.tsx
More file actions
100 lines (94 loc) · 3.44 KB
/
ImageViewerUtils.tsx
File metadata and controls
100 lines (94 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { computed, defineComponent, PropType } from '@vue/composition-api';
import {
ImageIcon, ZoomInIcon, ZoomOutIcon, DownloadIcon, MirrorIcon, RotationIcon,
} from 'tdesign-icons-vue';
import TImageViewerIcon from './ImageModalIcon';
import TToolTip from '../../tooltip';
import { useConfig } from '../../hooks/useConfig';
import { useImagePreviewUrl } from '../../hooks';
import { largeNumberToFixed } from '../../_common/js/input-number/large-number';
import { ImageInfo } from '../type';
const currentImage = {
type: Object as PropType<ImageInfo>,
default() {
return {};
},
};
export default defineComponent({
name: 'TImageViewerUtils',
props: {
scale: Number,
rotateHandler: Function as PropType<() => void>,
zoomInHandler: Function as PropType<() => void>,
zoomOutHandler: Function as PropType<() => void>,
mirrorHandler: Function as PropType<() => void>,
resetHandler: Function as PropType<() => void>,
downloadHandler: Function as PropType<(url: string) => void>,
globalConfig: Object,
currentImage,
},
setup(props) {
const { classPrefix } = useConfig('imageViewer');
const imageUrl = computed(() => props.currentImage.mainImage);
const { previewUrl } = useImagePreviewUrl(imageUrl);
return {
classPrefix,
previewUrl,
};
},
render() {
return (
<div class={`${this.classPrefix}-image-viewer__utils`}>
<div class={`${this.classPrefix}-image-viewer__utils-content`}>
<TToolTip
overlayClassName={`${this.classPrefix}-image-viewer__utils--tip`}
content={this.globalConfig.mirrorTipText}
destroyOnClose
placement="top"
showArrow
theme="default"
>
<TImageViewerIcon clickHandler={this.mirrorHandler} icon={() => <MirrorIcon size="medium" />} />
</TToolTip>
<TToolTip
overlayClassName={`${this.classPrefix}-image-viewer__utils--tip`}
content={this.globalConfig.rotateTipText}
destroyOnClose
placement="top"
showArrow
theme="default"
>
<TImageViewerIcon clickHandler={this.rotateHandler} icon={() => <RotationIcon size="medium" />} />
</TToolTip>
<TImageViewerIcon icon={() => <ZoomOutIcon size="medium" />} clickHandler={this.zoomOutHandler} />
<TImageViewerIcon
class={`${this.classPrefix}-image-viewer__utils-scale`}
size="medium"
label={`${largeNumberToFixed(String(this.scale * 100))}%`}
/>
<TImageViewerIcon icon={() => <ZoomInIcon size="medium" />} clickHandler={this.zoomInHandler} />
<TToolTip
overlayClassName={`${this.classPrefix}-image-viewer__utils--tip`}
content={this.globalConfig.originalSizeTipText}
destroyOnClose
placement="top"
showArrow
theme="default"
>
<div class={`${this.classPrefix}-image-viewer__modal-icon`}>
<TImageViewerIcon icon={() => <ImageIcon size="medium" />} clickHandler={this.resetHandler} />
</div>
</TToolTip>
{this.currentImage.download && (
<TImageViewerIcon
icon={() => <DownloadIcon size="medium" />}
clickHandler={() => {
this.downloadHandler(this.previewUrl);
}}
/>
)}
</div>
</div>
);
},
});