公告管理
This commit is contained in:
1 parent
374ce74e2d
commit
c0621ff48b
15 files changed
+4641
No files matched your search
@@ -0,0 +1,616 @@
|
||||
<script>
|
||||
|
||||
|
||||
class ArticleMarkdownEngine {
|
||||
static settings = Object.assign({
|
||||
gfm: true,
|
||||
toc: true,
|
||||
tocm: false,
|
||||
tocStartLevel: 1,
|
||||
tocTitle: '目录',
|
||||
tocDropdown: false,
|
||||
tocContainer: '',
|
||||
markdown: '',
|
||||
markdownSourceCode: false,
|
||||
htmlDecode: false,
|
||||
autoLoadKaTeX: true,
|
||||
pageBreak: true,
|
||||
atLink: true, // for @link
|
||||
emailLink: true, // for mail address auto link
|
||||
tex: false,
|
||||
taskList: false, // Github Flavored Markdown task lists
|
||||
emoji: false,
|
||||
flowChart: false,
|
||||
sequenceDiagram: false,
|
||||
previewCodeHighlight: true,
|
||||
}, {
|
||||
// 定制配置,从前端复制
|
||||
htmlDecode: 'style,script,iframe', // you can filter tags decode
|
||||
// toc : false,
|
||||
tocm: true, // Using [TOCM]
|
||||
// tocContainer : "#custom-toc-container", // 自定义 ToC 容器层
|
||||
// gfm : false,
|
||||
// tocDropdown : true,
|
||||
// markdownSourceCode : true, // 是否保留 Markdown 源码,即是否删除保存源码的 Textarea 标签
|
||||
emoji: true,
|
||||
taskList: true,
|
||||
tex: true, // 默认不解析
|
||||
flowChart: true, // 默认不解析
|
||||
sequenceDiagram: true, // 默认不解析
|
||||
});
|
||||
|
||||
static regexs = {
|
||||
atLink: /@(\w+)/g,
|
||||
email: /(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,
|
||||
emailLink: /(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,
|
||||
// mark : /==([^\s][^\<\/code\>][\s\S]*?[^\s])==(?!=)/g,
|
||||
mark: /(={2})([^\<\/code\>].+?)\1/g,
|
||||
emoji: /:([A-Za-z\+-]+):/g,
|
||||
emojiDatetime: /(\d{2}:\d{2}:\d{2})/g,
|
||||
twemoji: /:(tw-([\w]+)-?(\w+)?):/g,
|
||||
fontAwesome: /:(fa-([\w]+)(-(\w+)){0,}):/g,
|
||||
editormdLogo: /:(editormd-logo-?(\w+)?):/g,
|
||||
pageBreak: /^\[[=]{8,}\]$/,
|
||||
};
|
||||
|
||||
static urls = {
|
||||
atLinkBase: 'https://github.com/',
|
||||
};
|
||||
|
||||
|
||||
// Emoji graphics files url path
|
||||
static emoji = {
|
||||
path: 'http://www.emoji-cheat-sheet.com/graphics/emojis/',
|
||||
ext: '.png',
|
||||
};
|
||||
|
||||
// Twitter Emoji (Twemoji) graphics files url path
|
||||
static twemoji = {
|
||||
path: 'http://twemoji.maxcdn.com/36x36/',
|
||||
ext: '.png',
|
||||
};
|
||||
|
||||
static classPrefix = 'editormd-';
|
||||
|
||||
static classNames = {
|
||||
tex: ArticleMarkdownEngine.classPrefix + 'tex',
|
||||
};
|
||||
|
||||
/**
|
||||
* 清除字符串两边的空格
|
||||
* Clear the space of strings both sides.
|
||||
*
|
||||
* @param {String} str string
|
||||
* @return {String} trimed string
|
||||
*/
|
||||
static trim = function(str) {
|
||||
return (!String.prototype.trim) ? str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '') : str.trim();
|
||||
};
|
||||
|
||||
static filterHTMLTags(html, filters) {
|
||||
|
||||
const expression = filters.split('|');
|
||||
const filterTags = expression[0].split(',');
|
||||
|
||||
for (let i = 0, len = filterTags.length; i < len; i++) {
|
||||
const tag = filterTags[i];
|
||||
|
||||
html = html.replace(new RegExp('\<\s*' + tag + '\s*([^\>]*)\>([^\>]*)\<\s*\/' + tag + '\s*\>', 'igm'), '');
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义marked的解析器
|
||||
* Custom Marked renderer rules
|
||||
*
|
||||
* @param {Array} markdownToC 传入用于接收TOC的数组
|
||||
* @param options
|
||||
* @return {Renderer} markedRenderer 返回marked的Renderer自定义对象
|
||||
*/
|
||||
static markedRenderer(markdownToC, options) {
|
||||
const markedRenderer = new marked.Renderer();
|
||||
markdownToC = markdownToC || [];
|
||||
|
||||
const atLinkReg = ArticleMarkdownEngine.regexs.atLink;
|
||||
const markReg = ArticleMarkdownEngine.regexs.mark;
|
||||
const emojiReg = ArticleMarkdownEngine.regexs.emoji;
|
||||
const twemojiReg = ArticleMarkdownEngine.regexs.twemoji;
|
||||
const faIconReg = ArticleMarkdownEngine.regexs.fontAwesome;
|
||||
const editormdLogoReg = ArticleMarkdownEngine.regexs.editormdLogo;
|
||||
const pageBreakReg = ArticleMarkdownEngine.regexs.pageBreak;
|
||||
|
||||
// 增加引用样式解析规则
|
||||
markedRenderer.blockquote = function($quote) {
|
||||
let quoteBegin = '';
|
||||
|
||||
const ps = $quote.match(/<p\s*?>/i);
|
||||
|
||||
if (ps !== null) {
|
||||
quoteBegin = ps[0];
|
||||
$quote = $quote.substr(3);
|
||||
}
|
||||
let $class = 'default';
|
||||
|
||||
if ($quote.indexOf('i ') === 0) {
|
||||
$class = 'info';
|
||||
$quote = $quote.substr(1);
|
||||
} else if ($quote.indexOf('w ') === 0) {
|
||||
$class = 'warning';
|
||||
$quote = $quote.substr(1);
|
||||
} else if ($quote.indexOf('s ') === 0) {
|
||||
$class = 'success';
|
||||
$quote = $quote.substr(1);
|
||||
} else if ($quote.indexOf('d ') === 0) {
|
||||
$class = 'danger';
|
||||
$quote = $quote.substr(1);
|
||||
}
|
||||
|
||||
return '<blockquote class="' + $class + '">\n' + quoteBegin + $quote + '</blockquote>\n';
|
||||
};
|
||||
|
||||
// marked 解析图片
|
||||
markedRenderer.image = function(href, title, text) {
|
||||
const attr = '';
|
||||
const begin = '';
|
||||
const end = '';
|
||||
|
||||
if (/^=(.*?)/.test(text)) {
|
||||
// console.log(text)
|
||||
switch (text) {
|
||||
case '=video':
|
||||
if (href.match(/^.+.(mp4|m4v|ogg|ogv|webm)$/)) {
|
||||
return "<video src='" + href + "' controls='controls' preload width=500></video>";
|
||||
}
|
||||
|
||||
break;
|
||||
case '=audio':
|
||||
if (href.match(/^.+.(mp3|wav|flac|m4a)$/)) {
|
||||
return "<audio src='" + href + "' controls='controls'></audio>";
|
||||
}
|
||||
|
||||
break;
|
||||
case '=video_iframe':
|
||||
const youtubeMatch = href.match(/\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?/);
|
||||
const youkuMatch = href.match(/\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/);
|
||||
const qqMatch = href.match(/\/\/v\.qq\.com\/x\/cover\/.*\/([^\/]+)\.html\??.*/);
|
||||
const coubMatch = href.match(/(?:www\.|\/\/)coub\.com\/view\/(\w+)/);
|
||||
const facebookMatch = href.match(/(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/);
|
||||
const dailymotionMatch = href.match(/.+dailymotion.com\/(video|hub)\/(\w+)\?/);
|
||||
const bilibiliMatch = href.match(/(?:www\.|\/\/)bilibili\.com\/video\/(\w+)/);
|
||||
const tedMatch = href.match(/(?:www\.|\/\/)ted\.com\/talks\/(\w+)/);
|
||||
|
||||
if (youtubeMatch && youtubeMatch[1].length === 11) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="//www.youtube.com/embed/${youtubeMatch[1] + (youtubeMatch[2] ? '?start=' + youtubeMatch[2] : '')}"></iframe>`;
|
||||
} else if (youkuMatch && youkuMatch[1]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="//player.youku.com/embed/${youkuMatch[1]}"></iframe>`;
|
||||
} else if (qqMatch && qqMatch[1]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://v.qq.com/txp/iframe/player.html?vid=${qqMatch[1]}"></iframe>`;
|
||||
} else if (coubMatch && coubMatch[1]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="//coub.com/embed/${coubMatch[1]}?muted=false&autostart=false&originalSize=true&startWithHD=true"></iframe>`;
|
||||
} else if (facebookMatch && facebookMatch[0]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(facebookMatch[0])}"></iframe>`;
|
||||
} else if (dailymotionMatch && dailymotionMatch[2]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="https://www.dailymotion.com/embed/video/${dailymotionMatch[2]}"></iframe>`;
|
||||
} else if (bilibiliMatch && bilibiliMatch[1]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="//player.bilibili.com/player.html?bvid=${bilibiliMatch[1]}"></iframe>`;
|
||||
} else if (tedMatch && tedMatch[1]) {
|
||||
return `<iframe height=400 width=500 frameborder=0 allowfullscreen src="//embed.ted.com/talks/${tedMatch[1]}"></iframe>`;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return begin + '<img src="' + href + '" title="' + title + '" alt="' + text + '" ' + attr + ' />' + end;
|
||||
};
|
||||
|
||||
// marked emoji 解析
|
||||
markedRenderer.emoji = function(text) {
|
||||
|
||||
text = text.replace(ArticleMarkdownEngine.regexs.emojiDatetime, function($1) {
|
||||
return $1.replace(/:/g, ':');
|
||||
});
|
||||
|
||||
const matchs = text.match(emojiReg);
|
||||
|
||||
if (!matchs || !ArticleMarkdownEngine.settings.emoji) {
|
||||
return text;
|
||||
}
|
||||
|
||||
for (let i = 0, len = matchs.length; i < len; i++) {
|
||||
if (matchs[i] === ':+1:') {
|
||||
matchs[i] = ':\\+1:';
|
||||
}
|
||||
|
||||
text = text.replace(new RegExp(matchs[i]), function($1, $2) {
|
||||
const faMatchs = $1.match(faIconReg);
|
||||
const name = $1.replace(/:/g, '');
|
||||
|
||||
if (faMatchs) {
|
||||
for (let fa = 0, len1 = faMatchs.length; fa < len1; fa++) {
|
||||
const faName = faMatchs[fa].replace(/:/g, '');
|
||||
|
||||
return '<i class="fa ' + faName + ' fa-emoji" title="' + faName.replace('fa-', '') + '"></i>';
|
||||
}
|
||||
} else {
|
||||
const emdlogoMathcs = $1.match(editormdLogoReg);
|
||||
const twemojiMatchs = $1.match(twemojiReg);
|
||||
|
||||
if (emdlogoMathcs) {
|
||||
for (let x = 0, len2 = emdlogoMathcs.length; x < len2; x++) {
|
||||
const logoName = emdlogoMathcs[x].replace(/:/g, '');
|
||||
return '<i class="' + logoName + '" title="Editor.md logo (' + logoName + ')"></i>';
|
||||
}
|
||||
} else if (twemojiMatchs) {
|
||||
for (let t = 0, len3 = twemojiMatchs.length; t < len3; t++) {
|
||||
const twe = twemojiMatchs[t].replace(/:/g, '').replace('tw-', '');
|
||||
return '<img src="' + ArticleMarkdownEngine.twemoji.path + twe + ArticleMarkdownEngine.twemoji.ext + '" title="twemoji-' + twe + '" alt="twemoji-' + twe + '" class="emoji twemoji" />';
|
||||
}
|
||||
} else {
|
||||
let src = (name === '+1') ? 'plus1' : name;
|
||||
src = (src === 'black_large_square') ? 'black_square' : src;
|
||||
src = (src === 'moon') ? 'waxing_gibbous_moon' : src;
|
||||
|
||||
return '<img src="' + ArticleMarkdownEngine.emoji.path + src + ArticleMarkdownEngine.emoji.ext + '" class="emoji" title=":' + name + ':" alt=":' + name + ':" />';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
// marked @ 解析
|
||||
markedRenderer.atLink = function(text) {
|
||||
return text;
|
||||
};
|
||||
|
||||
// marked 高亮标记解析
|
||||
markedRenderer.mark = function(text) {
|
||||
if (markReg.test(text)) {
|
||||
// console.log(1,text)
|
||||
const mark_replace_reg = /==(.+)==/g;
|
||||
text = text.replace(markReg, function(e) {
|
||||
// console.log(2,e)
|
||||
return '<mark>' + e.replace(mark_replace_reg, function($1, $2) { return $2; }) + '</mark>';
|
||||
});
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
// marked 链接解析
|
||||
markedRenderer.link = function(href, title, text) {
|
||||
if (this.options.sanitize) {
|
||||
let prot;
|
||||
try {
|
||||
prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, '').toLowerCase();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (prot.indexOf('javascript:') === 0) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
let out = '<a href="' + href + '"';
|
||||
|
||||
if (atLinkReg.test(title) || atLinkReg.test(text)) {
|
||||
if (title) {
|
||||
out += ' title="' + title.replace(/@/g, '@');
|
||||
}
|
||||
|
||||
return out + '">' + text.replace(/@/g, '@') + '</a>';
|
||||
}
|
||||
|
||||
if (title) {
|
||||
out += ' title="' + title + '"';
|
||||
}
|
||||
|
||||
out += '>' + text + '</a>';
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
// marked 解析标题
|
||||
markedRenderer.heading = function(text, level, raw) {
|
||||
|
||||
const linkText = text;
|
||||
const hasLinkReg = /\s*\<a\s*href\=\"(.*)\"\s*([^\>]*)\>(.*)\<\/a\>\s*/;
|
||||
const getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
|
||||
|
||||
if (hasLinkReg.test(text)) {
|
||||
const tempText = [];
|
||||
text = text.split(/\<a\s*([^\>]+)\>([^\>]*)\<\/a\>/);
|
||||
|
||||
for (let i = 0, len = text.length; i < len; i++) {
|
||||
tempText.push(text[i].replace(/\s*href\=\"(.*)\"\s*/g, ''));
|
||||
}
|
||||
|
||||
text = tempText.join(' ');
|
||||
}
|
||||
|
||||
text = ArticleMarkdownEngine.trim(text);
|
||||
|
||||
const isChinese = /^[\u4e00-\u9fa5]+$/.test(text);
|
||||
// var id = (isChinese) ? escape(text).replace(/\%/g, "") : text.toLowerCase().replace(/[^\w]+/g, "-");
|
||||
const id = escape(text.toLowerCase().replace(' ', '')).replace(/\%/g, ''); // 生成包含中文编码的标题ID
|
||||
|
||||
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
const toc = {
|
||||
text,
|
||||
level,
|
||||
slug: escapedText,
|
||||
id: 'h' + level + '-' + this.options.headerPrefix + id,
|
||||
};
|
||||
|
||||
markdownToC.push(toc);
|
||||
|
||||
let headingHTML = '<h' + level + ' id="h' + level + '-' + this.options.headerPrefix + id + '">';
|
||||
|
||||
// headingHTML += "<a name=\"" + text + "\" class=\"reference-link\"></a>";
|
||||
headingHTML += '<a name="' + text.replace(/<[^>]*>\s?/g, '') + '" class="reference-link"></a>';
|
||||
headingHTML += '<span class="header-link octicon octicon-link"></span>';
|
||||
headingHTML += (hasLinkReg) ? this.atLink(this.mark(this.emoji(linkText))) : this.mark(this.emoji(text));
|
||||
headingHTML += '</h' + level + '>';
|
||||
// console.log(headingHTML)
|
||||
return headingHTML;
|
||||
};
|
||||
|
||||
// marked 解析分页符
|
||||
markedRenderer.pageBreak = function(text) {
|
||||
if (pageBreakReg.test(text) && ArticleMarkdownEngine.settings.pageBreak) {
|
||||
text = '<hr style="page-break-after:always;" class="page-break editormd-page-break" />';
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
// marked 解析段落
|
||||
markedRenderer.paragraph = function(text) {
|
||||
const isTeXInline = /\$\$(.*)\$\$/g.test(text);
|
||||
const isTeXLine = /^\$\$(.*)\$\$$/.test(text);
|
||||
const isTeXAddClass = (isTeXLine) ? ' class="' + ArticleMarkdownEngine.classNames.tex + '"' : '';
|
||||
const isToC = (ArticleMarkdownEngine.settings.tocm) ? /^(\[TOC\]|\[TOCM\])$/.test(text) : /^\[TOC\]$/.test(text);
|
||||
const isToCMenu = /^\[TOCM\]$/.test(text);
|
||||
|
||||
if (!isTeXLine && isTeXInline) {
|
||||
text = text.replace(/(\$\$([^\$]*)\$\$)+/g, function($1, $2) {
|
||||
return '<span class="' + ArticleMarkdownEngine.classNames.tex + '">' + $2.replace(/\$/g, '') + '</span>';
|
||||
});
|
||||
} else {
|
||||
text = (isTeXLine) ? text.replace(/\$/g, '') : text;
|
||||
}
|
||||
|
||||
const tocHTML = '<div class="markdown-toc editormd-markdown-toc">' + text + '</div>';
|
||||
return (isToC) ? ((isToCMenu) ? '<div class="editormd-toc-menu">' + tocHTML + '</div><br/>' : tocHTML)
|
||||
: ((pageBreakReg.test(text)) ? this.pageBreak(text) : '<p' + isTeXAddClass + '>' + this.atLink(this.mark(this.emoji(text))) + '</p>\n');
|
||||
};
|
||||
// marked 解析代码块
|
||||
markedRenderer.code = function(code, lang, escaped) {
|
||||
// 自定义颜色function
|
||||
function custom_color(color) {
|
||||
if (color === 'red') {
|
||||
return 'layui-bg-red';
|
||||
} else if (color === 'orange') {
|
||||
return 'layui-bg-orange';
|
||||
} else if (color === 'green') {
|
||||
return 'layui-bg-green';
|
||||
} else if (color === 'cyan') {
|
||||
return 'layui-bg-cyan';
|
||||
} else if (color === 'black') {
|
||||
return 'layui-bg-black';
|
||||
} else if (color === 'grey') {
|
||||
return 'layui-bg-grey';
|
||||
}
|
||||
return '';
|
||||
|
||||
|
||||
}
|
||||
if (lang === 'seq' || lang === 'sequence') {
|
||||
return '<div class="sequence-diagram">' + code + '</div>';
|
||||
} else if (lang === 'flow') {
|
||||
return '<div class="flowchart">' + code + '</div>';
|
||||
} else if (lang === 'math' || lang === 'latex' || lang === 'katex') {
|
||||
return '<p class="' + editormd.classNames.tex + '">' + code + '</p>';
|
||||
} else if (/^mindmap/i.test(lang)) { // 思维导图
|
||||
const len = 9 || 32;
|
||||
const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
||||
const maxPos = $chars.length;
|
||||
let map_id = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
map_id += $chars.charAt(Math.floor(Math.random() * maxPos));
|
||||
}
|
||||
// var map_id = lang.split('>')[1];
|
||||
// console.log(map_id)
|
||||
let custom_height;
|
||||
const h = lang.split('>')[1];
|
||||
if (h != undefined) {
|
||||
custom_height = h;
|
||||
} else {
|
||||
custom_height = 150;
|
||||
}
|
||||
|
||||
return "<svg class='mindmap' style='width:100%;min-height:150px;height:" + custom_height + "px;' id='mindmap-" + map_id + "'>" + code + '</svg>';
|
||||
} else if (/^echart/i.test(lang) || /^echarts/i.test(lang)) { // echart 图表
|
||||
const len = 9 || 32;
|
||||
const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
||||
const maxPos = $chars.length;
|
||||
let map_id = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
map_id += $chars.charAt(Math.floor(Math.random() * maxPos));
|
||||
}
|
||||
// var map_id = lang.split('>')[1];
|
||||
// console.log(map_id)
|
||||
let custom_height;
|
||||
const h = lang.split('>')[1];
|
||||
if (h != undefined) {
|
||||
custom_height = h;
|
||||
} else {
|
||||
custom_height = 150;
|
||||
}
|
||||
|
||||
return "<div class='echart' style='width:100%;min-height:350px;height:" + custom_height + "px;' id='echart-" + map_id + "'>" + code + '</div>';
|
||||
} else if (/^timeline/i.test(lang)) { // 时间线
|
||||
let time_line = '<ul class="layui-timeline">';
|
||||
// console.log(code)
|
||||
const timeline_code = code.split(/(\r\n\t|\n|\r\t)+/);
|
||||
// console.log(timeline_code)
|
||||
timeline_code.forEach(function(item, index) {
|
||||
// console.log(item,index)
|
||||
if (item.match(/^# /)) { // 时间标题
|
||||
time_line += '<li class="layui-timeline-item" style="list-style:none;">';
|
||||
time_line += '<i class="layui-icon layui-timeline-axis"></i>';
|
||||
time_line += '<div class="layui-timeline-content layui-text">';
|
||||
time_line += '<h3 class="layui-timeline-title" style="margin-top:0px;">';
|
||||
time_line += item.replace('# ', '');
|
||||
time_line += '</h3>';
|
||||
} else if (/^[=]{4,}$/.test(item)) {
|
||||
time_line += '</div></li>';
|
||||
} else {
|
||||
time_line += marked(item);
|
||||
}
|
||||
});
|
||||
|
||||
time_line += '</ul>';
|
||||
return time_line;
|
||||
} else if (/^title/i.test(lang)) { // site-title
|
||||
let site_title = '<div class="site-title" style="margin:30px 0 20px;">';
|
||||
// console.log(code)
|
||||
const title_code = code.split(/[(\r\n)\r\n]+/);
|
||||
// console.log(title_code)
|
||||
title_code.forEach(function(item, index) {
|
||||
// console.log(item,index)
|
||||
if (item.match(/^# /)) { // 时间标题
|
||||
site_title += '<fieldset style="border: none;padding: 0;border-top: 1px solid #eee;">';
|
||||
site_title += '<legend style="margin-left: 20px; padding: 0 10px; font-size: 22px; font-weight: 300;">';
|
||||
site_title += '<div name="default">';
|
||||
site_title += item.replace('# ', '');
|
||||
site_title += '</div></legend></fieldset>';
|
||||
} else {
|
||||
site_title += marked(item);
|
||||
}
|
||||
});
|
||||
|
||||
site_title += '</div>';
|
||||
return site_title;
|
||||
} else if (/^tblock/i.test(lang)) { // site-title-block
|
||||
let title_block = '<div class="site-text" style="position: relative;">';
|
||||
// console.log(code)
|
||||
const titleblock_code = code.split(/[(\r\n)\r\n]+/);
|
||||
// console.log(titleblock_code)
|
||||
titleblock_code.forEach(function(item, index) {
|
||||
// console.log(item,index)
|
||||
if (item.match(/^# /)) { // 时间标题
|
||||
title_block += '<fieldset class="layui-elem-field">';
|
||||
title_block += '<legend>';
|
||||
title_block += item.replace('# ', '');
|
||||
title_block += '</div></legend><div class="layui-field-box">';
|
||||
} else {
|
||||
title_block += marked(item);
|
||||
}
|
||||
});
|
||||
|
||||
title_block += '</fieldset></div>';
|
||||
return title_block;
|
||||
} else if (/^hr/i.test(lang)) { // 分割线
|
||||
const color = lang.split(' ')[1];
|
||||
const ccolor = custom_color(color);
|
||||
let hr = '<hr class="' + ccolor + '">';
|
||||
hr += '</hr>';
|
||||
return hr;
|
||||
} else if (/^card/i.test(lang)) { // 卡片面板
|
||||
const color = lang.split(' ')[1];
|
||||
const ccolor = custom_color(color);
|
||||
let card = '<div class="layui-card">';
|
||||
// console.log(code)
|
||||
const card_code = code.split(/[(\r\n)\r\n]+/);
|
||||
// console.log(card_code)
|
||||
card_code.forEach(function(item, index) {
|
||||
// console.log(item,index)
|
||||
if (item.match(/^# /)) { // 时间标题
|
||||
card += '<div class="layui-card-header ' + ccolor + '">';
|
||||
card += item.replace('# ', '');
|
||||
card += '</div>';
|
||||
card += '<div class="layui-card-body">';
|
||||
} else {
|
||||
card += marked(item);
|
||||
}
|
||||
});
|
||||
|
||||
card += '</div>';
|
||||
return card;
|
||||
}
|
||||
|
||||
return marked.Renderer.prototype.code.apply(this, arguments);
|
||||
|
||||
};
|
||||
|
||||
// marked 解析表格
|
||||
markedRenderer.tablecell = function(content, flags) {
|
||||
const type = (flags.header) ? 'th' : 'td';
|
||||
const tag = (flags.align) ? '<' + type + ' style="text-align:' + flags.align + '">' : '<' + type + '>';
|
||||
|
||||
return tag + this.atLink(this.emoji(content)) + '</' + type + '>\n';
|
||||
};
|
||||
|
||||
// marked 解析列表项
|
||||
markedRenderer.listitem = function(text) {
|
||||
if (ArticleMarkdownEngine.settings.taskList && /^\s*\[[x\s]\]\s*/.test(text)) {
|
||||
text = text.replace(/^\s*\[\s\]\s*/, '<input type="checkbox" class="task-list-item-checkbox" /> ')
|
||||
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" class="task-list-item-checkbox" checked disabled /> ');
|
||||
|
||||
return '<li style="list-style: none;">' + this.atLink(this.emoji(text)) + '</li>';
|
||||
}
|
||||
|
||||
return '<li>' + this.atLink(this.emoji(text)) + '</li>';
|
||||
|
||||
};
|
||||
|
||||
return markedRenderer;
|
||||
}
|
||||
|
||||
static md2html(markdownDoc) {
|
||||
// let markdownDoc = (ArticleMarkdownEngine.settings.markdown === '') ? saveTo.val() : ArticleMarkdownEngine.settings.markdown;
|
||||
const markdownToC = [];
|
||||
|
||||
const rendererOptions = {
|
||||
toc: ArticleMarkdownEngine.settings.toc,
|
||||
tocm: ArticleMarkdownEngine.settings.tocm,
|
||||
tocStartLevel: ArticleMarkdownEngine.settings.tocStartLevel,
|
||||
taskList: ArticleMarkdownEngine.settings.taskList,
|
||||
emoji: ArticleMarkdownEngine.settings.emoji,
|
||||
tex: ArticleMarkdownEngine.settings.tex,
|
||||
pageBreak: ArticleMarkdownEngine.settings.pageBreak,
|
||||
atLink: ArticleMarkdownEngine.settings.atLink, // for @link
|
||||
emailLink: ArticleMarkdownEngine.settings.emailLink, // for mail address auto link
|
||||
flowChart: ArticleMarkdownEngine.settings.flowChart,
|
||||
sequenceDiagram: ArticleMarkdownEngine.settings.sequenceDiagram,
|
||||
previewCodeHighlight: ArticleMarkdownEngine.settings.previewCodeHighlight,
|
||||
};
|
||||
|
||||
const markedOptions = {
|
||||
renderer: this.markedRenderer(markdownToC, rendererOptions),
|
||||
gfm: ArticleMarkdownEngine.settings.gfm,
|
||||
tables: true,
|
||||
breaks: true,
|
||||
pedantic: false,
|
||||
// MODIFY:允许 html tag,不进行转义
|
||||
sanitize: false,
|
||||
smartLists: true,
|
||||
// MODIFY:不转义引号
|
||||
smartypants: false,
|
||||
};
|
||||
|
||||
marked.setOptions(markedOptions);
|
||||
markdownDoc = markdownDoc.replace(/ /g, ' ');
|
||||
markdownDoc = markdownDoc.replace(/>/g, '>');
|
||||
let markdownParsed = marked.parse(markdownDoc);
|
||||
|
||||
markdownParsed = this.filterHTMLTags(markdownParsed, ArticleMarkdownEngine.settings.htmlDecode);
|
||||
return markdownParsed;
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
<template id="article-query-template">
|
||||
<v-list dense class="ma-2">
|
||||
<v-list-item-group
|
||||
color="primary"
|
||||
>
|
||||
<v-list-item
|
||||
v-for="(item, i) in articleList"
|
||||
:key="item.id"
|
||||
>
|
||||
<v-list-item-icon class="ma-0 mr-2 mt-2">
|
||||
<span>{{i+1}}. </span>
|
||||
</v-list-item-icon>
|
||||
<v-list-item-content>
|
||||
<v-list-item-title v-text="item.articleTitle"></v-list-item-title>
|
||||
</v-list-item-content>
|
||||
</v-list-item>
|
||||
</v-list-item-group>
|
||||
</v-list>
|
||||
</template>
|
||||
<script>
|
||||
Vue.component("article-query-template", {
|
||||
template: "#article-query-template",
|
||||
name: "article-query-template",
|
||||
props: {
|
||||
params: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
params: {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
handler(value, oValue) {
|
||||
if(value) {
|
||||
this.getArticleList(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
articleList: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
console.log("created", this.params)
|
||||
},
|
||||
|
||||
methods: {
|
||||
async getArticleList(paramObj) {
|
||||
const result = await window.jianghuAxios({
|
||||
data: {
|
||||
appData: {
|
||||
pageId: 'home_content',
|
||||
actionId: "selectItemList",
|
||||
actionData: paramObj
|
||||
}
|
||||
}
|
||||
});
|
||||
this.articleList = result.data.appData.resultData;
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,205 @@
|
||||
<script>
|
||||
class JhTagEngine {
|
||||
currentArticleContentSection;
|
||||
articleContentText;
|
||||
|
||||
// 替换正则特殊符号
|
||||
replaceSpecialChat(string) {
|
||||
return string.replace(/\[/g, '___【___').replace(/]/g, '___】___').replace(/\//g, '___、___');
|
||||
};
|
||||
|
||||
// 还原正则特殊符号
|
||||
restoreSpecialChat(string) {
|
||||
return string.replace(/___n___/g, '\n').replace(/___【___/g, '[').replace(/___】___/g, ']').replace(/___、___/g, '/');
|
||||
};
|
||||
|
||||
// 提取articleQueryList
|
||||
async jhArticleQueryTagListHandle() {
|
||||
this.currentArticleContentSection.forEach((articleItem, index) => {
|
||||
articleItem.content = articleItem.content.replace(/\n/g, '___n___')
|
||||
const _articleQueryList = articleItem.content.match(/\[jh-article-query.+\[\/jh-article-query\]/g);
|
||||
if(_articleQueryList && _articleQueryList.length) {
|
||||
articleItem.children = [];
|
||||
_articleQueryList.forEach((query, qIndex) => {
|
||||
// 1. 提取query的内容
|
||||
let queryContent = query.replace(/(.*)\[jh-article-query]/, '').replace(/(.*)\[\/jh-article-query]/, '$1');
|
||||
queryContent = queryContent.replace(/___n___/g, '');
|
||||
const queryMap = JSON.parse(queryContent);
|
||||
if(query === articleItem.content) {
|
||||
articleItem.type = 'articleQuery';
|
||||
articleItem.params = queryMap;
|
||||
articleItem.children = null;
|
||||
} else {
|
||||
// 转化内容特殊符号
|
||||
articleItem.content = this.replaceSpecialChat(articleItem.content);
|
||||
// 分割内容
|
||||
let resourceContent = articleItem.content;
|
||||
if(articleItem.children.length) {
|
||||
resourceContent = articleItem.children.pop();
|
||||
}
|
||||
const contentList = resourceContent.split(this.replaceSpecialChat(query));
|
||||
// 把每次split的list拼接到children
|
||||
articleItem.children = articleItem.children.concat(contentList)
|
||||
// 同时在最后一条的位置上拼接上query类型数据
|
||||
articleItem.children.splice(articleItem.children.length - 1, 0, {
|
||||
type: 'articleQuery', params: queryMap
|
||||
});
|
||||
}
|
||||
})
|
||||
if(articleItem.children) {
|
||||
articleItem.children = articleItem.children.map((content, index) => {
|
||||
if (typeof content == 'string') {
|
||||
return {
|
||||
type: 'text', content: this.restoreSpecialChat(content)
|
||||
};
|
||||
}
|
||||
return content;
|
||||
})
|
||||
}
|
||||
} else {
|
||||
articleItem.content = this.restoreSpecialChat(articleItem.content);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
// jhPdfViewer [jh-pdf-viewer src="/__appId__/upload\articleMaterial\30009\1668869349745_生态高尔夫与高尔夫球场环境认证_戴子云.pdf"/]
|
||||
async jhPdfViewer() {
|
||||
// 如存在pdf 则把 原有content index 下的 {type: 'text', src: 'xxx'} 替换为 {type: 'text', src: 'xxx'},{type: 'pdfViewer', src: 'xxx'},{type: 'text', src: 'xxx'}
|
||||
// content 数组从后往前替换避免 index 变化问题
|
||||
const replaceArray = [];
|
||||
this.currentArticleContentSection.forEach((articleItem, index) => {
|
||||
let content = articleItem.content;
|
||||
const pdfObj = {
|
||||
contentIndex: index,
|
||||
content: []
|
||||
};
|
||||
const _pdfViewList = articleItem.content.match(/\[jh-pdf-viewer.+\/]/g);
|
||||
if(_pdfViewList && _pdfViewList.length) {
|
||||
_pdfViewList.forEach((query, qIndex) => {
|
||||
pdfObj.content.pop();
|
||||
// 1. 提取标签/src 的内容 {src: 'xxx'}
|
||||
const params = this.extractedPdfViewer(query);
|
||||
|
||||
// 2. 提取 pdf-viewer 前的content text内容 和自己
|
||||
const contentArr = content.split(query);
|
||||
pdfObj.content.push({ type: 'text', content: contentArr[0] });
|
||||
pdfObj.content.push({ type: 'pdfViewer', params });
|
||||
|
||||
// 3. push 暂存剩余文本至最后一个
|
||||
contentArr.splice(0, 1)
|
||||
content = contentArr.join(query);
|
||||
pdfObj.content.push({ type: 'text', content });
|
||||
})
|
||||
}
|
||||
if(pdfObj.content.length) {
|
||||
replaceArray.unshift(pdfObj);
|
||||
}
|
||||
})
|
||||
// replaceArray [{contentIndex: 1, content: [{type: 'text', content: 'xxx'},{type: 'pdfViewer', src: 'xxx'},{type: 'text', content: 'xxx'}]}]
|
||||
replaceArray.forEach((item, index) => {
|
||||
this.currentArticleContentSection.splice(item.contentIndex, 1, ...item.content);
|
||||
})
|
||||
};
|
||||
|
||||
lineToUpper(split, str) {
|
||||
return str.split(split).map((e, i) => {
|
||||
return i ? e.slice(0, 1).toUpperCase() + e.slice(1) : e
|
||||
}).join('')
|
||||
};
|
||||
|
||||
// 提取toggleList
|
||||
async jhTagTemplateHandler(_articleContentText) {
|
||||
this.articleContentText = _articleContentText || '';
|
||||
// \n会导致正则失败
|
||||
this.articleContentText = this.articleContentText.replace(/\n/g, '___n___');
|
||||
// 1. 提取toggle标签对
|
||||
const _toggleList = this.articleContentText.match(/\[jh-toggle[\s\S]*?\[\/jh-toggle\]/g);
|
||||
// [、]、/ 这些正则符号会导致替换失败,使用替代符号暂时替代
|
||||
this.articleContentText = this.replaceSpecialChat(this.articleContentText);
|
||||
// toggleList 未必会包含articleQueryList
|
||||
if (_toggleList && _toggleList.length) {
|
||||
_toggleList.forEach((item, index) => {
|
||||
// 替换的正则,同上处理
|
||||
const regExp = this.replaceSpecialChat(item);
|
||||
// toggle标签分割内容
|
||||
this.splitContent(index, regExp);
|
||||
this.covertContentString2Json();
|
||||
this.extractedToggle(item);
|
||||
})
|
||||
} else {
|
||||
this.currentArticleContentSection = [{
|
||||
type: 'text', content: this.replaceSpecialChat(this.articleContentText)
|
||||
}]
|
||||
}
|
||||
// 提取articleQuery
|
||||
this.jhArticleQueryTagListHandle();
|
||||
this.jhPdfViewer();
|
||||
return this.currentArticleContentSection;
|
||||
};
|
||||
|
||||
// 分割content body数组
|
||||
splitContent(index, regExp) {
|
||||
if (index === 0) {
|
||||
this.currentArticleContentSection = this.articleContentText.split(regExp);
|
||||
} else {
|
||||
const lastArticleContent = this.replaceSpecialChat(this.currentArticleContentSection.pop().content.replace(/\n/g, '___n___'));
|
||||
const lastArticleContentArr = lastArticleContent.split(regExp)
|
||||
this.currentArticleContentSection = this.currentArticleContentSection.concat(lastArticleContentArr);
|
||||
}
|
||||
}
|
||||
|
||||
covertContentString2Json() {
|
||||
this.currentArticleContentSection = this.currentArticleContentSection.map((content, index) => {
|
||||
if (typeof content == 'string') {
|
||||
return {
|
||||
type: 'text', content: this.restoreSpecialChat(content)
|
||||
};
|
||||
}
|
||||
return content;
|
||||
})
|
||||
}
|
||||
|
||||
extractedToggle(item) {
|
||||
// 通toggle中提取内容
|
||||
let toggleDomStr = item.split(']')[0].substring('[jh-toggle '.length);
|
||||
let toggleDom = {};
|
||||
|
||||
const attrList = toggleDomStr.match(/['"][\s\S]*?['"]/g);
|
||||
attrList.forEach(e => {
|
||||
e = e.replace(/['"]/g, '');
|
||||
const targetStr = e.replace(/\s/g, '');
|
||||
toggleDomStr = toggleDomStr.replace(e, targetStr)
|
||||
})
|
||||
toggleDomStr.split(' ').forEach(e => {
|
||||
toggleDom = Object.assign(toggleDom, {
|
||||
[this.lineToUpper('-', e.split('=')[0])]: e.split('=')[1].replace(/"/g, '')
|
||||
})
|
||||
})
|
||||
let toggleContent = item.split(']').slice(1).join(']').replace(/(.*)\[\/jh-toggle]/, '$1');
|
||||
// toggleContent = toggleContent.slice(toggleContent.length - 1, 1);
|
||||
this.currentArticleContentSection.splice(this.currentArticleContentSection.length - 1, 0, {
|
||||
type: 'toggle', content: this.restoreSpecialChat(toggleContent), params: toggleDom
|
||||
});
|
||||
}
|
||||
|
||||
extractedPdfViewer(item) {
|
||||
// 通toggle中提取内容
|
||||
let domStr = item.split('/]')[0].substring('[jh-pdf-viewer '.length);
|
||||
let dom = {};
|
||||
|
||||
const attrList = domStr.match(/['"][\s\S]*?['"]/g);
|
||||
attrList.forEach(e => {
|
||||
e = e.replace(/['"]/g, '');
|
||||
const targetStr = e.replace(/\s/g, '');
|
||||
domStr = domStr.replace(e, targetStr)
|
||||
})
|
||||
domStr.split(' ').forEach(e => {
|
||||
dom = Object.assign(dom, {
|
||||
[this.lineToUpper('-', e.split('=')[0])]: e.split('=')[1].replace(/"/g, '')
|
||||
})
|
||||
})
|
||||
return dom;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,152 @@
|
||||
<!--md2html.html start-->
|
||||
<script src="/<$ ctx.app.config.appId $>/public/plugins/editor.md/lib/marked.min.js"></script>
|
||||
<template id="md2html">
|
||||
<div>
|
||||
<template v-for="(item, index) of currentArticleContentSection">
|
||||
<template v-if="item.type === 'text'">
|
||||
<template v-if="item.children">
|
||||
<template v-for="(child, cindex) of item.children">
|
||||
<template v-if="child.type === 'text'">
|
||||
<div ref="artContent" class="content pa-5 markdown-body editormd-html-preview"
|
||||
:id="'artContent' + Math.floor(Math.random() * 9999)" :data-content="child.content">
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="child.type === 'articleQuery'">
|
||||
<article-query-template :params="child.params"></article-query-template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div ref="artContent" class="content pa-5 markdown-body editormd-html-preview"
|
||||
:id="'artContent' + Math.floor(Math.random() * 9999)" :data-content="item.content">
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
<template v-if="item.type === 'toggle'">
|
||||
<toggle-template :params="item.params" @open="renderMarkdown">
|
||||
<template v-if="item.children">
|
||||
<template v-for="(child, cIndex) of item.children">
|
||||
<template v-if="child.type === 'text'">
|
||||
<div ref="artContent" class="content pa-5 markdown-body editormd-html-preview"
|
||||
:id="'artContent' + Math.floor(Math.random() * 9999)" :data-content="child.content">
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="child.type === 'articleQuery'">
|
||||
<article-query-template :params="child.params"></article-query-template>
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div ref="artContent" class="content pa-5 markdown-body editormd-html-preview"
|
||||
:id="'artContent' + Math.floor(Math.random() * 9999)" :data-content="item.content">
|
||||
</div>
|
||||
</template>
|
||||
</toggle-template>
|
||||
</template>
|
||||
<template v-if="item.type === 'articleQuery'">
|
||||
<article-query-template :params="item.params"></article-query-template>
|
||||
</template>
|
||||
<template v-if="item.type === 'pdfViewer'">
|
||||
<pdf-viewer :params="item.params"></pdf-viewer>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
{% include 'component/markdown2html/jhTagEngine.html' %}
|
||||
{% include 'component/markdown2html/toggleTemplate.html' %}
|
||||
{% include 'component/markdown2html/articleQueryTemplate.html' %}
|
||||
{% include 'component/markdown2html/articleMarkdownEngine.html' %}
|
||||
{% include 'component/markdown2html/pdfViewerTemplate.html' %}
|
||||
<script>
|
||||
Vue.component("md2html", {
|
||||
vuetify: new Vuetify(),
|
||||
name: 'md2html',
|
||||
props: ['articleContent'],
|
||||
data: () => ({
|
||||
currentArticleContentSection: []
|
||||
}),
|
||||
created() {
|
||||
this.jhTagEngine = new JhTagEngine();
|
||||
if(this.articleContent) {
|
||||
this.renderContent();
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
articleContent: {
|
||||
handler(value) {
|
||||
this.clearOldContent();
|
||||
if(value) {
|
||||
this.renderContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
clearOldContent() {
|
||||
const artContentRefs = this.$refs.artContent;
|
||||
if (artContentRefs && artContentRefs.length) {
|
||||
artContentRefs.forEach(artContent => {
|
||||
artContent.innerHTML = "";
|
||||
})
|
||||
}
|
||||
this.currentArticleContentSection = [];
|
||||
},
|
||||
renderMarkdown () {
|
||||
const artContentRefs = this.$refs.artContent;
|
||||
if (artContentRefs && artContentRefs.length) {
|
||||
setTimeout(() => {
|
||||
this.markdownToHTML(artContentRefs);
|
||||
this.isContentLoading = false;
|
||||
}, 300)
|
||||
} else {
|
||||
requestAnimationFrame(() => {
|
||||
this.renderContent();
|
||||
})
|
||||
}
|
||||
},
|
||||
markdownToHTML(artContentRefs) {
|
||||
artContentRefs.forEach(artContent => {
|
||||
const contentText = artContent.dataset.content;
|
||||
artContent.innerHTML = ArticleMarkdownEngine.md2html(contentText);
|
||||
})
|
||||
this.$emit('complete')
|
||||
},
|
||||
async renderContent() {
|
||||
const newArticleContent = this.articleContent.replace(/\/__appId__\/upload\//g, '/<$ ctx.app.config.appId $>/upload/')
|
||||
this.currentArticleContentSection = await this.jhTagEngine.jhTagTemplateHandler(newArticleContent);
|
||||
this.renderMarkdown();
|
||||
},
|
||||
dayjs: dayjs
|
||||
},
|
||||
template: '#md2html'
|
||||
})
|
||||
</script>
|
||||
<style scope>
|
||||
.articleOtherInfoBox span:last-child {
|
||||
padding: 0 20px;
|
||||
}
|
||||
.articleOtherInfoBox span {
|
||||
color: #666666;
|
||||
}
|
||||
.editormd-preview-container ol.linenums li, .editormd-html-preview ol.linenums li {
|
||||
list-style-type: none;
|
||||
}
|
||||
.editormd-preview-container ol.linenums, .editormd-html-preview ol.linenums {
|
||||
color: #999;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.markdown-body pre {
|
||||
font-family: unset;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.markdown-body pre code {
|
||||
background-color: unset !important;
|
||||
font-family: unset !important;
|
||||
max-width: 100%;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
<!--md2html.html end-->
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
<template id="pdf-viewer">
|
||||
<div style="width: 100%; padding: 65% 0;position: relative;">
|
||||
<iframe :src="'/<$ ctx.app.config.appId $>/public/pdf/web/viewer.html?file=' + src" frameborder="0" style="position: absolute;width: 100%; height: 100%; top: 0;left: 0"></iframe>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
Vue.component("pdf-viewer", {
|
||||
template: "#pdf-viewer",
|
||||
name: "pdf-viewer",
|
||||
props: {
|
||||
params: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
appId: '<$ ctx.app.config.appId $>',
|
||||
prefix: '<$ ctx.app.config.downloadBasePath $>',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
src() {
|
||||
if (this.params.src) {
|
||||
// 替换appId
|
||||
const src = this.params.src.replace('__appId__', this.appId);
|
||||
if (src.includes('/upload/')) {
|
||||
return encodeURIComponent(this.prefix + '/' + src.split('upload')[1]);
|
||||
} else {
|
||||
return encodeURIComponent(this.prefix + src);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
<template id="toggle-template">
|
||||
<div>
|
||||
<v-expansion-panels style="width: calc(100% - 20px); margin: 10px;" @change="onOpen">
|
||||
<v-expansion-panel>
|
||||
<v-expansion-panel-header>{{_params['title']}}</v-expansion-panel-header>
|
||||
<v-expansion-panel-content>
|
||||
<slot></slot>
|
||||
</v-expansion-panel-content>
|
||||
</v-expansion-panel>
|
||||
</v-expansion-panels>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
Vue.component("toggle-template", {
|
||||
template: "#toggle-template",
|
||||
name: "toggle-template",
|
||||
props: {
|
||||
params: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {
|
||||
title: '测试标题',
|
||||
defaultOpen: ''
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
_params() {
|
||||
return this.params;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
params: {
|
||||
deep: true,
|
||||
handler(value, oldValue) {
|
||||
// console.log('params', value, oldValue)
|
||||
}
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
},
|
||||
|
||||
methods: {
|
||||
onOpen(status) {
|
||||
requestAnimationFrame(() => {
|
||||
this.$emit('open', status)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
Reference in new issue
Block a user