Demo:导出png、pdf、svg支持设置底部自定义文字

This commit is contained in:
街角小林 2024-03-28 19:06:10 +08:00
parent 614aa1ec30
commit c6f8f38648
5 changed files with 78 additions and 8 deletions

View File

@ -130,7 +130,9 @@ export default {
paddingX: 'Padding x', paddingX: 'Padding x',
paddingY: 'Padding y', paddingY: 'Padding y',
useMultiPageExport: 'Export multi page', useMultiPageExport: 'Export multi page',
defaultFileName: 'Mind map' defaultFileName: 'Mind map',
addFooterTextPlaceholder: 'For example: From simple-mind-map',
addFooterText: 'Add text at the footer'
}, },
fullscreen: { fullscreen: {
fullscreenShow: 'Full screen show', fullscreenShow: 'Full screen show',
@ -278,7 +280,8 @@ export default {
splitByWrap: 'Is automatically split nodes based on line breaks?', splitByWrap: 'Is automatically split nodes based on line breaks?',
tip: 'Tip', tip: 'Tip',
yes: 'Yes', yes: 'Yes',
no: 'No' no: 'No',
exportError: 'Export failed'
}, },
mouseAction: { mouseAction: {
tip1: tip1:

View File

@ -128,7 +128,9 @@ export default {
paddingX: '水平内边距', paddingX: '水平内边距',
paddingY: '垂直内边距', paddingY: '垂直内边距',
useMultiPageExport: '是否多页导出', useMultiPageExport: '是否多页导出',
defaultFileName: '思维导图' defaultFileName: '思维导图',
addFooterText: '底部添加文字',
addFooterTextPlaceholder: '比如来自simple-mind-map'
}, },
fullscreen: { fullscreen: {
fullscreenShow: '全屏查看', fullscreenShow: '全屏查看',
@ -274,7 +276,8 @@ export default {
splitByWrap: '是否按换行自动分割节点?', splitByWrap: '是否按换行自动分割节点?',
tip: '提示', tip: '提示',
yes: '是', yes: '是',
no: '否' no: '否',
exportError: '导出失败'
}, },
mouseAction: { mouseAction: {
tip1: '当前:左键拖动画布,右键框选节点', tip1: '当前:左键拖动画布,右键框选节点',

View File

@ -156,7 +156,8 @@ export default {
useLeftKeySelectionRightKeyDrag: state => useLeftKeySelectionRightKeyDrag: state =>
state.localConfig.useLeftKeySelectionRightKeyDrag, state.localConfig.useLeftKeySelectionRightKeyDrag,
isUseHandDrawnLikeStyle: state => isUseHandDrawnLikeStyle: state =>
state.localConfig.isUseHandDrawnLikeStyle state.localConfig.isUseHandDrawnLikeStyle,
extraTextOnExport: state => state.extraTextOnExport
}) })
}, },
watch: { watch: {
@ -348,12 +349,55 @@ export default {
console.error(err) console.error(err)
switch (code) { switch (code) {
case 'export_error': case 'export_error':
this.$message.error('导出失败') this.$message.error(this.$t('edit.exportError'))
break break
default: default:
break break
} }
},
addContentToFooter: () => {
const text = this.extraTextOnExport.trim()
if (!text) return null
const el = document.createElement('div')
el.className = 'footer'
el.innerHTML = text
const cssText = `
.footer {
width: 100%;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
font-size: 12px;
color: #979797;
}
`
return {
el,
cssText,
height: 30
}
} }
// addContentToHeader: () => {
// const el = document.createElement('div')
// el.className = 'footer'
// el.innerHTML = ''
// const cssText = `
// .header {
// width: 100%;
// height: 50px;
// background: #f5f5f5;
// display: flex;
// justify-content: center;
// align-items: center
// }
// `
// return {
// el,
// cssText,
// height: 50
// }
// },
// beforeShortcutRun: (key, activeNodeList) => { // beforeShortcutRun: (key, activeNodeList) => {
// console.log(key, activeNodeList) // console.log(key, activeNodeList)
// // // //

View File

@ -50,6 +50,16 @@
@keydown.native.stop @keydown.native.stop
></el-input> ></el-input>
</div> </div>
<div class="paddingInputGroup">
<span class="name">{{ this.$t('export.addFooterText') }}</span>
<el-input
style="width: 200px"
v-model="extraText"
size="mini"
:placeholder="$t('export.addFooterTextPlaceholder')"
@keydown.native.stop
></el-input>
</div>
<div class="paddingInputGroup"> <div class="paddingInputGroup">
<el-checkbox <el-checkbox
v-show="['png', 'pdf'].includes(exportType)" v-show="['png', 'pdf'].includes(exportType)"
@ -85,7 +95,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import { downTypeList } from '@/config' import { downTypeList } from '@/config'
import { isMobile } from 'simple-mind-map/src/utils/index' import { isMobile } from 'simple-mind-map/src/utils/index'
@ -107,6 +117,7 @@ export default {
loadingText: '', loadingText: '',
paddingX: 10, paddingX: 10,
paddingY: 10, paddingY: 10,
extraText: '',
isMobile: isMobile() isMobile: isMobile()
} }
}, },
@ -127,6 +138,8 @@ export default {
this.$bus.$off('showExport', this.handleShowExport) this.$bus.$off('showExport', this.handleShowExport)
}, },
methods: { methods: {
...mapMutations(['setExtraTextOnExport']),
handleShowExport() { handleShowExport() {
this.dialogVisible = true this.dialogVisible = true
}, },
@ -153,6 +166,7 @@ export default {
* @Desc: 确定 * @Desc: 确定
*/ */
confirm() { confirm() {
this.setExtraTextOnExport(this.extraText)
if (this.exportType === 'svg') { if (this.exportType === 'svg') {
this.$bus.$emit( this.$bus.$emit(
'export', 'export',

View File

@ -26,7 +26,8 @@ const store = new Vuex.Store({
activeSidebar: '', // 当前显示的侧边栏 activeSidebar: '', // 当前显示的侧边栏
isOutlineEdit: false, // 是否是大纲编辑模式 isOutlineEdit: false, // 是否是大纲编辑模式
isReadonly: false, // 是否只读 isReadonly: false, // 是否只读
isSourceCodeEdit: false// 是否是源码编辑模式 isSourceCodeEdit: false, // 是否是源码编辑模式
extraTextOnExport: ''// 导出时底部添加的文字
}, },
mutations: { mutations: {
// 设置思维导图数据 // 设置思维导图数据
@ -67,6 +68,11 @@ const store = new Vuex.Store({
setIsOutlineEdit(state, data) { setIsOutlineEdit(state, data) {
state.isSourceCodeEdit = data state.isSourceCodeEdit = data
}, },
// 设置导出时底部添加的文字
setExtraTextOnExport(state, data) {
state.extraTextOnExport = data
}
}, },
actions: { actions: {
// 设置初始思维导图数据 // 设置初始思维导图数据