Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ScreenShot #3826

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"dayjs": "^1.11.10",
"echarts": "^5.5.0",
"exceljs": "^4.4.0",
"html2canvas": "^1.4.1",
"lodash-es": "^4.17.21",
"mockjs": "^1.1.0",
"nprogress": "^0.2.0",
Expand Down
46 changes: 46 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/locales/lang/en/routes/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"feat": {
"feat": "Page Function",
"icon": "Icon",
"screenShot": "Screen Shot",
"tabs": "Tabs",
"tabDetail": "Tab Detail",
"sessionTimeout": "Session Timeout",
Expand Down Expand Up @@ -176,4 +177,4 @@
"resizeParentHeightTable": "resizeParentHeightTable",
"vxeTable": "VxeTable"
}
}
}
3 changes: 2 additions & 1 deletion src/locales/lang/zh-CN/routes/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"feat": {
"feat": "功能",
"icon": "图标",
"screenShot": "截图",
"sessionTimeout": "登录过期",
"tabs": "标签页操作",
"tabDetail": "标签详情页",
Expand Down Expand Up @@ -175,4 +176,4 @@
"resizeParentHeightTable": "继承父元素高度",
"vxeTable": "VxeTable"
}
}
}
8 changes: 8 additions & 0 deletions src/router/routes/modules/demo/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const feat: AppRouteModule = {
title: t('routes.demo.feat.icon'),
},
},
{
path: 'screenshot',
name: 'Screenshot',
component: () => import('@/views/demo/feat/screenshot/index.vue'),
meta: {
title: t('routes.demo.feat.screenShot'),
},
},
{
path: 'ws',
name: 'WebSocket',
Expand Down
49 changes: 49 additions & 0 deletions src/views/demo/feat/screenshot/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<PageWrapper title="截图示例">
<Row :gutter="24">
<Col :span="3">
<Card title="截图">
<a-button type="primary" @click="screenShot">点击截图</a-button>
<div class="mt-8" v-show="open">
<a-button type="primary" @click="Dele">点击删除</a-button>
</div>
</Card>
</Col>
<Col :span="21">
<Card title="截图内容" v-show="open">
<div ref="picture"></div>
</Card>
</Col>
</Row>
</PageWrapper>
</template>
<script lang="ts" setup>
import { PageWrapper } from '@/components/Page';
import html2canvas from 'html2canvas';
import { ref } from 'vue';
import { Card, Col, Row } from 'ant-design-vue';

const picture = ref();
const open = ref(false);
function screenShot() {
if (open.value) {
return;
}
html2canvas(document.body, {
backgroundColor: '#ffffff',
allowTaint: true, //开启跨域
useCORS: true,
scrollY: 0,
scrollX: 0,
}).then(function (canvas) {
canvas.style.width = '100%';
canvas.style.height = '100%';
picture.value.appendChild(canvas);
open.value = true;
});
}
function Dele() {
picture.value.innerHTML = '';
open.value = false;
}
</script>
Loading