templateView.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="templateViewPanel">
  3. <div id="jsmind_container"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import jsMind from "@/lib/jsmind";
  8. import "@/assets/common/css/jsmind.css";
  9. export default {
  10. name: "templateView", // 模板预览
  11. components: {},
  12. data() {
  13. return {
  14. mind: {},
  15. jm: {},
  16. options: {
  17. container: "jsmind_container",
  18. editable: false,
  19. theme: "primary",
  20. mode: "side",
  21. },
  22. };
  23. },
  24. props: {
  25. viewData: {
  26. type: Array,
  27. default: [],
  28. },
  29. errArr: {
  30. type: Array,
  31. default: [],
  32. },
  33. },
  34. watch: {
  35. viewData(val) {
  36. if (val && val.length > 0) {
  37. this.load_jsmind();
  38. }
  39. },
  40. },
  41. methods: {
  42. // 用jsmind插件,进行模板预览
  43. load_jsmind() {
  44. this.mind = {
  45. meta: {
  46. name: "templateView",
  47. },
  48. format: "node_array",
  49. data: this.viewData,
  50. };
  51. this.jm.show(this.mind);
  52. this.jm.expand_all();
  53. this.jm.enable_edit();
  54. this.errArr.forEach((i) => {
  55. this.jm.set_node_color(i, "red");
  56. });
  57. this.jm.disable_edit();
  58. },
  59. },
  60. mounted() {
  61. this.jm = new jsMind(this.options);
  62. this.load_jsmind();
  63. setTimeout(()=>{
  64. let body = $('.templateViewDia .el-dialog__body').height();
  65. let panel = $('.templateViewDia .templateViewPanel').height();
  66. if(panel < body - 10 ) {
  67. $('.templateViewDia .el-dialog__body').addClass('toCenter');
  68. }
  69. }, 0)
  70. },
  71. };
  72. </script>
  73. <style lang='less' scoped>
  74. .templateViewPanel {
  75. display: flex;
  76. justify-content: center;
  77. align-items: center;
  78. #jsmind_container {
  79. // display: flex;
  80. // justify-content: center;
  81. // align-items: center;
  82. // width: 94%;
  83. // height: calc(100% - 130px);
  84. // height: 100%;
  85. // min-height: 400px;
  86. // border: solid 1px #ccc;
  87. // background: #f4f4f4;
  88. overflow: auto;
  89. }
  90. }
  91. </style>