|
@@ -3,10 +3,14 @@
|
|
|
<div class="header">
|
|
|
<h1>麻城知识库思维导图</h1>
|
|
|
<div class="controls">
|
|
|
- <button @click="toggleFullscreen" class="control-btn">
|
|
|
- <i :class="isFullscreen ? 'el-icon-shrink' : 'el-icon-full-screen'"></i>
|
|
|
- {{ isFullscreen ? '退出全屏' : '全屏显示' }}
|
|
|
+ <button @click="downloadSvg" class="control-btn">
|
|
|
+ <i class="el-icon-download"></i>
|
|
|
+ 下载SVG
|
|
|
</button>
|
|
|
+ <!-- <button @click="toggleFullscreen" class="control-btn">-->
|
|
|
+ <!-- <i :class="isFullscreen ? 'el-icon-shrink' : 'el-icon-full-screen'"></i>-->
|
|
|
+ <!-- {{ isFullscreen ? '退出全屏' : '全屏显示' }}-->
|
|
|
+ <!-- </button>-->
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -66,11 +70,9 @@ export default {
|
|
|
getQueryData() {
|
|
|
const query = this.$route.query;
|
|
|
this.markdownContent = decodeURIComponent(query.data);
|
|
|
-
|
|
|
},
|
|
|
loadMarkmap() {
|
|
|
-
|
|
|
-this.getQueryData();
|
|
|
+ this.getQueryData();
|
|
|
// 动态加载markmap
|
|
|
const script = document.createElement('script');
|
|
|
script.src = 'https://cdn.jsdelivr.net/npm/markmap-autoloader';
|
|
@@ -121,6 +123,48 @@ this.getQueryData();
|
|
|
this.$nextTick(() => {
|
|
|
setTimeout(this.fixSvgDimensions, 300);
|
|
|
});
|
|
|
+ },
|
|
|
+
|
|
|
+ downloadSvg() {
|
|
|
+ const svgElement = document.querySelector('.markmap svg');
|
|
|
+ if (!svgElement) {
|
|
|
+ console.error('未找到SVG元素');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 克隆SVG元素以避免影响原始显示
|
|
|
+ const clonedSvg = svgElement.cloneNode(true);
|
|
|
+
|
|
|
+ // 设置固定的宽度和高度以确保导出质量
|
|
|
+ const bbox = svgElement.getBBox();
|
|
|
+ clonedSvg.setAttribute('width', bbox.width + 100);
|
|
|
+ clonedSvg.setAttribute('height', bbox.height + 100);
|
|
|
+ clonedSvg.setAttribute('viewBox', `${bbox.x - 50} ${bbox.y - 50} ${bbox.width + 100} ${bbox.height + 100}`);
|
|
|
+
|
|
|
+ // 序列化SVG
|
|
|
+ const serializer = new XMLSerializer();
|
|
|
+ const svgStr = serializer.serializeToString(clonedSvg);
|
|
|
+
|
|
|
+ // 创建Blob并下载
|
|
|
+ const blob = new Blob([svgStr], { type: 'image/svg+xml' });
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
+ const downloadLink = document.createElement('a');
|
|
|
+
|
|
|
+ // 生成文件名
|
|
|
+ const fileName = `麻城知识库思维导图_${new Date().toISOString().slice(0, 10)}.svg`;
|
|
|
+
|
|
|
+ downloadLink.href = url;
|
|
|
+ downloadLink.download = fileName;
|
|
|
+ document.body.appendChild(downloadLink);
|
|
|
+ downloadLink.click();
|
|
|
+ document.body.removeChild(downloadLink);
|
|
|
+
|
|
|
+ // 清理URL
|
|
|
+ setTimeout(() => URL.revokeObjectURL(url), 100);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('下载SVG时出错:', error);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|