index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. import JSPDF from "jspdf";
  38. export default {
  39. name: "Flow",
  40. props: {
  41. value: {
  42. type: ''
  43. },
  44. readOnly: {
  45. type: Boolean,
  46. default: false
  47. },
  48. },
  49. data() {
  50. return {
  51. loadIng: true,
  52. flow: null,
  53. url: window.location.origin + '/js/grapheditor/' + (this.readOnly ? 'viewer' : 'index') + '.html',
  54. }
  55. },
  56. mounted() {
  57. window.addEventListener('message', this.handleMessage)
  58. this.flow = this.$refs.myFlow.contentWindow;
  59. },
  60. activated() {
  61. window.addEventListener('message', this.handleMessage)
  62. this.flow = this.$refs.myFlow.contentWindow;
  63. },
  64. methods: {
  65. handleMessage (event) {
  66. const data = event.data;
  67. switch (data.act) {
  68. case 'ready':
  69. this.loadIng = false;
  70. this.flow.postMessage({
  71. act: 'setXml',
  72. params: {
  73. xml: this.value,
  74. }
  75. }, '*')
  76. break
  77. case 'change':
  78. this.$emit('input', data.params.xml);
  79. break
  80. case 'imageContent':
  81. let pdf = new JSPDF({
  82. format: [data.params.width, data.params.height]
  83. });
  84. pdf.addImage(data.params.content, 'PNG', 0, 0, 0, 0);
  85. pdf.save(`${data.params.name}.pdf`);
  86. break
  87. }
  88. },
  89. exportPNG(name, scale = 10) {
  90. this.flow.postMessage({
  91. act: 'exportPNG',
  92. params: {
  93. name: name || this.$L('无标题'),
  94. scale: scale,
  95. type: 'png',
  96. }
  97. }, '*')
  98. },
  99. exportPDF(name, scale = 10) {
  100. this.flow.postMessage({
  101. act: 'exportPNG',
  102. params: {
  103. name: name || this.$L('无标题'),
  104. scale: scale,
  105. type: 'imageContent',
  106. }
  107. }, '*')
  108. }
  109. },
  110. }
  111. </script>