loadCAD.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. window.grendCAD = (function grendCAD() {
  2. let initFloor
  3. // let initDOM
  4. let point, dire
  5. window.cad = {
  6. setSign: function(p, d) {
  7. point = p
  8. dire = d
  9. }
  10. }
  11. function loadDOM($parent,id) {
  12. // if (initDOM) return initDOM;
  13. let $layer = document.createElement('div')
  14. let $cad = document.createElement('div')
  15. $layer.className = id
  16. $cad.id = id
  17. $cad.setAttribute('class',window.number)
  18. $layer.appendChild($cad)
  19. let style = document.createElement('style')
  20. style.innerHTML = `
  21. .${id} {
  22. position: fixed;
  23. right: -310px;
  24. top: 80px;
  25. width: 260px;
  26. height: 200px;
  27. z-index: 99;
  28. transition: all 0.3s ease;
  29. }
  30. .${id} > div {
  31. width: 100%;
  32. height: 100%;
  33. }
  34. @media only screen and (max-width: 600px) {
  35. .${id} {
  36. position: absolute;
  37. left: -310px;
  38. top: 65px;
  39. width: 100px;
  40. height: 100px;
  41. background: rgba(0, 0, 0, .3);
  42. border-radius: 5px;
  43. }
  44. }
  45. `
  46. $parent.appendChild(style)
  47. $parent.appendChild($layer)
  48. return $layer
  49. }
  50. function setStyle(signColor, borderColor, borderWidth) {
  51. cad.setDefaultPointStyle({
  52. fillColor: "rgba(0,0,0,0)",
  53. storkeColor: "rgba(0,0,0,0)"
  54. });
  55. console.log(borderWidth)
  56. cad.setDefaultLineStyle({
  57. width: borderWidth,
  58. color: borderColor
  59. });
  60. console.log('执行===============');
  61. cad.setDefaultSignStyle({
  62. color: signColor,
  63. r: 6,
  64. })
  65. }
  66. return function(floor, $parent, signColor, borderColor, borderWidth, id) {
  67. // if (initFloor) {
  68. // console.log('cache')
  69. // return setStyle(signColor, borderColor, borderWidth)
  70. // }
  71. console.log('load')
  72. initFloor = floor
  73. let $layer = loadDOM($parent,id)
  74. $layer.style.visibility = 'hidden'
  75. window.cad = structureCAD({
  76. data: {
  77. block: [],
  78. column: [],
  79. door: [],
  80. hole: [],
  81. segment: [],
  82. "vertex-xy": [],
  83. "vertex-z": [],
  84. },
  85. layer: $layer.querySelector('#'+id),
  86. edit: false
  87. });
  88. setStyle(signColor, borderColor, borderWidth)
  89. cad.hideDire()
  90. cad.hideGauge()
  91. console.log('loadData')
  92. cad.loadData(initFloor);
  93. if (point && dire) {
  94. window.cad.setSign(point, dire)
  95. }
  96. $layer.style.visibility = 'visible'
  97. }
  98. })();
  99. $.ajax({
  100. url: `static/data/${window.number}.json`,
  101. method: 'GET',
  102. success(res) {
  103. grendCAD(res, document.documentElement, '#D32424', '#ffffff', '1px','cad')
  104. }
  105. })