Meta2d.vue 1.3 KB

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