From 4ce5f3f7da3535e8d076f092b6a0c89b0b3f3fbb Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Fri, 26 Mar 2021 16:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9F=E8=B0=B1=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stdiet-ui/package.json | 1 + .../RecipesView/RecipesHeaderCom/index.vue | 67 ++++++++++++++++++- .../src/views/custom/recipesBuild/index.vue | 2 +- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/stdiet-ui/package.json b/stdiet-ui/package.json index c60d94dd3..3d9272a77 100644 --- a/stdiet-ui/package.json +++ b/stdiet-ui/package.json @@ -50,6 +50,7 @@ "element-ui": "2.13.2", "file-saver": "^2.0.5", "fuse.js": "3.4.4", + "html2canvas": "^1.0.0-rc.7", "immer": "^8.0.1", "js-beautify": "1.10.2", "js-cookie": "2.2.0", diff --git a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue index feed15795..5f5a599cf 100644 --- a/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue +++ b/stdiet-ui/src/views/custom/recipesBuild/RecipesView/RecipesHeaderCom/index.vue @@ -19,6 +19,17 @@ > 另存为模板 + + 导出图片 +
@@ -96,6 +107,7 @@ const { mapActions, mapState, mapMutations } = createNamespacedHelpers( "recipes" ); import TemplateDialog from "@/components/TemplateDialog"; +import html2canvans from "html2canvas"; export default { name: "RecipesHeaderCom", components: { @@ -104,6 +116,7 @@ export default { data() { return { loading: false, + downloading: false, nFontSize: 0, fontSizeOpts: [ { value: 8, label: "8" }, @@ -117,7 +130,14 @@ export default { }, updated() {}, computed: { - ...mapState(["recipesId", "reviewStatus", "fontSize", "leftShow"]), + ...mapState([ + "recipesId", + "reviewStatus", + "fontSize", + "leftShow", + "healthyData", + "recipesData", + ]), }, watch: {}, methods: { @@ -193,12 +213,46 @@ export default { return "info"; } }, + handleOnExportImg() { + this.downloading = true; + this.$nextTick(() => { + const centerContentDom = document.getElementById("center_content"); + if (!centerContentDom) { + this.downloading = false; + return; + } + centerContentDom.style.overflow = "visible"; + const recipesDom = document.getElementById("recipes_content"); + if (!recipesDom) { + this.downloading = false; + return; + } + recipesDom.style.overflow = "visible"; + html2canvans(recipesDom, { + scale: 1.5, + height: recipesDom.scrollHeight, + }).then((canvas) => { + const { name } = this.healthyData; + const startNum = this.recipesData[0].numDay; + const endNum = this.recipesData[this.recipesData.length - 1].numDay; + const link = document.createElement("a"); + link.download = `${name}_第${startNum}至${endNum}天.jpeg`; + link.href = canvas.toDataURL(); + link.click(); + + centerContentDom.style.overflow = "auto"; + recipesDom.style.overflow = "auto"; + + this.downloading = false; + }); + }); + }, ...mapActions(["saveRecipes", "updateReviewStatus"]), ...mapMutations(["updateStateData", "updateFontSize", "toggleLeftShow"]), }, }; - diff --git a/stdiet-ui/src/views/custom/recipesBuild/index.vue b/stdiet-ui/src/views/custom/recipesBuild/index.vue index 81680c96e..b2e4ebeed 100644 --- a/stdiet-ui/src/views/custom/recipesBuild/index.vue +++ b/stdiet-ui/src/views/custom/recipesBuild/index.vue @@ -8,7 +8,7 @@ -
+