优化issue

This commit is contained in:
何童崇 2022-03-09 14:51:00 +08:00
parent ab4f72701b
commit 3596f0ed2b
2 changed files with 4 additions and 6 deletions

View File

@ -31,23 +31,21 @@ class ExportWord extends Component {
if (typeof window === 'undefined' || (typeof navigator !== 'undefined' && /MSIE [1-9]\./.test(navigator.userAgent))) {
return;
}
const location =window.location;
const mHtml = {
top: `Mime-Version: 1.0\nContent-Base: ${location.href}\nContent-Type: Multipart/related; boundary="NEXT.ITEM-BOUNDARY";type="text/html"\n\n--NEXT.ITEM-BOUNDARY\nContent-Type: text/html; charset="utf-8"\nContent-Location: ${location.href}\n\n<!DOCTYPE html>\n<html>\n_html_</html>`,
head: '<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n<style>\n_styles_\n</style>\n</head>\n',
body: '<body>_body_</body>',
};
const activeDoc = document.getElementById(wordId) // 获取 dom 节点
.cloneNode(true);
const activeDoc = document.getElementById(wordId).cloneNode(true); // 获取 dom 节点
const { wordStyles: styles } = this.props; // 文件样式
// 默认样式
const defaultStyle = '.text-div{ text-decoration: underline; margin-right: 15px; } .textarea-div{ text-decoration: underline; }';
const mHtmlBottom = '\n--NEXT.ITEM-BOUNDARY--';// 文件尾信息
// 替换模板里的内容
const fileContent = mHtml.top.replace('_html_', mHtml.head.replace('_styles_', defaultStyle + styles) + mHtml.body.replace('_body_', activeDoc.innerHTML)) + mHtmlBottom;
const fileContent = mHtml.top.replace('_html_', mHtml.head.replace('_styles_', defaultStyle ) + mHtml.body.replace('_body_', activeDoc.innerHTML)) + mHtmlBottom;
// 创建包含文件内容的blob
const blob = new Blob([fileContent], { type: 'application/msword;charset=utf-8' });
// 下载word文件

View File

@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from "react";
import { Input, Button, Form, Select } from "antd";
import { Input, Button, Form, message } from "antd";
import MDEditor from "../../../modules/tpm/challengesnew/tpm-md-editor";
import {getAgreement, agreementAdd,agreementEdit } from "../api";
import "../index.scss";