vue无需引入第三方, 将web页面内容直接下载为docx

vue无需引入第三方, 将web页面内容直接下载为docx

将web页面内容重绘 html ,通过 a 标签直接下载

通过写行内样式,控制docx中的文字图效果

复制代码
 let echHtmlWithIf = '';
        if (this.chartImg.length) {
          if (this.exceed10Min) {
            echHtmlWithIf += `<div v-if="exceed10Min" id="chartId">` +
              this.chartImg.map(item => `<img src="${item.src}" width="550"/>`)
              + `</div>`;
          } else {
            echHtmlWithIf += `  <p v-else class="ml20" style="margin-left: 20px;">报告生成中,预计 ` + this.Dshowtime + `分钟后生成。</p>`;
          }
        } else {
          echHtmlWithIf = "暂无相关数据"
        }

        let img0 = false, img2 = false, img4 = false
        let img0html = `<img src="${this.img64[0]}" width="550" />`,
          img2html = `<img src="${this.img64[1]}" width="550" />`,
          img4html = `<img src="${this.img64[2]}" width="550" />`

        this.nullImgs.forEach(e => {
          if (e == 0) {
            img0 = true
          } else if (e == 2) {
            img2 = true
          } else if (e == 4) {
            img4 = true
          }
        });

        if (img0) {
          img0html = `<img src="${this.errorImgurl}" width="200">`
        }
        if (img2) {
          img2html = `<img src="${this.errorImgurl}"  width="200">`
        }
        if (img4) {
          img4html = `<img src="${this.errorImgurl}"  width="200">`
        }

        const html = `
<html>
  <body>
    <div id="pcContract">
          <p style="text-align: center;font-size: 24px; font-weight: bold; line-height: 60px;">
            关于${this.alarm.monitorPoint.name}限高架发生碰撞报警的报告</p>
          <p class="ar-contit" style="font-size: 20px; font-weight: bold; line-height: 60px;">一、告警通知</p>
          <div class="ar-context ml20" style="text-indent: 2em;margin: 10px 0;">${this.alarm.remark}</div>
          <div class="ar-context ml20" style="text-indent: 2em;margin: 10px 0;"> 经核实,以上告警为:${this.remarkText} ,碰撞程度为:${this.resultText}。
          </div>
          <p style="font-size: 20px; font-weight: bold; line-height: 60px;">二、监测数据</p>
          <p style="font-size: 18px; font-weight: bold; line-height: 60px;margin-bottom: 40px;">2.1视频监测图片:</p>
          <div>
            <div style="text-align: center;margin-bottom: 20px;">
              ${img0html}
              <p>碰撞前</p>
            </div>
            <div style="text-align: center;margin-bottom: 20px;">
              ${img2html}
              <p>碰撞中</p>
            </div>
            <div style="text-align: center;margin-bottom: 20px;">
              ${img4html}
              <p>碰撞后</p>
            </div>
          </div>
          <p style="font-size: 18px; font-weight: bold; line-height: 60px; margin-bottom: 40px;">2.2 加速度监测曲线:</p>
          <div>
            ${echHtmlWithIf}
          </div>

          <p class="dateP" style="text-align: right; line-height: 60px;">${this.alarmDate}</p>
        </div>
  </body>
</html>
`;
        this.html = html
        // 导出
       const blob = new Blob([html], {
          type: 'application/msword',
        });
        const link = document.createElement('a');
        link.download = `关于${this.alarm.monitorPoint.name}限高架发生碰撞报警的报告.docx`;
         link.href = URL.createObjectURL(blob);
        link.click();
相关推荐
jllllyuz9 分钟前
matlab实现蚁群算法解决公交车路径规划问题
服务器·前端·数据库
小屁孩大帅-杨一凡1 小时前
一个简单点的js的h5页面实现地铁快跑的小游戏
开发语言·前端·javascript·css·html
读心悦1 小时前
CSS 布局系统深度解析:从传统到现代的布局方案
前端·css
椒盐螺丝钉1 小时前
CSS盒子模型:Padding与Margin的适用场景与注意事项
前端·css
萧鼎2 小时前
构建全栈 Web 应用的新选择:NextPy 技术详解与实战指南
前端
purpleseashell_Lili2 小时前
配置别名路径 @
javascript·react
这个一个非常哈2 小时前
VUE篇之自定义组件使用v-model
前端·javascript·vue.js
purpleseashell_Lili3 小时前
react 基本写法
java·服务器·前端
哎哟喂_!3 小时前
Node.js 循环依赖问题详解:原理、案例与解决方案
前端·chrome·node.js
热爱前端的小君同学3 小时前
长按拖拽移动的vue3组件
前端·javascript·vue.js