index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 v-if="readOnly && zoom > 0" class="zoom-box" :class="{'zoom-ing': zoomIng}">
  6. <div class="zoom-svg">
  7. <svg t="1600613502044" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1161" width="18" height="18"><path d="M598.646154 401.723077H279.630769c-15.753846 0-27.569231 11.815385-27.569231 31.507692 0 15.753846 11.815385 27.569231 31.507693 27.569231h319.015384c15.753846 0 27.569231-11.815385 27.569231-31.507692 0-15.753846-15.753846-27.569231-31.507692-27.569231z" fill="#666666" p-id="1162"></path><path d="M921.6 850.707692l-204.8-196.923077c47.261538-59.076923 78.769231-137.846154 78.769231-220.553846 0-196.923077-157.538462-354.461538-354.461539-354.461538s-354.461538 157.538462-354.461538 354.461538 157.538462 354.461538 354.461538 354.461539c90.584615 0 173.292308-35.446154 236.307693-90.584616l204.8 196.923077c3.938462 3.938462 11.815385 7.876923 19.692307 7.876923s15.753846-3.938462 19.692308-7.876923c11.815385-15.753846 11.815385-35.446154 0-43.323077z m-484.430769-126.030769c-161.476923 0-295.384615-133.907692-295.384616-295.384615S275.692308 133.907692 437.169231 133.907692s295.384615 133.907692 295.384615 295.384616-129.969231 295.384615-295.384615 295.384615z" fill="#666666" p-id="1163"></path></svg>
  8. <svg t="1600613514136" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1403" width="18" height="18"><path d="M929.476923 854.646154l-212.676923-200.861539c47.261538-59.076923 78.769231-137.846154 78.769231-220.553846 0-196.923077-157.538462-354.461538-354.461539-354.461538s-354.461538 157.538462-354.461538 354.461538 157.538462 354.461538 354.461538 354.461539c90.584615 0 173.292308-35.446154 236.307693-90.584616l212.676923 200.861539c3.938462 3.938462 11.815385 7.876923 19.692307 7.876923s15.753846-3.938462 19.692308-7.876923c11.815385-11.815385 11.815385-31.507692 0-43.323077z m-488.369231-126.030769c-161.476923 0-295.384615-133.907692-295.384615-295.384616s133.907692-295.384615 295.384615-295.384615 295.384615 133.907692 295.384616 295.384615-133.907692 295.384615-295.384616 295.384616z" fill="#666666" p-id="1404"></path><path d="M598.646154 401.723077h-129.969231V271.753846c0-15.753846-11.815385-31.507692-31.507692-31.507692s-31.507692 11.815385-31.507693 31.507692v129.969231H279.630769c-15.753846 0-31.507692 11.815385-31.507692 31.507692s11.815385 31.507692 31.507692 31.507693h129.969231V590.769231c0 15.753846 11.815385 31.507692 31.507692 31.507692s31.507692-11.815385 31.507693-31.507692v-129.969231h129.96923c15.753846 0 31.507692-11.815385 31.507693-31.507692s-15.753846-27.569231-35.446154-27.569231z" fill="#666666" p-id="1405"></path></svg>
  9. </div>
  10. <Slider class="zoom-slider" v-model="zoom" :min="1" :max="300" :tip-format="formatZoom" @on-change="zoomIng=false" @on-input="zoomIng=true"></Slider>
  11. </div>
  12. </div>
  13. </template>
  14. <style lang="scss" scoped>
  15. .flow-content {
  16. position: absolute;
  17. top: 0;
  18. left: 0;
  19. width: 100%;
  20. height: 100%;
  21. .flow-iframe {
  22. position: absolute;
  23. top: 0;
  24. left: 0;
  25. width: 100%;
  26. height: 100%;
  27. background: 0 0;
  28. border: 0;
  29. float: none;
  30. margin: -1px 0 0;
  31. max-width: none;
  32. outline: 0;
  33. padding: 0;
  34. }
  35. .flow-loading {
  36. position: absolute;
  37. top: 50%;
  38. left: 50%;
  39. transform: translate(-50%, -50%);
  40. }
  41. .zoom-box {
  42. position: absolute;
  43. left: 20px;
  44. bottom: 20px;
  45. height: 34px;
  46. max-width: 50%;
  47. border-radius: 3px;
  48. box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
  49. background-color: #fff;
  50. color: #666;
  51. z-index: 10;
  52. padding: 0 6px;
  53. .zoom-svg {
  54. height: 34px;
  55. display: flex;
  56. align-items: center;
  57. .icon {
  58. margin: 0 6px;
  59. }
  60. }
  61. .zoom-slider {
  62. display: none;
  63. padding: 0 10px;
  64. width: 300px;
  65. max-width: 100%;
  66. }
  67. &:hover,
  68. &.zoom-ing {
  69. .zoom-svg {
  70. display: none;
  71. }
  72. .zoom-slider {
  73. display: inline-block;
  74. }
  75. }
  76. }
  77. }
  78. </style>
  79. <script>
  80. import JSPDF from "jspdf";
  81. export default {
  82. name: "Flow",
  83. props: {
  84. value: {
  85. type: Object,
  86. default: function () {
  87. return {}
  88. }
  89. },
  90. readOnly: {
  91. type: Boolean,
  92. default: false
  93. },
  94. },
  95. data() {
  96. return {
  97. loadIng: true,
  98. flow: null,
  99. url: window.location.origin + '/js/grapheditor/' + (this.readOnly ? 'viewer' : 'index') + '.html',
  100. zoom: -1,
  101. zoomIng: false,
  102. }
  103. },
  104. mounted() {
  105. window.addEventListener('message', this.handleMessage)
  106. this.flow = this.$refs.myFlow.contentWindow;
  107. },
  108. activated() {
  109. window.addEventListener('message', this.handleMessage)
  110. this.flow = this.$refs.myFlow.contentWindow;
  111. },
  112. watch: {
  113. value: {
  114. handler() {
  115. this.updateContent();
  116. },
  117. deep: true
  118. },
  119. zoom(val) {
  120. this.flow.postMessage({
  121. act: 'zoom',
  122. params: {
  123. zoom: val / 100
  124. }
  125. }, '*')
  126. }
  127. },
  128. methods: {
  129. formatZoom(val) {
  130. return val + '%';
  131. },
  132. updateContent() {
  133. this.zoom = Math.max(1, (typeof this.value.scale === "number" ? this.value.scale : 1) * 100)
  134. this.flow.postMessage({
  135. act: 'setXml',
  136. params: Object.assign(this.value, typeof this.value.xml === "undefined" ? {
  137. xml: this.value.content
  138. } : {})
  139. }, '*')
  140. },
  141. handleMessage (event) {
  142. const data = event.data;
  143. switch (data.act) {
  144. case 'ready':
  145. this.loadIng = false;
  146. this.updateContent();
  147. break
  148. case 'change':
  149. this.$emit('input', data.params);
  150. break
  151. case 'save':
  152. this.$emit('saveData');
  153. break
  154. case 'imageContent':
  155. let pdf = new JSPDF({
  156. format: [data.params.width, data.params.height]
  157. });
  158. pdf.addImage(data.params.content, 'PNG', 0, 0, 0, 0);
  159. pdf.save(`${data.params.name}.pdf`);
  160. break
  161. }
  162. },
  163. exportPNG(name, scale = 10) {
  164. this.flow.postMessage({
  165. act: 'exportPNG',
  166. params: {
  167. name: name || this.$L('无标题'),
  168. scale: scale,
  169. type: 'png',
  170. }
  171. }, '*')
  172. },
  173. exportPDF(name, scale = 10) {
  174. this.flow.postMessage({
  175. act: 'exportPNG',
  176. params: {
  177. name: name || this.$L('无标题'),
  178. scale: scale,
  179. type: 'imageContent',
  180. }
  181. }, '*')
  182. }
  183. },
  184. }
  185. </script>