loadCAD.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. window.grendCAD = (function grendCAD() {
  2. let initFloor
  3. let initScript
  4. let initDOM
  5. let point, dire
  6. window.cad = {
  7. setSign: function (p, d) {
  8. point = p
  9. dire = d
  10. }
  11. }
  12. function loadScript(cb) {
  13. if (initScript) return cb()
  14. let $script = document.createElement('script')
  15. $script.src = 'static/js/bundle.js'
  16. $script.onload = function () {
  17. initScript = true
  18. cb()
  19. }
  20. document.documentElement.appendChild($script)
  21. }
  22. function loadDOM($parent) {
  23. if (initDOM) return initDOM;
  24. let $layer = document.createElement('div')
  25. let $cad = document.createElement('div')
  26. $layer.className = 'cad'
  27. $cad.id = 'cad'
  28. $layer.appendChild($cad)
  29. let style = document.createElement('style')
  30. style.innerHTML = `
  31. .cad {
  32. position: absolute;
  33. right: 20px;
  34. top: 20px;
  35. width: 180px;
  36. height: 180px;
  37. background: rgb(146 3 3 / 37%);
  38. backdrop-filter:blur(10px);
  39. border-radius: 5px;
  40. pointer-events: none;
  41. }
  42. .cad > div {
  43. width: 100%;
  44. height: 100%;
  45. }
  46. @media only screen and (max-width: 1000px) {
  47. .cad {
  48. position: absolute;
  49. left:auto;
  50. transform: translate(0, 0);
  51. right: 10px;
  52. top: 10px;
  53. width: 120px;
  54. height: 120px;
  55. background: rgba(81, 32, 32, 0.4);
  56. border-radius: 5px;
  57. border: 2px solid #D6B970;
  58. }
  59. }
  60. `
  61. document.documentElement.appendChild(style)
  62. $('body').append($layer)
  63. $parent.appendChild(style)
  64. $parent.appendChild($layer)
  65. return $layer
  66. }
  67. function setStyle(signColor, borderColor, borderWidth) {
  68. cad.setDefaultPointStyle({
  69. fillColor: "rgba(0,0,0,0)",
  70. storkeColor: "rgba(0,0,0,0)"
  71. });
  72. console.log(borderWidth)
  73. cad.setDefaultLineStyle({
  74. width: borderWidth,
  75. color: borderColor
  76. });
  77. cad.setDefaultSignStyle({
  78. color: signColor
  79. })
  80. }
  81. return function (floor, $parent, signColor, borderColor, borderWidth) {
  82. if (initFloor) {
  83. console.log('cache')
  84. return setStyle(signColor, borderColor, borderWidth)
  85. }
  86. console.log('load')
  87. initFloor = floor
  88. loadScript(function () {
  89. let $layer = loadDOM($parent)
  90. $layer.style.visibility = 'hidden'
  91. window.cad = structureCAD({
  92. data: {
  93. block: [],
  94. column: [],
  95. door: [],
  96. hole: [],
  97. segment: [],
  98. "vertex-xy": [],
  99. "vertex-z": [],
  100. },
  101. layer: $layer.querySelector('#cad'),
  102. edit: false
  103. });
  104. setStyle(signColor, borderColor, borderWidth)
  105. cad.hideDire()
  106. cad.hideGauge()
  107. console.log('loadData')
  108. cad.loadData(initFloor);
  109. if (point && dire) {
  110. window.cad.setSign(point, dire)
  111. }
  112. $layer.style.visibility = 'visible'
  113. })
  114. }
  115. })();
  116. $.ajax({
  117. url: g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(),
  118. method: 'GET',
  119. success(data) {
  120. if (!data.showCad) return
  121. $.ajax({
  122. url: '//super.4dage.com/data/' + window.number + '/floor.json',
  123. method: 'GET',
  124. success(res) {
  125. grendCAD(res, document.querySelector('body'), data.cadSignColor, data.cadBorderColor, data.cadBorderWidth)
  126. }
  127. })
  128. }
  129. })