index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. bakData: '',
  103. }
  104. },
  105. mounted() {
  106. window.addEventListener('message', this.handleMessage)
  107. this.flow = this.$refs.myFlow.contentWindow;
  108. },
  109. beforeDestroy() {
  110. window.removeEventListener('message', this.handleMessage)
  111. },
  112. watch: {
  113. value: {
  114. handler(val) {
  115. if (this.bakData == $A.jsonStringify(val)) {
  116. return;
  117. }
  118. this.bakData = $A.jsonStringify(val);
  119. this.updateContent();
  120. },
  121. deep: true
  122. },
  123. zoom(val) {
  124. this.flow.postMessage({
  125. act: 'zoom',
  126. params: {
  127. zoom: val / 100
  128. }
  129. }, '*')
  130. }
  131. },
  132. methods: {
  133. formatZoom(val) {
  134. return val + '%';
  135. },
  136. updateContent() {
  137. this.zoom = Math.max(1, (typeof this.value.scale === "number" ? this.value.scale : 1) * 100)
  138. this.flow.postMessage({
  139. act: 'setXml',
  140. params: Object.assign(this.value, typeof this.value.xml === "undefined" ? {
  141. xml: this.value.content
  142. } : {})
  143. }, '*')
  144. },
  145. handleMessage (event) {
  146. const data = event.data;
  147. switch (data.act) {
  148. case 'ready':
  149. this.loadIng = false;
  150. this.updateContent();
  151. break
  152. case 'change':
  153. this.bakData = $A.jsonStringify(data.params);
  154. this.$emit('input', data.params);
  155. break
  156. case 'save':
  157. this.$emit('saveData');
  158. break
  159. case 'imageContent':
  160. let pdf = new JSPDF({
  161. format: [data.params.width, data.params.height]
  162. });
  163. pdf.addImage(data.params.content, 'PNG', 0, 0, 0, 0);
  164. pdf.save(`${data.params.name}.pdf`);
  165. break
  166. }
  167. },
  168. exportPNG(name, scale = 10) {
  169. this.flow.postMessage({
  170. act: 'exportPNG',
  171. params: {
  172. name: name || this.$L('无标题'),
  173. scale: scale,
  174. type: 'png',
  175. }
  176. }, '*')
  177. },
  178. exportPDF(name, scale = 10) {
  179. this.flow.postMessage({
  180. act: 'exportPNG',
  181. params: {
  182. name: name || this.$L('无标题'),
  183. scale: scale,
  184. type: 'imageContent',
  185. }
  186. }, '*')
  187. }
  188. },
  189. }
  190. </script>