Vue中使用mind-map实现在线思维导图

概述

在前面的文章Vue中实现在线画流程图实现中介绍了流程图的在线绘制,在本文,给大家分享一下基于mind-map实现在线的思维导图,并实现:1. 导图导出为图片;2. 打开xmind文件。

实现效果

图标选择

主题选择

结构选择

实现

1. mind-map简介

simple-mind-map(思绪思维导图)是一个简单&强大的Web思维导图库,不依赖任何特定框架。可以帮助你快速开发思维导图产品。

  • 在线文档:https://wanglin2.github.io/mind-map/#/index
  • 在线示例:https://wanglin2.github.io/mind-map/#/

2. 实现

1)添加依赖

{
    "simple-mind-map": "^0.10.2-fix.1",
}

2)引入插件

import MindMap from 'simple-mind-map'

3)插件导入

import MiniMap from 'simple-mind-map/src/plugins/MiniMap.js'
import Watermark from 'simple-mind-map/src/plugins/Watermark.js'
import KeyboardNavigation from 'simple-mind-map/src/plugins/KeyboardNavigation.js'
import ExportPDF from 'simple-mind-map/src/plugins/ExportPDF.js'
import ExportXMind from 'simple-mind-map/src/plugins/ExportXMind.js'
import Export from 'simple-mind-map/src/plugins/Export.js'
import Drag from 'simple-mind-map/src/plugins/Drag.js'
import Select from 'simple-mind-map/src/plugins/Select.js'
import AssociativeLine from 'simple-mind-map/src/plugins/AssociativeLine.js'
import TouchEvent from 'simple-mind-map/src/plugins/TouchEvent.js'
import NodeImgAdjust from 'simple-mind-map/src/plugins/NodeImgAdjust.js'
import SearchPlugin from 'simple-mind-map/src/plugins/Search.js'
import Painter from 'simple-mind-map/src/plugins/Painter.js'
import Formula from 'simple-mind-map/src/plugins/Formula.js'
import RainbowLines from 'simple-mind-map/src/plugins/RainbowLines.js'
import Demonstrate from 'simple-mind-map/src/plugins/Demonstrate.js'
import OuterFrame from 'simple-mind-map/src/plugins/OuterFrame.js'

// 注册插件
MindMap.usePlugin(MiniMap)
  .usePlugin(Watermark)
  .usePlugin(Drag)
  .usePlugin(KeyboardNavigation)
  .usePlugin(ExportPDF)
  .usePlugin(ExportXMind)
  .usePlugin(Export)
  .usePlugin(Select)
  .usePlugin(AssociativeLine)
  .usePlugin(NodeImgAdjust)
  .usePlugin(TouchEvent)
  .usePlugin(SearchPlugin)
  .usePlugin(Painter)
  .usePlugin(Formula)
  .usePlugin(RainbowLines)
  .usePlugin(Demonstrate)
  .usePlugin(OuterFrame)

4)自定义主题

import cactus from './themes/cactus'
import classic5 from './themes/classic5'
import classic6 from './themes/classic6'
import classic7 from './themes/classic7'
import dark3 from './themes/dark3'
import dark4 from './themes/dark4'
import darkNightLceBlade from './themes/darkNightLceBlade'
import index from './themes/index'
import lemonBubbles from './themes/lemonBubbles'
import morandi from './themes/morandi'
import neonLamp from './themes/neonLamp'
import oreo from './themes/oreo'
import rose from './themes/rose'
import seaBlueLine from './themes/seaBlueLine'
import shallowSea from './themes/shallowSea'

MindMap.defineTheme('cactus', cactus)
MindMap.defineTheme('classic5', classic5)
MindMap.defineTheme('classic6', classic6)
MindMap.defineTheme('classic7', classic7)
MindMap.defineTheme('dark3', dark3)
MindMap.defineTheme('dark4', dark4)
MindMap.defineTheme('darkNightLceBlade', darkNightLceBlade)
MindMap.defineTheme('index', index)
MindMap.defineTheme('lemonBubbles', lemonBubbles)
MindMap.defineTheme('morandi', morandi)
MindMap.defineTheme('neonLamp', neonLamp)
MindMap.defineTheme('oreo', oreo)
MindMap.defineTheme('rose', rose)
MindMap.defineTheme('seaBlueLine', seaBlueLine)
MindMap.defineTheme('shallowSea', shallowSea)

5)引入图标

import { nodeIconList } from 'simple-mind-map/src/svg/icons'

6)导出图片

mindMapInstance.export('png', true, this.name)

7)打开xmind文件

import xmind from 'simple-mind-map/src/parse/xmind.js'

{
  methods:{
      ElMessageBox.confirm('是否直接替换当前思维导图?', '警告', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      })
     .then(() => {
          const { raw } = file
          xmind.parseXmindFile(raw).then(data => {
            that.setData(data)
          })
        })
        .catch(() => {})
     }
}

完整代码如下:

