Meta2d.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!-- -->
  2. <template>
  3. <div class="content">
  4. <div id="meta2d"></div>
  5. </div>
  6. </template>
  7. <script>
  8. let meta2d = null;
  9. export default {
  10. name: 'meta2d',
  11. data() {
  12. return {};
  13. },
  14. mounted() {
  15. this.initMeta2d();
  16. },
  17. destroyed() {
  18. meta2d?.destroy();
  19. },
  20. methods: {
  21. initMeta2d() {
  22. meta2d = new window.Meta2d("meta2d",{
  23. background: '#1e2430',
  24. x: 10,
  25. y: 10,
  26. width: 1920,
  27. color: '#bdc7db',
  28. height: 1080,
  29. });
  30. window.registerCommonDiagram();
  31. this._fetch("/json/data.json", function (text) {
  32. var data = JSON.parse(text);
  33. data.locked = 1;
  34. meta2d.open(data);
  35. let fit =
  36. meta2d.store.data.scaleMode === '3'
  37. ? 'height'
  38. : meta2d.store.data.scaleMode === '2'
  39. ? 'width'
  40. : true;
  41. meta2d.fitSizeView(fit, 10);
  42. });
  43. },
  44. _fetch(url, cb) {
  45. var xhr = new XMLHttpRequest();
  46. xhr.open("GET", url, true);
  47. xhr.send();
  48. xhr.onreadystatechange = function () {
  49. if (xhr.readyState == 4 && xhr.status == 200) {
  50. cb && cb(xhr.responseText);
  51. }
  52. };
  53. },
  54. },
  55. };
  56. </script>
  57. <style>
  58. html,
  59. body {
  60. height: 100vh;
  61. margin: 0;
  62. padding: 0;
  63. }
  64. .content {
  65. position: relative;
  66. background-color: #f4f4f4;
  67. height: 100vh;
  68. }
  69. #meta2d {
  70. position: absolute !important;
  71. width: 100%;
  72. height: 100%;
  73. touch-action: none;
  74. overflow: hidden;
  75. }
  76. </style>