index.vue 2.2 KB

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