<template>
  <div class="mind-map-container">
    <div class="mindmap-tools" v-show="!readonly">
      <el-upload
        ref="upload"
        style="margin-right: 0.8rem"
        :limit="1"
        :on-change="handleChange"
        :show-file-list="false"
        :accept="'.xmind'"
        :auto-upload="false"
      >
        <template #trigger>
          <el-button class="my-button" size="small">
            <div class="my-button">
              <svg
                t="1720518684993"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="29039"
                width="32"
                height="32"
              >
                <path
                  d="M910.19 175.16L776.1 41.07A136.94 136.94 0 0 0 679.27 1H235A161.29 161.29 0 0 0 73.69 162.25v699.5A161.29 161.29 0 0 0 235 1023h554a161.29 161.29 0 0 0 161.31-161.25V272a136.89 136.89 0 0 0-40.12-96.84z m-148.8 459.72c-1.53 8-14.94 8.24-36.72 11.59s-95.51 17.6-103 17.6-12.56-11.31-13.4-14.66-9.35-33.24-20.53-46.92-49.74-54.17-112.86-51.66-68.14 49.57-69.82 64.65 2.52 30.16-10.89 32.67-103 19.27-109.33 19.69-11.31-4.19-10.89-20.11 6.28-45.24 31.84-65.35 93.83-48.17 100.95-52.38 10.47-7.54 8-13.82-46.54-21.76-65.39-30.18-54.45-26-71.21-54.87-17.59-42.73-15.08-46.92S274 378 274 378s125.67-23 131.53-21.78 16.76 39.37 20.94 47.33 30.16 61.58 93.42 58.64 52.78-41 49.42-53-8.16-22.44-1.46-25.8 108.28-20.52 115.4-19.68 19.27 4.47 18.71 31.83-6.56 46.92-27.93 60.32-65.48 19.55-68.13 26.39 5.58 12.43 25.41 21.36 72.88 36 88.8 51.67 46.59 56.43 41.28 79.6z"
                  p-id="29040"
                  fill="currentColor"
                ></path>
              </svg>
              <div>打开xmind文件</div>
            </div>
          </el-button>
        </template>
      </el-upload>
      <el-button
        :disabled="activeNodes.length === 0"
        class="my-button"
        size="small"
        @click="addNode"
      >
        <div class="my-button">
          <svg
            t="1719284042715"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="32998"
            width="32"
            height="32"
          >
            <path
              d="M510.833431 62.695924c-247.644193 0-448.406636 200.762443-448.406636 448.406636 0 247.65545 200.762443 448.416869 448.406636 448.416869 247.65545 0 448.416869-200.76142 448.416869-448.416869C959.2503 263.458367 758.488881 62.695924 510.833431 62.695924zM779.544429 562.112328 560.358381 562.112328l0 219.186048-102.008278 0L458.350103 562.112328 239.164055 562.112328l0-102.008278 219.186048 0L458.350103 240.918002l102.008278 0 0 219.186048 219.186048 0L779.544429 562.112328z"
              fill="currentColor"
              p-id="32999"
            ></path>
          </svg>
          <div>添加同级节点</div>
        </div>
      </el-button>
      <el-button
        :disabled="activeNodes.length === 0"
        class="my-button"
        size="small"
        @click="addChildNode"
      >
        <div class="my-button">
          <svg
            t="1719283662028"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="23087"
            width="32"
            height="32"
          >
            <path
              d="M739.555556 0a56.888889 56.888889 0 0 1 56.888888 56.888889v227.555555a56.888889 56.888889 0 0 1-56.888888 56.888889H227.555556v455.111111h170.666666v-56.888888a56.888889 56.888889 0 0 1 56.888889-56.888889h512a56.888889 56.888889 0 0 1 56.888889 56.888889v227.555555a56.888889 56.888889 0 0 1-56.888889 56.888889H455.111111a56.888889 56.888889 0 0 1-56.888889-56.888889v-56.888889H170.666667a56.888889 56.888889 0 0 1-56.888889-56.888889V341.333333H56.888889a56.888889 56.888889 0 0 1-56.888889-56.888889V56.888889a56.888889 56.888889 0 0 1 56.888889-56.888889h682.666667z"
              fill="currentColor"
              p-id="23088"
            ></path>
          </svg>
          <div>添加子节点</div>
        </div>
      </el-button>
      <el-button
        :disabled="activeNodes.length === 0"
        class="my-button"
        size="small"
        @click="dropNode"
      >
        <div class="my-button">
          <svg
            t="1719283698787"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="24126"
            width="32"
            height="32"
          >
            <path
              d="M316.652201 74.043048L339.889115 28.356912A53.16921 53.16921 0 0 1 386.756789 0h250.486058a53.16921 53.16921 0 0 1 46.867674 28.356912l23.236914 45.686136a53.16921 53.16921 0 0 0 47.261521 28.356913h177.624547A51.987672 51.987672 0 0 1 984.615021 153.599941a51.987672 51.987672 0 0 1-52.381518 51.19998H91.766134A51.987672 51.987672 0 0 1 39.384615 153.599941a51.987672 51.987672 0 0 1 52.381519-51.19998h177.624547a53.16921 53.16921 0 0 0 47.26152-28.356913z m-118.153801 181.956854h630.153604a51.593826 51.593826 0 0 1 52.381518 51.19998v614.399764a101.218423 101.218423 0 0 1-30.719988 72.467664 105.944575 105.944575 0 0 1-74.043048 29.932296H250.879919a105.944575 105.944575 0 0 1-74.043049-29.932296 101.218423 101.218423 0 0 1-30.719988-72.467664V307.199882A51.593826 51.593826 0 0 1 196.923016 255.999902z m52.381519 153.59994v460.799823a51.987672 51.987672 0 0 0 52.775364 51.199981h419.839838a51.987672 51.987672 0 0 0 52.775365-51.199981V409.599842a51.987672 51.987672 0 0 0-52.775365-51.19998H303.655283a51.987672 51.987672 0 0 0-54.350748 51.19998z m157.538401 51.199981a51.987672 51.987672 0 0 1 52.775364 51.19998v255.999902a51.987672 51.987672 0 0 1-52.775364 51.19998 51.987672 51.987672 0 0 1-52.381519-51.19998V511.999803a51.987672 51.987672 0 0 1 50.806135-51.19998z m210.313765 0a51.987672 51.987672 0 0 1 52.381518 51.19998v255.999902a51.987672 51.987672 0 0 1-52.381518 51.19998 51.987672 51.987672 0 0 1-52.775364-51.19998V511.999803a51.987672 51.987672 0 0 1 51.19998-51.19998z"
              p-id="24127"
              fill="currentColor"
            ></path>
          </svg>
          <div>删除节点</div>
        </div>
      </el-button>
      <el-button
        :disabled="activeNodes.length === 0"
        class="my-button"
        size="small"
        @click="addGeneralization"
      >
        <div class="my-button">
          <svg
            t="1719283740026"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="26481"
            width="32"
            height="32"
          >
            <path
              d="M128 576h416a64 64 0 0 1 64 64v192a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64v-192a64 64 0 0 1 64-64z m32 64h352a32 32 0 0 1 32 32v128a32 32 0 0 1-32 32H160a32 32 0 0 1-32-32v-128a32 32 0 0 1 32-32zM128 128h416a64 64 0 0 1 64 64v192a64 64 0 0 1-64 64H128a64 64 0 0 1-64-64V192a64 64 0 0 1 64-64z m766.56 415.968A352.16 352.16 0 0 1 704 825.632c-23.68 3.52-35.52-7.2-35.52-32.224 0-15.584 11.84-29.568 35.52-41.92A287.712 287.712 0 0 0 832 512c0-99.84-50.816-187.84-128-239.488-23.68-14.848-35.52-29.536-35.52-44.064 0-25.568 11.84-35.584 35.52-30.08a352.16 352.16 0 0 1 190.56 281.664L896 480h32a32 32 0 0 1 0 64h-32l-1.44-0.032zM160 192h352a32 32 0 0 1 32 32v128a32 32 0 0 1-32 32H160a32 32 0 0 1-32-32V224a32 32 0 0 1 32-32z"
              fill="currentColor"
              p-id="26482"
            ></path>
          </svg>
          <div>添加概要</div>
        </div>
      </el-button>
      <el-button class="my-button" size="small" @click="exportPng">
        <div class="my-button">
          <svg
            t="1719283812353"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="28576"
            width="32"
            height="32"
          >
            <path
              d="M896.341333 128c23.381333 0 42.325333 18.986667 42.325334 42.368v398.890667A255.573333 255.573333 0 0 0 853.333333 554.666667V213.333333H170.666667l0.042666 597.333334 396.458667-396.501334a42.624 42.624 0 0 1 56.32-3.584l3.968 3.626667 151.296 151.466667a256.128 256.128 0 0 0-166.826667 330.368L127.658667 896A42.368 42.368 0 0 1 85.333333 853.632V170.368A42.666667 42.666667 0 0 1 127.658667 128h768.682666zM341.333333 298.666667a85.333333 85.333333 0 1 1 0 170.666666 85.333333 85.333333 0 0 1 0-170.666666z m512 469.333333v-128l170.666667 170.666667-170.666667 170.666666v-128h-170.666666v-85.333333h170.666666z"
              fill="currentColor"
              p-id="28577"
            ></path>
          </svg>
          <div>导出图片</div>
        </div>
      </el-button>
      <el-button
        :disabled="activeNodes.length === 0"
        :type="activedPanel === 'icon' ? 'primary' : 'default'"
        class="my-button"
        size="small"
        @click="activePanel('icon')"
      >
        <div class="my-button">
          <svg
            t="1719283775623"
            class="icon"
            viewBox="0 0 1026 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="27549"
            width="32"
            height="32"
          >
            <path
              d="M495.465 830.665c-187.138 0-264.948-168.222-268.193-175.401l62.966-28.307c2.486 5.49 62.207 134.667 205.194 134.667 153.067-1.795 211.302-129.213 213.685-134.633l63.103 27.996c-3.141 7.077-79.054 173.364-273.13 175.643l-3.625 0.034zM500.16 991.221c-256.974 0-466.034-209.060-466.034-466.034s209.060-466.034 466.034-466.034 466.034 209.060 466.034 466.034-209.060 466.034-466.034 466.034zM500.16 128.196c-218.897 0-396.991 178.094-396.991 396.991s178.094 396.991 396.991 396.991 396.991-178.094 396.991-396.991-178.059-396.991-396.991-396.991zM311.088 444.27c0 29.689 24.062 53.818 53.818 53.818s53.818-24.096 53.818-53.818-24.062-53.818-53.818-53.818-53.818 24.096-53.818 53.818zM580.765 444.27c0 29.689 24.062 53.818 53.818 53.818s53.818-24.096 53.818-53.818-24.062-53.818-53.818-53.818-53.818 24.096-53.818 53.818z"
              fill="currentColor"
              p-id="27550"
            ></path>
          </svg>
          <div>设置图标</div>
        </div>
      </el-button>
      <el-button
        :type="activedPanel === 'theme' ? 'primary' : 'default'"
        class="my-button"
        size="small"
        @click="activePanel('theme')"
      >
        <div class="my-button">
          <svg
            t="1719283846317"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="29654"
            width="32"
            height="32"
          >
            <path
              d="M772.8 96v64L936 321.6l-91.2 91.2c-12.8-11.2-27.2-16-43.2-16-36.8 0-65.6 28.8-65.6 65.6V800c0 35.2-28.8 64-64 64H352c-35.2 0-64-28.8-64-64V462.4c0-36.8-28.8-65.6-65.6-65.6-16 0-32 6.4-43.2 16L88 321.6 249.6 160h40l1.6 1.6C336 228.8 420.8 272 512 272c91.2 0 176-41.6 220.8-110.4 0-1.6 1.6-1.6 1.6-1.6h38.4V96m-481.6 0H256c-22.4 0-38.4 6.4-49.6 19.2L43.2 276.8c-25.6 25.6-25.6 65.6 0 89.6l94.4 94.4c11.2 11.2 27.2 17.6 41.6 17.6s30.4-6.4 41.6-17.6h1.6c1.6 0 1.6 0 1.6 1.6V800c0 70.4 57.6 128 128 128h320c70.4 0 128-57.6 128-128V462.4c0-1.6 0-1.6 1.6-1.6h1.6c11.2 11.2 27.2 17.6 41.6 17.6 16 0 30.4-6.4 41.6-17.6l94.4-94.4c25.6-25.6 25.6-65.6 0-89.6L819.2 115.2C806.4 102.4 790.4 96 772.8 96h-40c-22.4 0-41.6 11.2-54.4 30.4-33.6 49.6-96 81.6-168 81.6s-134.4-33.6-168-81.6C332.8 107.2 312 96 291.2 96z"
              fill="currentColor"
              p-id="29655"
            ></path>
          </svg>
          <div>选择主题</div>
        </div>
      </el-button>
      <el-button
        :type="activedPanel === 'layout' ? 'primary' : 'default'"
        class="my-button"
        size="small"
        @click="activePanel('layout')"
      >
        <div class="my-button">
          <svg
            t="1719283873990"
            class="icon"
            viewBox="0 0 1024 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="30805"
            width="32"
            height="32"
          >
            <path
              d="M938.666667 640h-64v-42.666667c0-72.533333-55.466667-128-128-128H554.666667V384h64c46.933333 0 85.333333-38.4 85.333333-85.333333V85.333333c0-46.933333-38.4-85.333333-85.333333-85.333333h-213.333334c-46.933333 0-85.333333 38.4-85.333333 85.333333v213.333334c0 46.933333 38.4 85.333333 85.333333 85.333333H469.333333v85.333333H277.333333c-72.533333 0-128 55.466667-128 128v29.866667c0 4.266667 0 8.533333 4.266667 12.8H85.333333c-46.933333 0-85.333333 38.4-85.333333 85.333333v213.333334c0 46.933333 38.4 85.333333 85.333333 85.333333h213.333334c46.933333 0 85.333333-38.4 85.333333-85.333333v-213.333334c0-46.933333-38.4-85.333333-85.333333-85.333333H230.4c0-4.266667 4.266667-8.533333 4.266667-12.8V597.333333c0-25.6 17.066667-42.666667 42.666666-42.666666h469.333334c25.6 0 42.666667 17.066667 42.666666 42.666666v42.666667H725.333333c-46.933333 0-85.333333 38.4-85.333333 85.333333v213.333334c0 46.933333 38.4 85.333333 85.333333 85.333333h213.333334c46.933333 0 85.333333-38.4 85.333333-85.333333v-213.333334c0-46.933333-38.4-85.333333-85.333333-85.333333zM298.666667 725.333333v213.333334H85.333333v-213.333334h213.333334zM405.333333 298.666667V85.333333h213.333334v213.333334h-213.333334zM938.666667 938.666667h-213.333334v-213.333334h213.333334v213.333334z"
              fill="currentColor"
              p-id="30806"
            ></path>
          </svg>
          <div>选择结构</div>
        </div>
      </el-button>
    </div>
    <div
      id="mindMapContainer"
      @dragenter.stop.prevent
      @dragleave.stop.prevent
      @dragover.stop.prevent
      @drop.stop.prevent
    ></div>
    <div class="active-panel" v-show="!readonly && activedPanel !== ''">
      <!-- 图标 -->
      <div class="active-panel-box" v-if="activedPanel === 'icon'">
        <div class="title">
          选择图标
          <span class="close" @click="activedPanel = ''">×</span>
        </div>
        <div class="content icon">
          <div class="icon-group" v-for="group of nodeIconList" :key="group.type">
            <div class="group-title">
              {{ group.name }}
            </div>
            <div class="group-content">
              <span
                class="icon-item"
                :class="activeNodes.length === 0 ? 'disabled' : ''"
                v-for="icon of group.list"
                :key="icon.name"
                @click="setIcon(group.type, icon.name)"
                v-html="icon.icon"
              ></span>
            </div>
          </div>
        </div>
      </div>
      <!-- 主题 -->
      <div class="active-panel-box" v-else-if="activedPanel === 'theme'">
        <div class="title">
          选择主题
          <span class="close" @click="activedPanel = ''">×</span>
        </div>
        <div class="content">
          <li
            v-for="item of themes"
            :key="item.value"
            @click="changeTheme(item.value)"
            :class="theme === item.value ? 'active' : ''"
          >
            <img :src="`/pages/online-doc/icons/theme/${item.value}.jpg`" />
            <div>{{ item.label }}</div>
          </li>
        </div>
      </div>
      <!-- 结构 -->
      <div class="active-panel-box" v-else-if="activedPanel === 'layout'">
        <div class="title">
          选择结构
          <span class="close" @click="activedPanel = ''">×</span>
        </div>
        <div class="content">
          <li
            v-for="item of layouts"
            :key="item.value"
            @click="changeLayout(item.value)"
            :class="layout === item.value ? 'active' : ''"
          >
            <img :src="`/pages/online-doc/icons/layout/${item.value}.png`" />
            <div>{{ item.label }}</div>
          </li>
        </div>
      </div>
    </div>
  </div>

  <div class="mind-map-scale">
    <el-button text @click="zoomOut">
      <span style="font-size: 1.2rem; font-weight: bold">─</span>
    </el-button>
    <el-input
      style="display: inline-block; width: 50px; text-align: center"
      v-model="showScale"
      disabled
    />
    <el-button text @click="zoomIn"><span style="font-size: 1.2rem">+</span></el-button>
  </div>
