loadCAD.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 = '//www.4dmodel.com/CAD/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 $outerDiv = document.createElement('div')
  25. let $layer = document.createElement('div')
  26. let $cad = document.createElement('div')
  27. let $jiantou = document.createElement('div')
  28. let $jtimg = document.createElement('img')
  29. $jtimg.src="static/images/phone_step_05.png"
  30. $jiantou.id = 'cadimg'
  31. $layer.className = 'cad'
  32. $jiantou.className = 'jiantou'
  33. $outerDiv.className = 'cadouter'
  34. $cad.id = 'cad'
  35. $layer.appendChild($cad)
  36. $jiantou.appendChild($jtimg)
  37. $outerDiv.appendChild($layer)
  38. let wh= 200
  39. let style = document.createElement('style')
  40. style.innerHTML = `
  41. .jiantou{
  42. display: none!important;
  43. position: fixed;
  44. width: 40px;
  45. height: 50px;
  46. right: 40px;
  47. background: rgba(0, 0, 0, .6);
  48. top: 46px;
  49. display: flex;
  50. justify-content: center;
  51. align-items: center;
  52. border-radius: 0 5px 5px 0;
  53. cursor: pointer;
  54. }
  55. .jiantou>img{
  56. width:30%;
  57. }
  58. .jiantouactive{
  59. right: 0;
  60. transform: rotate(180deg);
  61. }
  62. .cadouter {
  63. display: none!important;
  64. position: absolute;
  65. right: 80px;
  66. top: 46px;
  67. width: ${wh}px;
  68. height: ${wh}px;
  69. background: rgba(0, 0, 0, .6);
  70. border-radius: 5px 0 5px 5px;
  71. overflow: hidden;
  72. }
  73. .cadouteractive{
  74. right: 200%;
  75. }
  76. .cad {
  77. display: none!important;
  78. position: absolute;
  79. left: 50%;
  80. top: 50%;
  81. right:unset;
  82. transform: translate(-50%, -50%);
  83. width: ${wh*1.4}px;
  84. height: ${wh*1.4}px;
  85. }
  86. .cad > div {
  87. width: 100%;
  88. height: 100%;
  89. }
  90. @media only screen and (max-width: 600px) {
  91. .cadouter,.jiantou{
  92. display: none!important;
  93. }
  94. .cad {
  95. position: absolute;
  96. left: 16px;
  97. top: 65px;
  98. width: 100px;
  99. height: 100px;
  100. background: rgba(0, 0, 0, .3);
  101. border-radius: 5px;
  102. }
  103. }
  104. `
  105. document.documentElement.appendChild(style)
  106. document.documentElement.appendChild($outerDiv)
  107. document.documentElement.appendChild($jiantou)
  108. $parent.appendChild(style)
  109. $parent.appendChild($outerDiv)
  110. $parent.appendChild($jiantou)
  111. $($jiantou).click(()=>{
  112. $($jiantou).toggleClass('jiantouactive')
  113. $($outerDiv).toggleClass('cadouteractive')
  114. })
  115. return $outerDiv
  116. }
  117. function setStyle(signColor, borderColor, borderWidth) {
  118. cad.setDefaultPointStyle({
  119. fillColor: "rgba(0,0,0,0)",
  120. storkeColor: "rgba(0,0,0,0)"
  121. });
  122. console.log(borderWidth)
  123. cad.setDefaultLineStyle({
  124. width: borderWidth,
  125. color: borderColor
  126. });
  127. cad.setDefaultSignStyle({
  128. color: signColor
  129. })
  130. }
  131. return function(floor, $parent, signColor, borderColor, borderWidth) {
  132. if (initFloor) {
  133. console.log('cache')
  134. return setStyle(signColor, borderColor, borderWidth)
  135. }
  136. console.log('load')
  137. initFloor = floor
  138. loadScript(function() {
  139. let $layer = loadDOM($parent)
  140. $layer.style.visibility = 'hidden'
  141. window.cad = structureCAD({
  142. data: {
  143. block: [],
  144. column: [],
  145. door: [],
  146. hole: [],
  147. segment: [],
  148. "vertex-xy": [],
  149. "vertex-z": [],
  150. },
  151. layer: $layer.querySelector('#cad'),
  152. edit: false
  153. });
  154. setStyle(signColor, borderColor, borderWidth)
  155. cad.hideDire()
  156. cad.hideGauge()
  157. console.log('loadData')
  158. cad.loadData(initFloor);
  159. if (point && dire) {
  160. window.cad.setSign(point, dire)
  161. }
  162. $layer.style.visibility = 'visible'
  163. })
  164. }
  165. })();
  166. console.log(1111111111111111111,window.number);
  167. if(window.number==='1151'){
  168. $.ajax({
  169. url: g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(),
  170. method: 'GET',
  171. success(data) {
  172. if (!data.showCad) return
  173. $.ajax({
  174. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  175. method: 'GET',
  176. success(res) {
  177. grendCAD(res, document.documentElement, data.cadSignColor, data.cadBorderColor, data.cadBorderWidth)
  178. }
  179. })
  180. }
  181. })
  182. }