From 40ba6daf55f6acc102fd319c408650d389b9eacb Mon Sep 17 00:00:00 2001 From: SHAOJIAHAO <55341701@qq.com> Date: Mon, 5 Jul 2021 16:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=20[=E5=AE=8C=E5=96=84]=E7=94=9F=E6=88=90word?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../create-plan-online-five.component.ts | 31 ++++++++++++++++++- .../collection-tools.component.ts | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts b/src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts index db23456..a6ec325 100644 --- a/src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts +++ b/src/app/plan-management/create-plan-online-five/create-plan-online-five.component.ts @@ -544,7 +544,36 @@ export class CreatePlanOnlineFiveComponent implements OnInit { } //生成word generatingDoc() { - console.log(666, $(".mainbox")) + changeImgToDataurl() + function changeImgToDataurl() { + let charImg = document.getElementsByTagName("img"); + console.log(charImg) + let imgURLs = ""; + for (let i = 0; i < charImg.length; i++) { + let imgURL = charImg[i].currentSrc; + getBase64(imgURL, charImg[i]); + } + } + function getBase64(url, charImg) { + let Img = new Image(); + Img.crossOrigin = "Anonymous";//跨域必须使用,且后台也得设置允许跨域 + let dataURL = ''; + Img.src = url; + Img.onload = function () { //要先确保图片完整获取到,这是个异步事件 + let canvas = document.createElement("canvas"), //创建canvas元素 + width = Img.width, //确保canvas的尺寸和图片一样 + height = Img.height; + canvas.width = width; + canvas.height = height; + canvas.getContext("2d").drawImage(Img, 0, 0, width, height); //将图片绘制到canvas中 + dataURL = canvas.toDataURL('image/jpg'); //转换图片为dataURL + condataurl ? condataurl(dataURL, charImg) : null; //调用回调函数 + }; + } + function condataurl(dataURL, charImg) { + charImg.src = dataURL; + } + $(".mainbox").wordExport('word文档'); } } diff --git a/src/app/ui/collection-tools-plan/collection-tools.component.ts b/src/app/ui/collection-tools-plan/collection-tools.component.ts index a6dc2e4..f7d8d32 100644 --- a/src/app/ui/collection-tools-plan/collection-tools.component.ts +++ b/src/app/ui/collection-tools-plan/collection-tools.component.ts @@ -864,7 +864,7 @@ export class CollectionToolsPlanComponent implements OnInit { //保存建筑数据 // console.log('CompanyData',CompanyData) - CompanyData.data = "{\"图例\":{\"Id\":\"图例\",\"Name\":\"图例\",\"Angle\":0,\"Color\":\"#066EED80\",\"Point\":{\"x\":200,\"y\":200},\"Scale\":1,\"Width\":32,\"Border\":null,\"Height\":32,\"PivotX\":0,\"PivotY\":0,\"Enabled\":true,\"FloorId\":\"60d43256660b093f1c3b5aa5\",\"DrawMode\":null,\"FillMode\":null,\"GameMode\":0,\"ImageUrl\":null,\"FixedSize\":null,\"Thickness\":null,\"MultiPoint\":null,\"TemplateId\":null,\"FireElementId\":null,\"PropertyInfos\":[{\"Tag\":\"\",\"Order\":0,\"Enabled\":true,\"Visible\":true,\"Required\":false,\"RuleName\":\"\",\"RuleValue\":\"\",\"PhysicalUnit\":\"\",\"PropertyName\":\"列\",\"PropertyType\":2,\"PropertyValue\":\"2\"}],\"IsFromBuilding\":null,\"InteractiveMode\":null}}" + // CompanyData.data = "{\"图例\":{\"Id\":\"图例\",\"Name\":\"图例\",\"Angle\":0,\"Color\":\"#066EED80\",\"Point\":{\"x\":200,\"y\":200},\"Scale\":1,\"Width\":32,\"Border\":null,\"Height\":32,\"PivotX\":0,\"PivotY\":0,\"Enabled\":true,\"FloorId\":\"60d43256660b093f1c3b5aa5\",\"DrawMode\":null,\"FillMode\":null,\"GameMode\":0,\"ImageUrl\":null,\"FixedSize\":null,\"Thickness\":null,\"MultiPoint\":null,\"TemplateId\":null,\"FireElementId\":null,\"PropertyInfos\":[{\"Tag\":\"\",\"Order\":0,\"Enabled\":true,\"Visible\":true,\"Required\":false,\"RuleName\":\"\",\"RuleValue\":\"\",\"PhysicalUnit\":\"\",\"PropertyName\":\"列\",\"PropertyType\":2,\"PropertyValue\":\"2\"}],\"IsFromBuilding\":null,\"InteractiveMode\":null}}" this.http.post("/api/CompanyData", CompanyData, { params: {