</template>

<script>
import MindMap from 'simple-mind-map'
import MiniMap from 'simple-mind-map/src/plugins/MiniMap.js'
import Watermark from 'simple-mind-map/src/plugins/Watermark.js'
import KeyboardNavigation from 'simple-mind-map/src/plugins/KeyboardNavigation.js'
import ExportPDF from 'simple-mind-map/src/plugins/ExportPDF.js'
import ExportXMind from 'simple-mind-map/src/plugins/ExportXMind.js'
import Export from 'simple-mind-map/src/plugins/Export.js'
import Drag from 'simple-mind-map/src/plugins/Drag.js'
import Select from 'simple-mind-map/src/plugins/Select.js'
import AssociativeLine from 'simple-mind-map/src/plugins/AssociativeLine.js'
import TouchEvent from 'simple-mind-map/src/plugins/TouchEvent.js'
import NodeImgAdjust from 'simple-mind-map/src/plugins/NodeImgAdjust.js'
import SearchPlugin from 'simple-mind-map/src/plugins/Search.js'
import Painter from 'simple-mind-map/src/plugins/Painter.js'
import Formula from 'simple-mind-map/src/plugins/Formula.js'
import RainbowLines from 'simple-mind-map/src/plugins/RainbowLines.js'
import Demonstrate from 'simple-mind-map/src/plugins/Demonstrate.js'
import OuterFrame from 'simple-mind-map/src/plugins/OuterFrame.js'
import { nodeIconList } from 'simple-mind-map/src/svg/icons'
import { ElMessageBox } from 'element-plus'
import xmind from 'simple-mind-map/src/parse/xmind.js'

