-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ImageViewer component and add ImageViewer demo
- Loading branch information
1 parent
a18ad8f
commit af9fc0a
Showing
9 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ImageViewer from './src/ImageViewer.vue' | ||
import { isClient } from '@/utils/is' | ||
import { createVNode, render, VNode } from 'vue' | ||
import { ImageViewerProps } from './src/types' | ||
|
||
let instance: Nullable<VNode> = null | ||
|
||
export function createImageViewer(options: ImageViewerProps) { | ||
if (!isClient) return | ||
const { | ||
urlList, | ||
initialIndex = 0, | ||
infinite = true, | ||
hideOnClickModal = false, | ||
appendToBody = false, | ||
zIndex = 2000, | ||
show = true | ||
} = options | ||
|
||
const propsData: Partial<ImageViewerProps> = {} | ||
const container = document.createElement('div') | ||
propsData.urlList = urlList | ||
propsData.initialIndex = initialIndex | ||
propsData.infinite = infinite | ||
propsData.hideOnClickModal = hideOnClickModal | ||
propsData.appendToBody = appendToBody | ||
propsData.zIndex = zIndex | ||
propsData.show = show | ||
|
||
document.body.appendChild(container) | ||
instance = createVNode(ImageViewer, propsData) | ||
render(instance, container) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script setup lang="ts"> | ||
import { ElImageViewer } from 'element-plus' | ||
import { computed, ref } from 'vue' | ||
import { imageViewerProps } from './props' | ||
const props = defineProps(imageViewerProps) | ||
const getBindValue = computed(() => { | ||
const propsData: Recordable = { ...props } | ||
delete propsData.show | ||
return propsData | ||
}) | ||
const show = ref(props.show) | ||
const close = () => { | ||
show.value = false | ||
} | ||
</script> | ||
|
||
<template> | ||
<ElImageViewer v-if="show" v-bind="getBindValue" @close="close" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PropType } from 'vue' | ||
|
||
export const imageViewerProps = { | ||
urlList: { | ||
type: Array as PropType<string[]>, | ||
default: (): string[] => [] | ||
}, | ||
zIndex: { | ||
type: Number as PropType<number>, | ||
default: 2000 | ||
}, | ||
initialIndex: { | ||
type: Number as PropType<number>, | ||
default: 0 | ||
}, | ||
infinite: { | ||
type: Boolean as PropType<boolean>, | ||
default: true | ||
}, | ||
hideOnClickModal: { | ||
type: Boolean as PropType<boolean>, | ||
default: false | ||
}, | ||
appendToBody: { | ||
type: Boolean as PropType<boolean>, | ||
default: false | ||
}, | ||
show: { | ||
type: Boolean as PropType<boolean>, | ||
default: false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface ImageViewerProps { | ||
urlList?: string[] | ||
zIndex?: number | ||
initialIndex?: number | ||
infinite?: boolean | ||
hideOnClickModal?: boolean | ||
appendToBody?: boolean | ||
show?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script setup lang="ts"> | ||
import { ContentWrap } from '@/components/ContentWrap' | ||
import { createImageViewer } from '@/components/ImageViewer' | ||
import { ElButton } from 'element-plus' | ||
import { useI18n } from '@/hooks/web/useI18n' | ||
const { t } = useI18n() | ||
const open = () => { | ||
createImageViewer({ | ||
urlList: [ | ||
'https://img1.baidu.com/it/u=657828739,1486746195&fm=26&fmt=auto&gp=0.jpg', | ||
'https://img0.baidu.com/it/u=3114228356,677481409&fm=26&fmt=auto&gp=0.jpg', | ||
'https://img1.baidu.com/it/u=508846955,3814747122&fm=26&fmt=auto&gp=0.jpg', | ||
'https://img1.baidu.com/it/u=3536647690,3616605490&fm=26&fmt=auto&gp=0.jpg', | ||
'https://img1.baidu.com/it/u=4087287201,1148061266&fm=26&fmt=auto&gp=0.jpg', | ||
'https://img2.baidu.com/it/u=3429163260,2974496379&fm=26&fmt=auto&gp=0.jpg' | ||
] | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<ContentWrap | ||
:title="t('imageViewerDemo.imageViewer')" | ||
:message="t('imageViewerDemo.imageViewerDes')" | ||
> | ||
<ElButton type="primary" @click="open">{{ t('imageViewerDemo.open') }}</ElButton> | ||
</ContentWrap> | ||
</template> |