|
|
"use strict";
|
|
|
(self["webpackChunk"] = self["webpackChunk"] || []).push([[7884],{
|
|
|
|
|
|
/***/ 25601:
|
|
|
/*!*********************************************************!*\
|
|
|
!*** ./src/pages/Shixuns/Exports/index.tsx + 1 modules ***!
|
|
|
\*********************************************************/
|
|
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
|
|
|
|
// ESM COMPAT FLAG
|
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
|
|
// EXPORTS
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
|
|
"default": function() { return /* binding */ Exports; }
|
|
|
});
|
|
|
|
|
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectSpread2.js
|
|
|
var objectSpread2 = __webpack_require__(42122);
|
|
|
var objectSpread2_default = /*#__PURE__*/__webpack_require__.n(objectSpread2);
|
|
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/regeneratorRuntime.js
|
|
|
var regeneratorRuntime = __webpack_require__(17061);
|
|
|
var regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(regeneratorRuntime);
|
|
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/asyncToGenerator.js
|
|
|
var asyncToGenerator = __webpack_require__(17156);
|
|
|
var asyncToGenerator_default = /*#__PURE__*/__webpack_require__.n(asyncToGenerator);
|
|
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/toConsumableArray.js
|
|
|
var toConsumableArray = __webpack_require__(861);
|
|
|
var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
|
|
|
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/slicedToArray.js
|
|
|
var slicedToArray = __webpack_require__(27424);
|
|
|
var slicedToArray_default = /*#__PURE__*/__webpack_require__.n(slicedToArray);
|
|
|
// EXTERNAL MODULE: ./node_modules/react/index.js
|
|
|
var react = __webpack_require__(67294);
|
|
|
// EXTERNAL MODULE: ./src/.umi-production/exports.ts
|
|
|
var _umi_production_exports = __webpack_require__(88275);
|
|
|
// EXTERNAL MODULE: ./node_modules/html2pdf.js/dist/html2pdf.js
|
|
|
var html2pdf = __webpack_require__(80599);
|
|
|
var html2pdf_default = /*#__PURE__*/__webpack_require__.n(html2pdf);
|
|
|
// EXTERNAL MODULE: ./node_modules/@umijs/plugins/node_modules/dayjs/dayjs.min.js
|
|
|
var dayjs_min = __webpack_require__(94699);
|
|
|
var dayjs_min_default = /*#__PURE__*/__webpack_require__.n(dayjs_min);
|
|
|
// EXTERNAL MODULE: ./src/service/shixuns.ts
|
|
|
var shixuns = __webpack_require__(56088);
|
|
|
// EXTERNAL MODULE: ./node_modules/antd/es/message/index.js + 4 modules
|
|
|
var message = __webpack_require__(2453);
|
|
|
// EXTERNAL MODULE: ./node_modules/antd/es/button/index.js
|
|
|
var es_button = __webpack_require__(71577);
|
|
|
// EXTERNAL MODULE: ./node_modules/antd/es/row/index.js
|
|
|
var row = __webpack_require__(71230);
|
|
|
// EXTERNAL MODULE: ./node_modules/antd/es/col/index.js
|
|
|
var col = __webpack_require__(15746);
|
|
|
// EXTERNAL MODULE: ./src/components/RenderHtml/index.tsx + 1 modules
|
|
|
var RenderHtml = __webpack_require__(12768);
|
|
|
// EXTERNAL MODULE: ./src/utils/util.tsx
|
|
|
var util = __webpack_require__(29427);
|
|
|
;// CONCATENATED MODULE: ./src/pages/Shixuns/Exports/index.less?modules
|
|
|
// extracted by mini-css-extract-plugin
|
|
|
/* harmony default export */ var Exportsmodules = ({"flex_box_center":"flex_box_center___jUfHY","flex_space_between":"flex_space_between___BsD9m","flex_box_vertical_center":"flex_box_vertical_center___U607n","flex_box_center_end":"flex_box_center_end___Cjzjt","flex_box_column":"flex_box_column___Zi6iY","list":"list___QG0cp","on":"on___bq2Xj"});
|
|
|
// EXTERNAL MODULE: ./node_modules/react/jsx-runtime.js
|
|
|
var jsx_runtime = __webpack_require__(85893);
|
|
|
;// CONCATENATED MODULE: ./src/pages/Shixuns/Exports/index.tsx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// import Filter from './components/Filter'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ShixunsListPage = function ShixunsListPage(_ref) {
|
|
|
var shixunsList = _ref.shixunsList,
|
|
|
globalSetting = _ref.globalSetting,
|
|
|
loading = _ref.loading,
|
|
|
dispatch = _ref.dispatch;
|
|
|
var _useState = (0,react.useState)([]),
|
|
|
_useState2 = slicedToArray_default()(_useState, 2),
|
|
|
data = _useState2[0],
|
|
|
setData = _useState2[1];
|
|
|
var _useState3 = (0,react.useState)(false),
|
|
|
_useState4 = slicedToArray_default()(_useState3, 2),
|
|
|
isLoading = _useState4[0],
|
|
|
setIsLoading = _useState4[1];
|
|
|
var _useState5 = (0,react.useState)(0),
|
|
|
_useState6 = slicedToArray_default()(_useState5, 2),
|
|
|
index = _useState6[0],
|
|
|
setIndex = _useState6[1];
|
|
|
var _useState7 = (0,react.useState)(0),
|
|
|
_useState8 = slicedToArray_default()(_useState7, 2),
|
|
|
pIndex = _useState8[0],
|
|
|
setPindex = _useState8[1];
|
|
|
var _useState9 = (0,react.useState)(false),
|
|
|
_useState10 = slicedToArray_default()(_useState9, 2),
|
|
|
downloadBatch = _useState10[0],
|
|
|
setDownloadBatch = _useState10[1];
|
|
|
var _useState11 = (0,react.useState)(0),
|
|
|
_useState12 = slicedToArray_default()(_useState11, 2),
|
|
|
downloadKey = _useState12[0],
|
|
|
setDownloadKey = _useState12[1];
|
|
|
var _useState13 = (0,react.useState)([]),
|
|
|
_useState14 = slicedToArray_default()(_useState13, 1),
|
|
|
queue = _useState14[0];
|
|
|
var _useState15 = (0,react.useState)(''),
|
|
|
_useState16 = slicedToArray_default()(_useState15, 2),
|
|
|
code = _useState16[0],
|
|
|
setCode = _useState16[1];
|
|
|
var location = (0,_umi_production_exports.useLocation)();
|
|
|
(0,react.useEffect)(function () {
|
|
|
var _data$pIndex, _data$pIndex$challeng, _data$pIndex$challeng2, _data$pIndex$challeng3;
|
|
|
if (!!(data !== null && data !== void 0 && (_data$pIndex = data[pIndex]) !== null && _data$pIndex !== void 0 && (_data$pIndex$challeng = _data$pIndex["challenge_info"]) !== null && _data$pIndex$challeng !== void 0 && (_data$pIndex$challeng2 = _data$pIndex$challeng[index]) !== null && _data$pIndex$challeng2 !== void 0 && (_data$pIndex$challeng3 = _data$pIndex$challeng2["task_pass"]) !== null && _data$pIndex$challeng3 !== void 0 && _data$pIndex$challeng3.length)) {
|
|
|
var _data$pIndex2, _data$pIndex2$challen, _data$pIndex2$challen2;
|
|
|
setCode(data === null || data === void 0 ? void 0 : (_data$pIndex2 = data[pIndex]) === null || _data$pIndex2 === void 0 ? void 0 : (_data$pIndex2$challen = _data$pIndex2["challenge_info"]) === null || _data$pIndex2$challen === void 0 ? void 0 : (_data$pIndex2$challen2 = _data$pIndex2$challen[index]) === null || _data$pIndex2$challen2 === void 0 ? void 0 : _data$pIndex2$challen2["task_pass"]);
|
|
|
setTimeout(function () {
|
|
|
var nbPages = 1;
|
|
|
var max_page_height = 1500;
|
|
|
var current_page_height = 0;
|
|
|
toConsumableArray_default()(document.getElementsByClassName('html2pdf__page-break')).forEach(function (x) {
|
|
|
if (!x.width || !x.height) {
|
|
|
x.remove();
|
|
|
}
|
|
|
});
|
|
|
var dom = Array.from(document.getElementById("export-all").querySelector(".markdown-body").children);
|
|
|
dom.map(function (item, key) {
|
|
|
current_page_height += item.scrollHeight;
|
|
|
if (max_page_height <= current_page_height) {
|
|
|
current_page_height = item.scrollHeight;
|
|
|
++nbPages;
|
|
|
var li = document.createElement("li");
|
|
|
li.className = 'html2pdf__page-break';
|
|
|
li.innerHTML = ' ';
|
|
|
document.getElementById("export-all").querySelector(".markdown-body").insertBefore(li, item);
|
|
|
}
|
|
|
});
|
|
|
if (downloadBatch) download();
|
|
|
}, 1500);
|
|
|
} else {
|
|
|
// throw new Error(pIndex)
|
|
|
}
|
|
|
}, [index, pIndex]);
|
|
|
(0,react.useEffect)(function () {
|
|
|
if (downloadBatch) {
|
|
|
if (index == 0 && pIndex == 0) {
|
|
|
download();
|
|
|
} else {
|
|
|
setIndex(0);
|
|
|
setPindex(0);
|
|
|
}
|
|
|
}
|
|
|
}, [downloadBatch]);
|
|
|
|
|
|
/**
|
|
|
* 把 html 内容转化为 markdown 格式 V1.0
|
|
|
*
|
|
|
* @author kohunglee
|
|
|
* @param {string} htmlData 转换前的 html
|
|
|
* @return {string} 转化后的 markdown 源码
|
|
|
*/
|
|
|
function html2md(htmlData) {
|
|
|
var codeContent = new Array(); // code标签数据
|
|
|
var preContent = new Array(); // pre标签数据
|
|
|
var tableContent = new Array(); // table标签数据
|
|
|
var olContent = new Array(); // ol标签数据
|
|
|
var imgContent = new Array(); // img标签数据
|
|
|
var aContent = new Array(); // a标签数据
|
|
|
var pureHtml = htmlData;
|
|
|
|
|
|
// 源代码
|
|
|
console.log("转换前的源码:" + pureHtml);
|
|
|
|
|
|
// 函数:删去html标签
|
|
|
function clearHtmlTag() {
|
|
|
var sourceData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
|
return sourceData.replace(/\<[\s\S]*?\>/g, '');
|
|
|
}
|
|
|
|
|
|
// 复原ol标签
|
|
|
function olRecover() {
|
|
|
var olData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
|
var result = olData;
|
|
|
var num = olData.match(/\<li\>/ig).length;
|
|
|
for (var i = 1; i <= num; i++) {
|
|
|
var line = '[~wrap]';
|
|
|
if (i == 1) line = '[~wrap][~wrap]';
|
|
|
result = result.replace(/\<li\>/i, line + i + '. ');
|
|
|
}
|
|
|
result = result.replace(/\<\/li\>/, '');
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 函数:复原img标签
|
|
|
function imgRecover() {
|
|
|
var imgHtml = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
|
var imgSrc, imgTit, imgAlt, result;
|
|
|
imgSrc = imgHtml.match(/(?<=src=['"])[\s\S]*?(?=['"])/i);
|
|
|
imgTit = imgHtml.match(/(?<=title=['"])[\s\S]*?(?=['"])/i);
|
|
|
imgAlt = imgHtml.match(/(?<=alt=['"])[\s\S]*?(?=['"])/i);
|
|
|
imgTit = imgTit != null ? " \"".concat(imgTit, "\"") : ' ';
|
|
|
imgAlt = imgAlt != 'null' ? imgAlt : " ";
|
|
|
result = ".concat(imgSrc).concat(imgTit, ")");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 函数:复原a标签
|
|
|
function aRecover() {
|
|
|
var aData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
|
var aHref = '' + aData.match(/(?<=href=['"])[\s\S]*?(?=['"])/i);
|
|
|
var aTit = '' + aData.match(/(?<=title=['"])[\s\S]*?(?=['"])/i);
|
|
|
var aText = '' + aData.match(/(?<=\<a\s*[^\>]*?\>)[\s\S]*?(?=<\/a>)/i);
|
|
|
var aImg = aData.match(/<img\s*[^\>]*?\>[^]*?(<\/img>)?/i);
|
|
|
var aImgSrc, aImgTit, aImgAlt;
|
|
|
aTit = aTit != 'null' ? " \"".concat(aTit, "\"") : ' ';
|
|
|
aText = clearHtmlTag(aText);
|
|
|
var result = "[".concat(aText, "](").concat(aHref).concat(aTit, ")");
|
|
|
if (aImg != null) {
|
|
|
// 函数:如果发现图片,则更换为图片显示模式
|
|
|
aImgSrc = aImg[0].match(/(?<=src=['"])[\s\S]*?(?=['"])/i);
|
|
|
aImgTit = aImg[0].match(/(?<=title=['"])[\s\S]*?(?=['"])/i);
|
|
|
aImgAlt = aImg[0].match(/(?<=alt=['"])[\s\S]*?(?=['"])/i);
|
|
|
aImgTit = aImgTit != null ? " \"".concat(aImgTit, "\"") : ' ';
|
|
|
aImgAlt = aImgAlt != 'null' ? aImgAlt : " ";
|
|
|
result = "[.concat(aImgSrc).concat(aImgTit, ")](").concat(aHref).concat(aTit, ")");
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// 函数:复原table标签
|
|
|
function tableRecover() {
|
|
|
var tableData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
|
if (tableData[0] == null) {
|
|
|
// 如果不存在 th 标签,则默认表格为一层
|
|
|
var _result = '';
|
|
|
var _colNum = tableData[1].length;
|
|
|
for (var i = 0; i < _colNum; i++) {
|
|
|
_result += "|".concat(clearHtmlTag(tableData[1][i]));
|
|
|
}
|
|
|
_result += "|[~wrap]";
|
|
|
for (var j = 0; j < _colNum; j++) {
|
|
|
_result += "| :------------: ";
|
|
|
}
|
|
|
_result += "|[~wrap]";
|
|
|
return _result;
|
|
|
}
|
|
|
var colNum = tableData[0].length; // 如果存在 th 标签,则按 th 的格数来构建整个表格
|
|
|
var result = '';
|
|
|
for (var _i = 0; _i < colNum; _i++) {
|
|
|
result += "|".concat(clearHtmlTag(tableData[0][_i]));
|
|
|
}
|
|
|
result += "|[~wrap]";
|
|
|
for (var _j = 0; _j < colNum; _j++) {
|
|
|
result += "| :------------: ";
|
|
|
}
|
|
|
result += "|[~wrap]";
|
|
|
for (var k = 0; k < tableData[1].length;) {
|
|
|
for (var z = 0; z < colNum; z++, k++) {
|
|
|
result += "|".concat(clearHtmlTag(tableData[1][k]));
|
|
|
}
|
|
|
result += "|[~wrap]";
|
|
|
}
|
|
|
return result + "[~wrap]";
|
|
|
}
|
|
|
// 去掉样式和脚本极其内容
|
|
|
pureHtml = pureHtml.replace(/<style\s*[^\>]*?\>[^]*?<\/style>/ig, '').replace(/<script\s*[^\>]*?\>[^]*?<\/script>/ig, '');
|
|
|
|
|
|
// 储存pre的内容,并替换<pre>中的内容
|
|
|
preContent = pureHtml.match(/<pre\s*[^\>]*?\>[^]*?<\/pre>/ig);
|
|
|
pureHtml = pureHtml.replace(/(?<=\<pre\s*[^\>]*?\>)[\s\S]*?(?=<\/pre>)/ig, '`#preContent#`');
|
|
|
|
|
|
// 储存code的内容,并替换<code>中的内容
|
|
|
codeContent = pureHtml.match(/(?<=\<code\s*[^\>]*?\>)[\s\S]*?(?=<\/code>)/ig);
|
|
|
pureHtml = pureHtml.replace(/(?<=\<code\s*[^\>]*?\>)[\s\S]*?(?=<\/code>)/ig, '`#codeContent#`');
|
|
|
|
|
|
// 储存a的内容,并替换<a>中的内容
|
|
|
aContent = pureHtml.match(/<a\s*[^\>]*?\>[^]*?<\/a>/ig);
|
|
|
pureHtml = pureHtml.replace(/<a\s*[^\>]*?\>[^]*?<\/a>/ig, '`#aContent#`');
|
|
|
|
|
|
// 储存img的内容,并替换<img>中的内容
|
|
|
imgContent = pureHtml.match(/<img\s*[^\>]*?\>[^]*?(<\/img>)?/ig);
|
|
|
pureHtml = pureHtml.replace(/<img\s*[^\>]*?\>[^]*?(<\/img>)?/ig, '`#imgContent#`');
|
|
|
|
|
|
// 获取纯净(无属性)的 html
|
|
|
pureHtml = pureHtml.replace(/(?<=\<[a-zA-Z0-9]*)\s.*?(?=\>)/g, '');
|
|
|
|
|
|
// 标题:标获取<h1><h2>...数据,并替换
|
|
|
pureHtml = pureHtml.replace(/<h1>/ig, '[~wrap]# ').replace(/<\/h1>/ig, '[~wrap][~wrap]').replace(/<h2>/ig, '[~wrap]## ').replace(/<\/h2>/ig, '[~wrap][~wrap]').replace(/<h3>/ig, '[~wrap]### ').replace(/<\/h3>/ig, '[~wrap][~wrap]').replace(/<h4>/ig, '[~wrap]#### ').replace(/<\/h4>/ig, '[~wrap][~wrap]').replace(/<h5>/ig, '[~wrap]##### ').replace(/<\/h5>/ig, '[~wrap][~wrap]').replace(/<h6>/ig, '[~wrap]###### ').replace(/<\/h6>/ig, '[~wrap][~wrap]');
|
|
|
|
|
|
// 段落:处理一些常用的结构标签
|
|
|
pureHtml = pureHtml.replace(/(<br>)/ig, '[~wrap]').replace(/(<\/p>)|(<br\/>)|(<\/div>)/ig, '[~wrap][~wrap]').replace(/(<meta>)|(<span>)|(<p>)|(<div>)/ig, '').replace(/<\/span>/ig, '');
|
|
|
|
|
|
// 粗体:替换<b><strong>
|
|
|
pureHtml = pureHtml.replace(/(<b>)|(<strong>)/ig, '**').replace(/(<\/b>)|(<\/strong>)/ig, '**');
|
|
|
|
|
|
// 斜体:替换<i><em><abbr><dfn><cite><address>
|
|
|
pureHtml = pureHtml.replace(/(<i>)|(<em>)|(<abbr>)|(<dfn>)|(<cite>)|(<address>)/ig, '*').replace(/(<\/i>)|(<\/em>)|(<\/abbr>)|(<\/dfn>)|(<\/cite>)|(<\/address>)/ig, '*');
|
|
|
|
|
|
// 删除线:替换<del>
|
|
|
pureHtml = pureHtml.replace(/\<del\>/ig, '~~').replace(/\<\/del\>/ig, '~~');
|
|
|
|
|
|
// 引用:替换<blockquote>
|
|
|
pureHtml = pureHtml.replace(/\<blockquote\>/ig, '[~wrap][~wrap]> ').replace(/\<\/blockquote\>/ig, '[~wrap][~wrap]');
|
|
|
|
|
|
// 水平线:替换<hr>
|
|
|
pureHtml = pureHtml.replace(/\<hr\>/ig, '[~wrap][~wrap]------[~wrap][~wrap]');
|
|
|
|
|
|
// 表格 <table>,得到数据,删除标签,然后逐层分析储存,最终根据结果生成
|
|
|
tableContent = pureHtml.match(/(?<=\<table\s*[^\>]*?\>)[\s\S]*?(?=<\/table>)/ig);
|
|
|
pureHtml = pureHtml.replace(/<table\s*[^\>]*?\>[^]*?<\/table>/ig, '`#tableContent#`');
|
|
|
if (tableContent !== null) {
|
|
|
// 分析储存
|
|
|
tbodyContent = new Array();
|
|
|
for (var i = 0; i < tableContent.length; i++) {
|
|
|
tbodyContent[i] = new Array(); // tbodyContent[i]的第一个数据是thead数据,第二个是tbody的数据
|
|
|
tbodyContent[i].push(tableContent[i].match(/(?<=\<th>)[\s\S]*?(?=<\/th?>)/ig));
|
|
|
tbodyContent[i].push(tableContent[i].match(/(?<=\<td>)[\s\S]*?(?=<\/td?>)/ig));
|
|
|
}
|
|
|
}
|
|
|
if (typeof tbodyContent !== "undefined") {
|
|
|
// 替换
|
|
|
for (var _i2 = 0; _i2 < tbodyContent.length; _i2++) {
|
|
|
var tableText = tableRecover(tbodyContent[_i2]);
|
|
|
pureHtml = pureHtml.replace(/\`\#tableContent\#\`/i, tableText);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 有序列表<ol>的<li>,储存ol的内容,并循环恢复ol中的内容
|
|
|
olContent = pureHtml.match(/(?<=\<ol\s*[^\>]*?\>)[\s\S]*?(?=<\/ol>)/ig);
|
|
|
pureHtml = pureHtml.replace(/(?<=\<ol\s*[^\>]*?\>)[\s\S]*?(?=<\/ol>)/ig, '`#olContent#`');
|
|
|
if (olContent !== null) {
|
|
|
for (var k = 0; k < olContent.length; k++) {
|
|
|
var olText = olRecover(olContent[k]);
|
|
|
pureHtml = pureHtml.replace(/\`\#olContent\#\`/i, clearHtmlTag(olText));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 无序列表<ul>的<li>,以及<dd>,直接替换
|
|
|
pureHtml = pureHtml.replace(/(<li>)|(<dd>)/ig, '[~wrap] - ').replace(/(<\/li>)|(<\/dd>)/ig, '[~wrap][~wrap]');
|
|
|
|
|
|
// 处理完列表后,将 <lu>、<\lu>、<ol>、<\ol> 处理
|
|
|
pureHtml = pureHtml.replace(/(<ul>)|(<ol>)/ig, '').replace(/(<\/ul>)|(<\/ol>)/ig, '[~wrap][~wrap]');
|
|
|
|
|
|
// 先恢复 img ,再恢复 a
|
|
|
if (imgContent !== null) {
|
|
|
for (var _i3 = 0; _i3 < imgContent.length; _i3++) {
|
|
|
var imgText = imgRecover(imgContent[_i3]);
|
|
|
pureHtml = pureHtml.replace(/\`\#imgContent\#\`/i, imgText);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 恢复 a
|
|
|
if (aContent !== null) {
|
|
|
for (var _k = 0; _k < aContent.length; _k++) {
|
|
|
var aText = aRecover(aContent[_k]);
|
|
|
pureHtml = pureHtml.replace(/\`\#aContent\#\`/i, aText);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 换行处理,1.替换 [~wrap] 为 ‘\n’ 2.首行换行删去。 3.将其他过长的换行删去。
|
|
|
pureHtml = pureHtml.replace(/\[\~wrap\]/ig, '\n').replace(/\n{3,}/g, '\n\n');
|
|
|
|
|
|
// 代码 <code> ,根据上面的数组恢复code,然后将code替换
|
|
|
if (codeContent !== null) {
|
|
|
for (var _i4 = 0; _i4 < codeContent.length; _i4++) {
|
|
|
pureHtml = pureHtml.replace(/\`\#codeContent\#\`/i, clearHtmlTag(codeContent[_i4]));
|
|
|
}
|
|
|
}
|
|
|
pureHtml = pureHtml.replace(/\<code\>/ig, ' ` ').replace(/\<\/code\>/ig, ' ` ');
|
|
|
|
|
|
// 代码 <pre> ,恢复pre,然后将pre替换
|
|
|
if (preContent !== null) {
|
|
|
for (var _k2 = 0; _k2 < preContent.length; _k2++) {
|
|
|
var preLanguage = preContent[_k2].match(/(?<=language-).*?(?=[\s'"])/i);
|
|
|
var preText = clearHtmlTag(preContent[_k2]);
|
|
|
preText = preText.replace(/^1\n2\n(\d+\n)*/, ''); // 去掉行数
|
|
|
|
|
|
preLanguage = preLanguage != null && preLanguage[0] != 'undefined' ? preLanguage[0] + '\n' : '\n';
|
|
|
pureHtml = pureHtml.replace(/\`\#preContent\#\`/i, preLanguage + preText);
|
|
|
}
|
|
|
}
|
|
|
pureHtml = pureHtml.replace(/\<pre\>/ig, '```').replace(/\<\/pre\>/ig, '\n```\n');
|
|
|
|
|
|
// 删去其余的html标签,还原预文本代码中的 '<' 和 '>'
|
|
|
pureHtml = clearHtmlTag(pureHtml);
|
|
|
pureHtml = pureHtml.replace(/\<\;/ig, '<').replace(/\>\;/ig, '>');
|
|
|
|
|
|
// 删去头部的空行
|
|
|
pureHtml = pureHtml.replace(/^\n{1,}/i, '');
|
|
|
return pureHtml;
|
|
|
}
|
|
|
var downloadAll = /*#__PURE__*/function () {
|
|
|
var _ref2 = asyncToGenerator_default()( /*#__PURE__*/regeneratorRuntime_default()().mark(function _callee() {
|
|
|
return regeneratorRuntime_default()().wrap(function _callee$(_context) {
|
|
|
while (1) switch (_context.prev = _context.next) {
|
|
|
case 0:
|
|
|
setDownloadBatch(true);
|
|
|
setDownloadKey(0);
|
|
|
case 2:
|
|
|
case "end":
|
|
|
return _context.stop();
|
|
|
}
|
|
|
}, _callee);
|
|
|
}));
|
|
|
return function downloadAll() {
|
|
|
return _ref2.apply(this, arguments);
|
|
|
};
|
|
|
}();
|
|
|
var download = /*#__PURE__*/function () {
|
|
|
var _ref3 = asyncToGenerator_default()( /*#__PURE__*/regeneratorRuntime_default()().mark(function _callee2() {
|
|
|
return regeneratorRuntime_default()().wrap(function _callee2$(_context2) {
|
|
|
while (1) switch (_context2.prev = _context2.next) {
|
|
|
case 0:
|
|
|
setIsLoading(true);
|
|
|
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
|
toConsumableArray_default()(document.getElementsByTagName('canvas')).forEach(function (x) {
|
|
|
if (!x.width || !x.height) {
|
|
|
x.remove();
|
|
|
}
|
|
|
});
|
|
|
try {
|
|
|
var _data$pIndex3;
|
|
|
var title = "".concat(data === null || data === void 0 ? void 0 : (_data$pIndex3 = data[pIndex]) === null || _data$pIndex3 === void 0 ? void 0 : _data$pIndex3["shixun_name"], "-\u7B2C").concat(index + 1, "\u5173-").concat(dayjs_min_default()().format('YYYY-MM-DD'));
|
|
|
var opt2 = {
|
|
|
margin: 10,
|
|
|
filename: title,
|
|
|
image: {
|
|
|
type: 'jpeg',
|
|
|
quality: 0.98
|
|
|
},
|
|
|
pagebreak: {
|
|
|
mode: ['avoid-all', 'css', 'legacy']
|
|
|
},
|
|
|
html2canvas: {
|
|
|
letterRendering: true,
|
|
|
useCORS: true,
|
|
|
allowTaint: false,
|
|
|
scale: 1
|
|
|
}
|
|
|
};
|
|
|
html2pdf_default()().set(opt2).from(document.getElementById("export-all")).toContainer().toCanvas().save();
|
|
|
resolve();
|
|
|
if (downloadBatch) {
|
|
|
++downloadKey;
|
|
|
var k = queue[downloadKey].split("-");
|
|
|
setDownloadKey(downloadKey);
|
|
|
setTimeout(function () {
|
|
|
setIndex(Number(k[1]));
|
|
|
setPindex(Number(k[0]));
|
|
|
}, 5000);
|
|
|
}
|
|
|
} catch (e) {
|
|
|
message/* default.warning */.ZP.warning('无下载内容');
|
|
|
reject();
|
|
|
}
|
|
|
}));
|
|
|
case 3:
|
|
|
case "end":
|
|
|
return _context2.stop();
|
|
|
}
|
|
|
}, _callee2);
|
|
|
}));
|
|
|
return function download() {
|
|
|
return _ref3.apply(this, arguments);
|
|
|
};
|
|
|
}();
|
|
|
(0,react.useEffect)(function () {
|
|
|
(0,util/* setDocumentTitle */.Dk)('实践项目导出');
|
|
|
getData();
|
|
|
}, [location]);
|
|
|
var getData = /*#__PURE__*/function () {
|
|
|
var _ref4 = asyncToGenerator_default()( /*#__PURE__*/regeneratorRuntime_default()().mark(function _callee3() {
|
|
|
var res, _res$data, _res$data$shixuns, _res$data$shixuns$pIn, _res$data$shixuns$pIn2, _res$data$shixuns$pIn3;
|
|
|
return regeneratorRuntime_default()().wrap(function _callee3$(_context3) {
|
|
|
while (1) switch (_context3.prev = _context3.next) {
|
|
|
case 0:
|
|
|
_context3.next = 2;
|
|
|
return (0,shixuns/* getTaskPass */.yx)(objectSpread2_default()({}, (0,util/* getJsonFromUrl */.oP)()));
|
|
|
case 2:
|
|
|
res = _context3.sent;
|
|
|
if (res.status === 0) {
|
|
|
res.data.shixuns.map(function (item, key) {
|
|
|
var _item$challenge_info;
|
|
|
(_item$challenge_info = item.challenge_info) === null || _item$challenge_info === void 0 ? void 0 : _item$challenge_info.map(function (i, k) {
|
|
|
queue.push("".concat(key, "-").concat(k));
|
|
|
});
|
|
|
});
|
|
|
setData(toConsumableArray_default()(res.data.shixuns));
|
|
|
setCode((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$shixuns = _res$data.shixuns) === null || _res$data$shixuns === void 0 ? void 0 : (_res$data$shixuns$pIn = _res$data$shixuns[pIndex]) === null || _res$data$shixuns$pIn === void 0 ? void 0 : (_res$data$shixuns$pIn2 = _res$data$shixuns$pIn["challenge_info"]) === null || _res$data$shixuns$pIn2 === void 0 ? void 0 : (_res$data$shixuns$pIn3 = _res$data$shixuns$pIn2[index]) === null || _res$data$shixuns$pIn3 === void 0 ? void 0 : _res$data$shixuns$pIn3["task_pass"]);
|
|
|
}
|
|
|
case 4:
|
|
|
case "end":
|
|
|
return _context3.stop();
|
|
|
}
|
|
|
}, _callee3);
|
|
|
}));
|
|
|
return function getData() {
|
|
|
return _ref4.apply(this, arguments);
|
|
|
};
|
|
|
}();
|
|
|
var downloadMD = function downloadMD() {
|
|
|
var _data$pIndex4;
|
|
|
// 将 Markdown 数据传递给 MarkdownExport 组件,并使用 markdown-to-plaintext 转换为纯文本格式
|
|
|
var markdownPlainText = html2md(code);
|
|
|
|
|
|
// 创建一个 Blob 对象
|
|
|
var blob = new Blob([markdownPlainText], {
|
|
|
type: 'text/markdown'
|
|
|
});
|
|
|
|
|
|
// 创建一个下载链接
|
|
|
var downloadLink = document.createElement('a');
|
|
|
downloadLink.href = URL.createObjectURL(blob);
|
|
|
var title = "".concat(data === null || data === void 0 ? void 0 : (_data$pIndex4 = data[pIndex]) === null || _data$pIndex4 === void 0 ? void 0 : _data$pIndex4["shixun_name"], "-\u7B2C").concat(index + 1, "\u5173-").concat(dayjs_min_default()().format('YYYY-MM-DD'), ".md");
|
|
|
downloadLink.download = title;
|
|
|
|
|
|
// 将下载链接添加到页面中,并模拟点击该链接以下载 .md 文件
|
|
|
document.body.appendChild(downloadLink);
|
|
|
downloadLink.click();
|
|
|
document.body.removeChild(downloadLink);
|
|
|
};
|
|
|
return /*#__PURE__*/(0,jsx_runtime.jsxs)("section", {
|
|
|
className: "edu-container mt20",
|
|
|
children: [/*#__PURE__*/(0,jsx_runtime.jsxs)("div", {
|
|
|
className: "tr",
|
|
|
children: [/*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, {
|
|
|
style: {
|
|
|
marginRight: 15
|
|
|
},
|
|
|
type: "primary",
|
|
|
onClick: downloadAll,
|
|
|
children: " \u6279\u91CF\u5BFC\u51FA\u5F53\u524D\u5B9E\u8BAD "
|
|
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, {
|
|
|
type: "primary",
|
|
|
style: {
|
|
|
marginRight: 15
|
|
|
},
|
|
|
onClick: downloadMD,
|
|
|
children: " \u5BFC\u51FA\u5F53\u524DMD\u6587\u6863 "
|
|
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)(es_button/* default */.ZP, {
|
|
|
type: "primary",
|
|
|
onClick: download,
|
|
|
children: " \u5BFC\u51FA\u5F53\u524D\u5B9E\u8BAD "
|
|
|
})]
|
|
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)("br", {}), /*#__PURE__*/(0,jsx_runtime.jsxs)(row/* default */.Z, {
|
|
|
gutter: [20, 20],
|
|
|
children: [/*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, {
|
|
|
span: 6,
|
|
|
children: /*#__PURE__*/(0,jsx_runtime.jsx)("ul", {
|
|
|
className: Exportsmodules.list,
|
|
|
children: data.map(function (item, key) {
|
|
|
return /*#__PURE__*/(0,jsx_runtime.jsxs)(jsx_runtime.Fragment, {
|
|
|
children: [/*#__PURE__*/(0,jsx_runtime.jsx)("h1", {
|
|
|
children: item.shixun_name
|
|
|
}), item.challenge_info.map(function (v, k) {
|
|
|
return /*#__PURE__*/(0,jsx_runtime.jsxs)("li", {
|
|
|
onClick: function onClick() {
|
|
|
setPindex(key);
|
|
|
setIndex(k);
|
|
|
},
|
|
|
className: key === pIndex && k === index && Exportsmodules.on,
|
|
|
children: [" ", v.challenge_name]
|
|
|
}, k);
|
|
|
})]
|
|
|
});
|
|
|
})
|
|
|
})
|
|
|
}), /*#__PURE__*/(0,jsx_runtime.jsx)(col/* default */.Z, {
|
|
|
span: 18,
|
|
|
children: /*#__PURE__*/(0,jsx_runtime.jsx)("aside", {
|
|
|
id: "export-all",
|
|
|
children: !!data.length && /*#__PURE__*/(0,jsx_runtime.jsx)(RenderHtml/* default */.Z, {
|
|
|
value: code
|
|
|
})
|
|
|
})
|
|
|
})]
|
|
|
})]
|
|
|
});
|
|
|
};
|
|
|
/* harmony default export */ var Exports = ((0,_umi_production_exports.connect)(function (_ref5) {
|
|
|
var shixunsList = _ref5.shixunsList,
|
|
|
loading = _ref5.loading,
|
|
|
globalSetting = _ref5.globalSetting;
|
|
|
return {
|
|
|
shixunsList: shixunsList,
|
|
|
globalSetting: globalSetting,
|
|
|
loading: loading.models.shixunsList
|
|
|
};
|
|
|
})(ShixunsListPage));
|
|
|
|
|
|
/***/ })
|
|
|
|
|
|
}]); |