import cactus from './themes/cactus'
import classic5 from './themes/classic5'
import classic6 from './themes/classic6'
import classic7 from './themes/classic7'
import dark3 from './themes/dark3'
import dark4 from './themes/dark4'
import darkNightLceBlade from './themes/darkNightLceBlade'
import index from './themes/index'
import lemonBubbles from './themes/lemonBubbles'
import morandi from './themes/morandi'
import neonLamp from './themes/neonLamp'
import oreo from './themes/oreo'
import rose from './themes/rose'
import seaBlueLine from './themes/seaBlueLine'
import shallowSea from './themes/shallowSea'

// 注册插件
MindMap.usePlugin(MiniMap)
  .usePlugin(Watermark)
  .usePlugin(Drag)
  .usePlugin(KeyboardNavigation)
  .usePlugin(ExportPDF)
  .usePlugin(ExportXMind)
  .usePlugin(Export)
  .usePlugin(Select)
  .usePlugin(AssociativeLine)
  .usePlugin(NodeImgAdjust)
  .usePlugin(TouchEvent)
  .usePlugin(SearchPlugin)
  .usePlugin(Painter)
  .usePlugin(Formula)
  .usePlugin(RainbowLines)
  .usePlugin(Demonstrate)
  .usePlugin(OuterFrame)

