editor-modal-drawio.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template lang='pug'>
  2. v-card.editor-modal-drawio.animated.fadeIn(flat, tile)
  3. iframe(
  4. ref='drawio'
  5. src='https://embed.diagrams.net/?embed=1&proto=json&spin=1&saveAndExit=0'
  6. frameborder='0'
  7. )
  8. </template>
  9. <script>
  10. import { sync, get } from 'vuex-pathify'
  11. const xmlTest = `<?xml version="1.0" encoding="UTF-8"?>
  12. <mxfile host="app.diagrams.net" modified="2020-07-10T23:41:09.492Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.61" etag="nuFLQDTKlZwSpOz4sG5q" version="13.4.2">
  13. <diagram id="SgbkCjxR32CZT1FvBvkp" name="Page-1">
  14. <mxGraphModel dx="2062" dy="1123" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
  15. <root>
  16. <mxCell id="0" />
  17. <mxCell id="1" parent="0" />
  18. <mxCell id="5gE3BTvRYS_8FoJnOusC-1" value="" style="whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1">
  19. <mxGeometry x="380" y="530" width="80" height="80" as="geometry" />
  20. </mxCell>
  21. </root>
  22. </mxGraphModel>
  23. </diagram>
  24. </mxfile>
  25. `
  26. export default {
  27. data() {
  28. return {
  29. }
  30. },
  31. computed: {
  32. editorKey: get('editor/editorKey'),
  33. activeModal: sync('editor/activeModal')
  34. },
  35. methods: {
  36. close () {
  37. this.activeModal = ''
  38. },
  39. overwriteAndClose() {
  40. this.$root.$emit('overwriteEditorContent')
  41. this.$root.$emit('resetEditorConflict')
  42. this.close()
  43. },
  44. send (msg) {
  45. this.$refs.drawio.contentWindow.postMessage(JSON.stringify(msg), '*')
  46. },
  47. receive (evt) {
  48. if (evt.frame === null || evt.source !== this.$refs.drawio.contentWindow || evt.data.length < 1) {
  49. return
  50. }
  51. try {
  52. const msg = JSON.parse(evt.data)
  53. switch (msg.event) {
  54. case 'init': {
  55. this.send({
  56. action: 'load',
  57. autosave: 0,
  58. saveAndExit: '0',
  59. modified: 'unsavedChanges',
  60. xml: xmlTest,
  61. title: this.$store.get('page/title')
  62. })
  63. break
  64. }
  65. case 'save': {
  66. console.info(msg)
  67. if (msg.exit) {
  68. this.close()
  69. } else {
  70. this.send({
  71. action: 'status',
  72. messageKey: 'allChangesSaved',
  73. modified: false
  74. })
  75. }
  76. break
  77. }
  78. case 'exit': {
  79. this.close()
  80. break
  81. }
  82. }
  83. } catch (err) {
  84. console.error(err)
  85. }
  86. }
  87. },
  88. async mounted () {
  89. window.addEventListener('message', this.receive)
  90. },
  91. beforeDestroy () {
  92. window.removeEventListener('message', this.receive)
  93. }
  94. }
  95. </script>
  96. <style lang='scss'>
  97. .editor-modal-drawio {
  98. position: fixed !important;
  99. top: 0;
  100. left: 0;
  101. z-index: 10;
  102. width: 100%;
  103. height: 100vh;
  104. background-color: rgba(255,255,255, 1) !important;
  105. overflow: hidden;
  106. > iframe {
  107. width: 100%;
  108. height: 100vh;
  109. border: 0;
  110. padding: 0;
  111. background-color: #FFF;
  112. }
  113. }
  114. </style>