index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="flow-content">
  3. <iframe ref="myFlow" class="flow-iframe" :src="url"></iframe>
  4. </div>
  5. </template>
  6. <style lang="scss" scoped>
  7. .flow-content {
  8. position: absolute;
  9. top: 0;
  10. left: 0;
  11. width: 100%;
  12. height: 100%;
  13. .flow-iframe {
  14. position: absolute;
  15. top: 0;
  16. left: 0;
  17. width: 100%;
  18. height: 100%;
  19. background: 0 0;
  20. border: 0;
  21. float: none;
  22. margin: -1px 0 0;
  23. max-width: none;
  24. outline: 0;
  25. padding: 0;
  26. }
  27. }
  28. </style>
  29. <script>
  30. export default {
  31. name: "Flow",
  32. props: {
  33. value: {
  34. type: ''
  35. },
  36. },
  37. data() {
  38. return {
  39. flow: null,
  40. url: window.location.origin + '/js/grapheditor/index.html',
  41. }
  42. },
  43. mounted() {
  44. window.addEventListener('message', this.handleMessage)
  45. this.flow = this.$refs.myFlow.contentWindow;
  46. },
  47. activated() {
  48. window.addEventListener('message', this.handleMessage)
  49. this.flow = this.$refs.myFlow.contentWindow;
  50. },
  51. methods: {
  52. handleMessage (event) {
  53. // 根据上面制定的结构来解析iframe内部发回来的数据
  54. const data = event.data;
  55. switch (data.act) {
  56. case 'ready':
  57. this.flow.postMessage({
  58. act: 'setXml',
  59. params: {
  60. xml: this.value,
  61. }
  62. }, '*')
  63. break
  64. case 'change':
  65. this.$emit('input', data.params.xml);
  66. break
  67. }
  68. }
  69. },
  70. }
  71. </script>