MindMap.defineTheme('cactus', cactus)
MindMap.defineTheme('classic5', classic5)
MindMap.defineTheme('classic6', classic6)
MindMap.defineTheme('classic7', classic7)
MindMap.defineTheme('dark3', dark3)
MindMap.defineTheme('dark4', dark4)
MindMap.defineTheme('darkNightLceBlade', darkNightLceBlade)
MindMap.defineTheme('index', index)
MindMap.defineTheme('lemonBubbles', lemonBubbles)
MindMap.defineTheme('morandi', morandi)
MindMap.defineTheme('neonLamp', neonLamp)
MindMap.defineTheme('oreo', oreo)
MindMap.defineTheme('rose', rose)
MindMap.defineTheme('seaBlueLine', seaBlueLine)
MindMap.defineTheme('shallowSea', shallowSea)

let mindMapInstance = null

window.mindMapInstance = mindMapInstance

export const defaultData = {
  data: {
    text: '根节点',
    expand: true,
    isActive: true,
  },
  children: [],
}

export default {
  props: {
    readonly: {
      type: Boolean,
      default: false,
    },
    name: {
      type: String,
      default: '思维导图',
    },
    mindData: {
      type: Object,
      default() {
        return defaultData
      },
    },
  },
  data() {
    return {
      nodeIconList,
      scale: 1,
      theme: 'classic4',
      //  default(默认)、classic(脑图经典)、minions(小黄人)、
      // pinkGrape(粉红葡萄)、mint(薄荷)、gold(金色vip)、vitalityOrange(活力橙)、
      // greenLeaf(绿叶)、dark2(暗色2)、skyGreen(天清绿)、classic2(脑图经典2)、
      // classic3(脑图经典3)、classic4(脑图经典4,v0.2.0+)、classicGreen(经典绿)、
      // classicBlue(经典蓝)、blueSky(天空蓝)、brainImpairedPink(脑残粉)、
      // dark(暗色)、earthYellow(泥土黄)、freshGreen(清新绿)、freshRed(清新红)、
      // romanticPurple(浪漫紫)、simpleBlack(v0.5.4+简约黑)、courseGreen(v0.5.4+课程绿)、
      // coffee(v0.5.4+咖啡)、redSpirit(v0.5.4+红色精神)、blackHumour(v0.5.4+黑色幽默)、
      // lateNightOffice(v0.5.4+深夜办公室)、blackGold(v0.5.4+黑金)、avocado(v.5.10-fix.2+牛油果)、
      // autumn(v.5.10-fix.2+秋天)、orangeJuice(v.5.10-fix.2+橙汁)
      themes: [
        { value: 'classic4', label: '脑图经典4' },
        { value: 'classic5', label: '脑图经典5' },
        { value: 'classic6', label: '脑图经典6' },
        { value: 'classic7', label: '脑图经典7' },
        { value: 'autumn', label: '秋天' },
        { value: 'cactus', label: '仙人掌' },
        { value: 'lemonBubbles', label: '柠檬气泡' },
        { value: 'coffee', label: '咖啡' },
        { value: 'courseGreen', label: '课程绿' },
        { value: 'gold', label: '金色vip' },
        { value: 'greenLeaf', label: '绿叶' },
        { value: 'minions', label: '小黄人' },
        { value: 'morandi', label: '莫兰迪' },
        { value: 'redSpirit', label: '红色精神' },
        { value: 'simpleBlack', label: '简约黑' },
        { value: 'vitalityOrange', label: '活力橙' },
        { value: 'oreo', label: '奥利奥' },
        { value: 'rose', label: '玫瑰' },
        { value: 'seaBlueLine', label: '海蓝线' },
        { value: 'shallowSea', label: '浅海' },
      ],
      layout: 'mindMap',
      layouts: [
        { value: 'mindMap', label: '思维导图' },
        { value: 'logicalStructure', label: '逻辑结构图' },
        { value: 'organizationStructure', label: '组织结构图' },
        { value: 'catalogOrganization', label: '目录组织图' },
        { value: 'timeline', label: '时间轴' },
        { value: 'timeline2', label: '时间轴2' },
        { value: 'fishbone', label: '鱼骨图' },
        { value: 'verticalTimeline', label: '垂直时间轴' },
      ],
      activeNodes: [],
      currentIconList: [],
      activedPanel: '',
    }
  },
  computed: {
    showScale() {
      return (this.scale * 100).toFixed(0)
    },
  },
  mounted() {
    this.init()
  },
  unmounted() {
    mindMapInstance.destroy()
  },
  watch: {
    mindData() {
      mindMapInstance.destroy()
      this.init()
    },
  },
  methods: {
    handleChange(file) {
      const that = this
      ElMessageBox.confirm('是否直接替换当前思维导图?', '警告', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const { raw } = file
          xmind.parseXmindFile(raw).then(data => {
            that.setData(data)
          })
        })
        .catch(() => {})
    },
    activePanel(type) {
      this.activedPanel = type === this.activedPanel ? '' : type
    },
    setIcon(type, name) {
      if (this.activeNodes.length === 0) return
      let key = type + '_' + name
      // 检查当前节点是否存在该图标
      let index = this.currentIconList.findIndex(item => {
        return item === key
      })
      // 存在则删除icon
      if (index !== -1) {
        this.currentIconList.splice(index, 1)
      } else {
        // 否则判断当前图标是否和要插入的图标是一个组的
        let typeIndex = this.currentIconList.findIndex(item => {
          return item.split('_')[0] === type
        })
        // 是一个组的则进行替换
        if (typeIndex !== -1) {
          this.currentIconList.splice(typeIndex, 1, key)
        } else {
          // 否则添加icon
          this.currentIconList.push(key)
        }
      }
      this.activeNodes.forEach(node => {
        node.setIcon([...this.currentIconList])
      })
    },
    addRelationLine() {
      mindMapInstance.createLineFromActiveNode()
    },
    addGeneralization() {
      mindMapInstance.execCommand('ADD_GENERALIZATION')
    },
    dropNode() {
      mindMapInstance.execCommand('REMOVE_NODE')
    },
    addNode() {
      mindMapInstance.execCommand('INSERT_NODE')
    },
    addChildNode() {
      mindMapInstance.execCommand('INSERT_CHILD_NODE')
    },
    changeTheme(theme) {
      this.theme = theme
      mindMapInstance.setTheme(theme)
    },
    changeLayout(layout) {
      this.layout = layout
      mindMapInstance.setLayout(layout)
    },
    zoomMap(e) {
      mindMapInstance.view.setScale(e)
    },
    zoomIn() {
      let scale = mindMapInstance.view.scale
      scale += 0.2
      if (scale > 2) scale = 2
      mindMapInstance.view.setScale(scale)
    },
    zoomOut() {
      let scale = mindMapInstance.view.scale
      scale -= 0.2
      if (scale < 0.1) scale = 0.1
      mindMapInstance.view.setScale(scale)
    },
    getData() {
      return mindMapInstance.getData(true)
    },
    setData(data) {
      mindMapInstance.setData(data)
    },
    exportPng() {
      mindMapInstance.export('png', true, this.name)
    },
    init() {
      const data = this.mindData || defaultData
      let mindData = data
      if (data.root) {
        this.layout = data.layout
        this.theme = data.theme.template
        mindData = data.root
      }
      mindMapInstance = new MindMap({
        enableFreeDrag: false,
        readonly: this.readonly,
        layout: this.layout, // 'logicalStructure',
        theme: this.theme,
        el: document.getElementById('mindMapContainer'),
        mousewheelAction: 'zoom', // zoom(放大缩小)、move(上下移动)
        data: mindData,
        fit: true,
        nodeTextEditZIndex: 1000,
        nodeNoteTooltipZIndex: 1000,
        initRootNodePosition: ['center', 'center'],
      })
      mindMapInstance.on('scale', e => {
        this.scale = Number(e.toFixed(2))
      })
      mindMapInstance.on('node_active', (...args) => {
        this.activeNodes = args[1]
        if (this.activeNodes.length > 0) {
          let firstNode = this.activeNodes[0]
          this.currentIconList = firstNode.getData('icon') || []
        } else {
          this.currentIconList = []
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.mind-map-container,
#mindMapContainer {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}
.my-button {
  svg {
    width: 1.5rem;
    height: 1.5rem;
  }
  width: 6rem;
  height: 3.8rem;
  text-align: center;
  line-height: 1.5rem;
  margin-top: 0.8rem;
}
.mindmap-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: row;
  justify-content: center;
  width: 100%;
  align-items: center;
}

$iconSize: 1.4rem;

.active-panel {
  position: absolute;
  top: 10rem;
  right: 5px;
  bottom: 10rem;
  width: 16rem;
  background: white;
  user-select: none;
  .active-panel-box {
    height: 100%;
    .title {
      height: 3rem;
      line-height: 3rem;
      padding: 0 0.8rem;
      font-weight: bold;
      font-size: 1.1rem;
      border-bottom: 1px solid #ccc;
      .close {
        float: right;
        cursor: pointer;
        font-size: 1.3rem;
      }
    }
    .content {
      height: calc(100% - 3rem);
      overflow-y: auto;
      overflow-x: hidden;
      padding: 1rem;
      &.icon {
        padding-right: 0.5rem;
      }

      .icon-group {
        margin-top: 1rem;
        line-height: 2;
        &:first-child {
          margin-top: 0;
        }
      }
      .group-title {
        font-weight: bold;
      }
      .group-content {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        .icon-item {
          width: $iconSize;
          height: $iconSize;
          margin-right: 0.4rem;
          margin-top: 0.4rem;
          cursor: pointer;
          &.disabled {
            cursor: not-allowed;
            opacity: 0.5;
          }
          svg {
            width: $iconSize;
            height: $iconSize;
          }
        }
      }

      li {
        list-style: none;
        text-align: center;
        margin-top: 1rem;
        border: 1px solid #ccc;
        border-radius: 4px;
        &:first-child {
          margin-top: 0;
        }
        &:hover {
          cursor: pointer;
          box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
        }
        &.active {
          border: 1px solid #67c23a;
          box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
        }
        img {
          width: 100%;
          height: 8rem;
        }
      }
    }
  }
}
.mind-map-scale {
  position: absolute;
  bottom: -1rem;
  right: 1rem;
  z-index: 99;
  background: #efefef;
  border-radius: 5px;
  opacity: 0.8;
}
:deep .mind-map-scale {
  .el-input__wrapper .el-input__inner {
    text-align: center !important;
  }
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/800724.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

随笔(三):CSS

一、CSS .&#xff08;类选择器&#xff09;和 #&#xff08;ID选择器&#xff09;在CSS中的主要区别在于它们的选择范围和用途&#xff1a; 1. 选择范围 类选择器&#xff08;. 开头&#xff09;&#xff1a; 类选择器用于选择具有指定类名的所有HTML元素。由于一个HTML元素…

spring boot基础知识

spring boot是整合spring 一系列的包的坐标集合 对依赖进行整合 总体介绍 spring boot是用来方便构建项目的工具 spring cloud是用来方便spring boot项目之间进行数据交互通讯和配置的 spring cloud data Flow 是用来进行数据的连接的 Spring 缺点 配置繁琐 虽然Spring的组件代…

超市管理系统 需求分析与设计 UML 方向

一、项目介绍 1.1项目背景 随着经济一体化和电子商务的迅速发展&#xff0c;网络传播信息的速度打破了传统信息传递的模式&#xff0c;互联网的高速发展和计算机应用在各个高校进展迅速&#xff0c;更多信息化产品的突飞猛进&#xff0c;让现代的管理模式也发生了巨大的变化&…

vue数据缓存

data 对象未定义或未正确传递&#xff1a;确保 data 对象在你调用 onMounted 钩子时已经存在且包含 base.columns 属性。 columns 响应式引用未定义&#xff1a;确保 columns 是一个使用 ref 或 reactive 创建的响应式引用。 异步数据问题&#xff1a;如果 data 是通过异步操…

vue 搭建 pinia

文章目录 环境设置存储读取数据【 storeToRefs】借助storeToRefs将store中的数据转为ref对象&#xff0c;方便在模板中使用【getters】当state中的数据&#xff0c;需要经过处理后再使用时&#xff0c;可以使用getters配置【$subscribe】通过 store 的 $subscribe() 方法侦听 s…

用动态规划算法均分纸牌,谈谈理解思路

&#x1f3c6;本文收录于《CSDN问答解答》专栏&#xff0c;主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案&#xff0c;希望能够助你一臂之力&#xff0c;帮你早日登顶实现财富自由&#x1f680;&#xff1b;同时&#xff0c;欢迎大家关注&&收藏&…

升级自动交易!打通miniQMT接口!股票量化分析工具QTYX-V2.8.7

前言 我们的股票量化系统QTYX在实战中不断迭代升级!!! 我们用Python搭建自己的量化交易系统&#xff0c;之前主要以手动交易或者是easytrader库为主&#xff0c;属于曲线救国的方案。 在大家的强烈推荐下&#xff0c;我们决定使用正规的量化交易平台作为下单的最后环节——QMT&…

【Visual Studio】Visual Studio使用技巧及报错解决合集

目录 目录 一.概述 二.Visual Studio报错问题及解决方法 三.Visual Studio操作过程中遇到的问题及解决方法 四.Visual Studio编译优化选项 五.Visual Studio快捷键 一.概述 持续更新Visual Studio报错及解决方法&#xff0c;包括Visual Studio报错问题及解决方法、Visua…

mac安装win10到外接固态硬盘

1、制作win10系统 1.1 下载 winToUSB&#xff0c;打开后选择第一个 1.2 选择本地下载镜像&#xff0c; 我用的分区方案是适用于UEFI的GPT模式 1.3 点右下角执行&#xff0c;等待执行完成即可 2、mac系统下载win驱动 2.1 comman空格 搜索启动转换助理&#xff0c;打开后选择…

Ubuntu 22.04.4 LTS (linux) 安装certbot 免费ssl证书申请 letsencrypt

1 安装certbot sudo apt update sudo apt-get install certbot 2 申请letsencrypt证书 sudo certbot certonly --webroot -w 网站目录 -d daloradius.域名.com 3 修改nginx 配置ssl 证书 # 配置服务器证书 ssl_certificate /etc/letsencrypt/live/daloradius.域名.com/f…

浅谈后置处理器之正则表达式提取器

浅谈后置处理器之正则表达式提取器 JMeter是一款功能强大的开源负载测试工具&#xff0c;广泛应用于Web应用、数据库等的性能测试。在进行接口测试或负载测试时&#xff0c;经常需要从服务器响应中提取某些数据作为后续请求的参数。这时&#xff0c;“正则表达式提取器”&…

Web开发:<br>标签的作用

br作用 介绍基本用法常见用途注意事项使用CSS替代 介绍 在Web开发中&#xff0c;<br> 标签是一个用于插入换行符的HTML标签。它是“break”的缩写&#xff0c;常用于需要在文本中强制换行的地方。<br> 标签是一个空标签&#xff0c;这意味着它没有结束标签。 基本…

HTML+CSS+JS用户管理(可储存用户数据)

使用cookies记录账号密码信息&#xff0c;可以注册、登录、注销账号。 点赞❤️收藏⭐️关注&#x1f60d; 效果图 源代码在效果图后面 源代码 HTML <!DOCTYPE html> <html lang"en"> <head> <meta charset"UTF-8"> <…

无人机图像目标检测

本仓库是人工智能课程的课程作业仓库&#xff0c;主要是完成无人机图像目标检测的任务&#xff0c;我们对visdrone数据集进行了处理&#xff0c;在yolo和ssd两种框架下进行了训练和测试&#xff0c;并编写demo用于实时的无人机图像目标检测。 requirements依赖&#xff1a; ss…

OpenGL笔记一之基础窗体搭建以及事件响应

OpenGL笔记一之基础窗体搭建以及事件响应 bilibili赵新政老师的教程看后笔记 code review! 文章目录 OpenGL笔记一之基础窗体搭建以及事件响应1.运行2.目录结构3.main.cpp4.CMakeList.txt 1.运行 2.目录结构 01_GLFW_WINDOW/ ├── CMakeLists.txt ├── glad.c ├── ma…

效能工具:执行 npm start 可直接切换proxy代理UR后直接启动项目

1) 背景: 我们项目是2个前端3个后端的配置。前端和每个后端都有需要调试的接口。 因此经常切换vite.congig.js中的proxy后端代理链接&#xff0c;是挺麻烦的。 于是我研究如何能快速切换后端URL&#xff0c;所幸懒人有懒福&#xff0c;我找到了Inquirer 和 fs&#xff0c; 实…

MySQL NaviCat 安装及配置教程(Windows)【安装】

文章目录 一、 MySQL 下载1. 官网下载2. 其它渠道 二、 MySQL 安装三、 MySQL 验证及配置四、 NaviCat 下载1. 官网下载2. 其它渠道 五、 NaviCat 安装六、 NaviCat 激活 软件 / 环境安装及配置目录 一、 MySQL 下载 1. 官网下载 安装地址&#xff1a;https://www.mysql.com/…

人员定位管理系统有怎样优势?这4点不可忽视

众所周知&#xff0c;人员定位管理系统是通过物联网和云计算等技术&#xff0c;记录所有员工的基本信息&#xff0c;将员工位置、工作情况、运动轨迹等信息上传给系统&#xff0c;全面记录和直观的展现厂区内所有工作人员的具体情况。 除了能够查看人员位置情况外&#xff0c;人…

【C++题解】1168. 歌唱比赛评分

问题&#xff1a;1168. 歌唱比赛评分 类型&#xff1a;数组找数 题目描述&#xff1a; 四&#xff08;1&#xff09; 班要举行一次歌唱比赛&#xff0c;以选拔更好的苗子参加校的歌唱比赛。评分办法如下&#xff1a;设 N 个评委&#xff0c;打 N 个分数&#xff08; 0≤每个分…

分手后失眠之夜:如何安放那颗无处安放的心

在人生的旅途中&#xff0c;我们总会遇到一些人&#xff0c;他们像流星般划过天际&#xff0c;给我们带来瞬间的绚烂&#xff0c;却也留下了长久的寂寥。当感情走到尽头&#xff0c;分手成为无法回避的现实&#xff0c;你是否也曾躺在床上&#xff0c;辗转反侧&#xff0c;难以…