Meta2d.jsx 849 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from "react";
  2. import "./Meta2d.css";
  3. let meta2d = null;
  4. export default class Meta2d extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. }
  8. componentDidMount() {
  9. meta2d = new window.Meta2d("meta2d");
  10. window.registerCommonDiagram();
  11. this._fetch("/json/data.json", function (text) {
  12. var data = JSON.parse(text);
  13. data.locked = 1;
  14. meta2d.open(data);
  15. });
  16. }
  17. componentWillUnmount() {
  18. meta2d?.destroy();
  19. }
  20. _fetch(url, cb) {
  21. var xhr = new XMLHttpRequest();
  22. xhr.open("GET", url, true);
  23. xhr.send();
  24. xhr.onreadystatechange = function () {
  25. if (xhr.readyState == 4 && xhr.status == 200) {
  26. cb && cb(xhr.responseText);
  27. }
  28. };
  29. }
  30. render() {
  31. return (
  32. <div className="content">
  33. <div id="meta2d"></div>
  34. </div>
  35. );
  36. }
  37. }