Skip to content

Commit

Permalink
feat: 加上图片预览函数调用
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Sep 27, 2022
1 parent ee56698 commit 4d10803
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template
src/components/meKeepAlive
dist
vite.config.ts.*
src/components/meVxeTable/vxe-table-plugin-element
vite.config.ts.*
24 changes: 24 additions & 0 deletions src/components/service/meImageViewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ElImageViewer } from 'element-plus';
import { createVNode, render } from 'vue';
//函数组件只能以服务的方式调用
export function createImageViewer(props: ComponentProps<typeof ElImageViewer>) {
const container = document.createElement('div');
const vnode = createVNode(
ElImageViewer,
Object.assign(
{
onClose: function () {
render(null, container);
if (typeof props.onClose === 'function') {
props.onClose.call(this);
}
},
},
props,
),
);
render(vnode, container);
// instances will remove this item when close function gets called. So we do not need to worry about it.
document.body.appendChild(container.firstElementChild!);
return vnode;
}
3 changes: 2 additions & 1 deletion src/locales/lang/en/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"表格": "Table",
"自定义表单": "Custom Form",
"数字动画": "Digital Animation",
"角色权限": "Role Permission"
"角色权限": "Role Permission",
"图片预览": "Image Viewer"
}
8 changes: 8 additions & 0 deletions src/router/routes/components/4-imageViewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { RouteRecordRaw } from 'vue-router';
export const routes: RouteRecordRaw[] = [
{
path: 'imageViewer',
component: () => import('@/views/components/imageViewer.vue'),
meta: { title: '图片预览' },
},
];
16 changes: 16 additions & 0 deletions src/views/components/imageViewer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div class="image-viewer">
<el-button @click="show()"> 预览 </el-button>
</div>
</template>
<script setup lang="ts" name="ImageViewer">
import { createImageViewer } from '@/components/service/meImageViewer';
const show = () =>
createImageViewer({
urlList: [
'https://scpic.chinaz.net/Files/pic/pic6/pic1281.jpg',
'https://scpic.chinaz.net/files/pic/pic9/202009/apic27858.jpg',
'https://tse3-mm.cn.bing.net/th/id/OIP-C.n0_p3rYRuofABd3XudbZnAHaEo?pid=ImgDet&rs=1',
],
});
</script>

0 comments on commit 4d10803

Please sign in to comment.