Commit ee16aa03 authored by yf's avatar yf

增加四色图导出

parent 17699257
......@@ -144,7 +144,21 @@ export const dynamicRoutes = [
path: 'index/:id(\\d+)',
component: () => import('@/views/risk/plan/ledgerdata'),
name: 'ledgerdata',
meta: { title: '台账数据', activeMenu: '/risk/plan/ledgerdata' }
meta: { title: '任务详情', activeMenu: '/risk/plan/ledgerdata' }
}
]
},
{
path: '/risk/drawCanvas/index',
component: Layout,
hidden: true,
permissions: ['system:ledgerRoom:list'],
children: [
{
path: 'index/:id(\\d+)',
component: () => import('@/views/risk/drawCanvas/index'),
name: 'drawCanvas',
meta: { title: '四色图', activeMenu: '/risk/drawCanvas/index' }
}
]
},
......
......@@ -4,6 +4,7 @@
<img src="../../assets/imgs/north.png" alt="" />
</div> -->
<grid-layout
id="gridView"
:layout.sync="layout"
:col-num="colNum"
:row-height="30"
......@@ -27,7 +28,7 @@
@moved="movedEvent"
:style="{
backgroundColor: item.c,
border: item.type == 'thorough' ? 'none !important' : ''
border: item.type == 'thorough' ? 'none !important' : '',
}"
>
<span class="text" :class="item.w > item.h * 5 ? '' : 'rowText'">{{
......@@ -36,19 +37,25 @@
<!-- <span class="remove" @click="removeItem(item.i)" v-if="item.i && isEdit">x</span> -->
</grid-item>
</grid-layout>
<el-row style="margin-top: 20px; margin-left: 20px">
<el-button type="primary" @click="getPdf">导 出</el-button>
<el-button @click="cancelDraw">取 消</el-button>
</el-row>
</div>
</template>
<script>
import html2Canvas from "html2canvas";
import JsPDF from "jspdf";
import { GridLayout, GridItem } from "vue-grid-layout";
import { ledgerRoomList ,getDictList} from "@/api/risk/draw";
import { ledgerRoomList, getDictList } from "@/api/risk/draw";
// 动态添加/删除
export default {
name: "riskView",
components: {
GridLayout,
GridItem
GridItem,
},
data() {
return {
......@@ -78,14 +85,14 @@ export default {
isBase: false,
baseName: "",
baseArr: [],
layoutData: []
layoutData: [],
};
},
props: {
isView: {
type: Boolean,
default: false
}
default: false,
},
},
mounted() {
// screenfull.toggle(this.$refs.mapbox);
......@@ -110,6 +117,53 @@ export default {
this.getRoomInfo();
},
methods: {
getPdf() {
var title = "四色图";
// html2Canvas(document.querySelector('#pdfDom'), { //这是在界面上设置一个id
//只下载id为pdfDom的内容
html2Canvas(document.querySelector("#gridView"), {
//body是下载整个界面
useCORS: true, //是否尝试使用CORS从服务器加载图像
allowTaint: true,
dpi: 300, //解决生产图片模糊
// width: 490, //canvas宽度
// height: 240, //canvas高度
// x: 0, //x坐标
// y: 0, //y坐标
async: false, //是否异步解析和呈现元素
foreignObjectRendering: true, //是否在浏览器支持的情况下使用ForeignObject渲染
}).then(function (canvas) {
console.log(canvas);
let contentWidth = canvas.width;
let contentHeight = canvas.height;
let pageHeight = (contentWidth / 592.28) * 841.89; // 一页pdf显示html页面生成的canvas高度;
let leftHeight = contentHeight; //未生成pdf的html页面高度
let position = 0; //pdf页面偏移
//a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
let imgWidth = 595.28;
let imgHeight = (592.28 / contentWidth) * contentHeight;
let pageData = canvas.toDataURL("image/jpeg", 1.0);
let PDF = new JsPDF("", "pt", "a4");
// 有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
//当内容未超过pdf一页显示的范围,无需分页
if (leftHeight < pageHeight) {
PDF.addImage(pageData, "JPEG", 0, 0, imgWidth, imgHeight);
} else {
while (leftHeight > 0) {
PDF.addImage(pageData, "JPEG", 20, position, imgWidth, imgHeight);
leftHeight -= pageHeight;
position -= 841.89;
if (leftHeight > 0) {
PDF.addPage();
}
}
}
PDF.save(title + ".pdf");
});
},
cancelDraw() {
this.$router.go(-1);
},
orientationChange() {
if (window.orientation === 180 || window.orientation === 0) {
console.log("竖屏状态!");
......@@ -179,14 +233,14 @@ export default {
},
getRoomInfo() {
let data = {
floorId: this.$route.params.floorId ? this.$route.params.floorId : "4"
floorId: this.$route.params.floorId ? this.$route.params.floorId : "4",
};
ledgerRoomList(data)
.then(res => {
ledgerRoomList(data)
.then((res) => {
if (res.code == 200) {
this.layout = [];
this.layoutData = res.data;
res.data.forEach(item => {
res.data.forEach((item) => {
item.position = JSON.parse(item.position);
item.position.i = item.id;
item.position.id = item.id;
......@@ -198,49 +252,49 @@ export default {
// //添加页面不显示颜色
// item.position.c = "#e6e5e5";
// } else {
/**
* 根据风险评分来匹配相应的颜色
* score 风险评分字段
*/
// item.score = Number(item.score)
// if (item.score>=21 && item.score <= 27) { //优
// item.position.c = this.colorList[3]
// }else if(item.score>=14 && item.score <=20){ //良
// item.position.c = this.colorList[2]
// }else if (item.score>=7&& item.score <= 13) { //中
// item.position.c = this.colorList[1]
// }else if (item.score>=0 && item.score <= 6) { //差
// item.position.c = this.colorList[0]
// }
item.position.c = this.colorList[Math.floor(Math.random() * 4)];
/**
* 根据风险评分来匹配相应的颜色
* score 风险评分字段
*/
// item.score = Number(item.score)
// if (item.score>=21 && item.score <= 27) { //优
// item.position.c = this.colorList[3]
// }else if(item.score>=14 && item.score <=20){ //良
// item.position.c = this.colorList[2]
// }else if (item.score>=7&& item.score <= 13) { //中
// item.position.c = this.colorList[1]
// }else if (item.score>=0 && item.score <= 6) { //差
// item.position.c = this.colorList[0]
// }
item.position.c = this.colorList[Math.floor(Math.random() * 4)];
// }
this.layout.push(item.position);
});
// console.log('layout==>>',this.layout)
}
})
.catch(err => {
.catch((err) => {
console.log("err==>>", err);
});
// getDictList({
// dictType: "risk_plan_room_type"
// }).then(res => {
// this.roomArr = res.data;
// });
// getDictList({
// dictType: "risk_plan_base_room"
// }).then(res => {
// this.baseArr = res.data;
// });
// getDictList({
// dictType: "risk_plan_room_type"
// }).then(res => {
// this.roomArr = res.data;
// });
// getDictList({
// dictType: "risk_plan_base_room"
// }).then(res => {
// this.baseArr = res.data;
// });
},
// 增加
addItem() {
if (this.layout.find(item => item.i == "")) {
if (this.layout.find((item) => item.i == "")) {
Toast.fail({
title: "提示",
forbidClick: true,
message: "请先点击确定,保存当前房间信息"
message: "请先点击确定,保存当前房间信息",
});
return;
}
......@@ -253,11 +307,11 @@ export default {
},
// 添加其他
addOther() {
if (this.layout.find(item => item.i == "")) {
if (this.layout.find((item) => item.i == "")) {
Toast.fail({
title: "提示",
forbidClick: true,
message: "请先点击确定,保存当前房间信息"
message: "请先点击确定,保存当前房间信息",
});
return;
}
......@@ -271,11 +325,11 @@ export default {
//添加基础设施
addBase() {
if (this.layout.find(item => item.i == "")) {
if (this.layout.find((item) => item.i == "")) {
Toast.fail({
title: "提示",
forbidClick: true,
message: "请先点击确定,保存当前房间信息"
message: "请先点击确定,保存当前房间信息",
});
return;
}
......@@ -294,7 +348,7 @@ export default {
// console.log('this.layout==>>',this.layout)
},
// 调整大小后的事件
resizedEvent: function(i, newH, newW) {
resizedEvent: function (i, newH, newW) {
this.layOutItem.w = newW;
this.layOutItem.h = newH;
// console.log('layOutItem==>>',this.layOutItem)
......@@ -342,8 +396,8 @@ export default {
this.roomName = value.dictValue;
}
this.showPicker = false;
}
}
},
},
};
</script>
......@@ -353,7 +407,7 @@ export default {
}
.wrap {
/* height: 100vh; */
width: 100vw;
width: 100%;
position: relative;
}
.north {
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment