evacuationLayout.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. import { Message } from 'element-ui'
  2. /*
  3. * ********************
  4. * 通用疏散布局方法封装
  5. * ********************
  6. */
  7. /*
  8. ******************* mapList-数据格式 *******************
  9. { name:"实验室房间",
  10. y: 101,
  11. x: 1,
  12. w: 100,
  13. h: 100,
  14. type: '1',//1房间2楼道3疏散通道
  15. direction: '1',//1上2右3下4左
  16. doorList:[{
  17. h:40,
  18. toward:"right",
  19. type:"door",
  20. w:10,
  21. x:90,
  22. y:22,
  23. }],
  24. },
  25. {
  26. name:"疏散通道",
  27. y: 101,
  28. x: 801,
  29. w: 100,
  30. h: 100,
  31. type: '3',//1房间2楼道3疏散通道
  32. direction: '1',//1上2右3下4左
  33. doorList:[
  34. {
  35. h:40,
  36. toward:"left",
  37. type:"door",
  38. w:10,
  39. x:0,
  40. y:34,
  41. }
  42. ],
  43. },
  44. {
  45. name:"l01",
  46. y: 101,
  47. x: 101,
  48. w: 100,
  49. h: 500,
  50. type: '2',//1房间2楼道3疏散通道
  51. direction: '1',//1上2右3下4左
  52. lightList:[
  53. { type:'lab',w:4,h:4,x:100,y:100},//实验室门点
  54. { type:'escape',w:4,h:4,x:100,y:100,},//疏散通道门点
  55. { type:'light',state:'',w:100,h:100,x:100,y:100,},//灯点
  56. { type:'traffic',w:4,h:4,x:lx,y:ly,},//交通点
  57. { type:'connect',w:4,h:4,x:0,y:100}//连接点
  58. ],
  59. },
  60. */
  61. /************************************全局变量/刷新方法************************************/
  62. //边界位置
  63. let borderLeft = null
  64. let borderTop = null
  65. //画布/楼层尺寸
  66. let layerWidth = null
  67. let layerHeight = null
  68. //房间尺寸限制
  69. let minHeight = null
  70. let maxHeight = null
  71. let minWidth = null
  72. let maxWidth = null
  73. //门尺寸数据
  74. let doorHeight = null
  75. let doorWidth = null
  76. //灯尺寸数据
  77. let minLightNum = null
  78. let maxLightNum = null
  79. //交通点检测时触手范围
  80. let tentaclesLength = null
  81. //缩放形状判断
  82. let zoomType = null
  83. export function setJsData(data) {
  84. borderLeft = data.borderLeft
  85. borderTop = data.borderTop
  86. layerWidth = data.layerWidth
  87. layerHeight = data.layerHeight
  88. minHeight = data.minHeight
  89. maxHeight = data.maxHeight
  90. minWidth = data.minWidth
  91. maxWidth = data.maxWidth
  92. doorWidth = data.doorWidth
  93. doorHeight = data.doorHeight
  94. minLightNum = data.minLightNum
  95. maxLightNum = data.maxLightNum
  96. tentaclesLength = data.tentaclesLength
  97. console.log('传参', data)
  98. }
  99. /************************************生成点/点连接 相关************************************/
  100. /*
  101. * 计算目标交通点位置
  102. * 传入:newMapList-布局数据
  103. * 返回:处理好的数据
  104. * 示例:
  105. * let obj = addDoorPoint(newMapList)
  106. */
  107. export function addDoorPoint(newMapList) {
  108. let labNum = 0;
  109. let escapeNum = 0;
  110. let corridorNum = 0;
  111. let lightNum = 0;
  112. let evacuationList = JSON.parse(JSON.stringify(newMapList));
  113. for (let i = 0; i < newMapList.length; i++) {
  114. if (newMapList[i].type == 1 || newMapList[i].type == 3) {
  115. if(newMapList[i].type == 1){
  116. newMapList[i].key = 'lab'+labNum;
  117. evacuationList[i].key = 'lab'+labNum;
  118. labNum++
  119. }else if(newMapList[i].type == 3){
  120. newMapList[i].key = 'escape'+escapeNum;
  121. evacuationList[i].key = 'escape'+escapeNum;
  122. escapeNum++
  123. }
  124. //生成门点
  125. let x = 0
  126. let y = 0
  127. if (newMapList[i].doorList[0].toward == 'top') {
  128. x = newMapList[i].x + newMapList[i].doorList[0].x + (doorWidth / 2)
  129. y = newMapList[i].y - tentaclesLength
  130. } else if (newMapList[i].doorList[0].toward == 'bottom') {
  131. x = newMapList[i].x + newMapList[i].doorList[0].x + (doorWidth / 2)
  132. y = newMapList[i].y + newMapList[i].h + tentaclesLength
  133. } else if (newMapList[i].doorList[0].toward == 'left') {
  134. x = newMapList[i].x - tentaclesLength
  135. y = newMapList[i].y + newMapList[i].doorList[0].y + (doorHeight / 2)
  136. } else if (newMapList[i].doorList[0].toward == 'right') {
  137. x = newMapList[i].x + newMapList[i].w + tentaclesLength
  138. y = newMapList[i].y + newMapList[i].doorList[0].y + (doorHeight / 2)
  139. }
  140. for (let j = 0; j < newMapList.length; j++) {
  141. if (newMapList[j].type == 2) {
  142. if (x > newMapList[j].x && x < (newMapList[j].x + newMapList[j].w) &&
  143. y > newMapList[j].y && y < (newMapList[j].y + newMapList[j].h)) {
  144. let lx = null
  145. let ly = null
  146. if (newMapList[i].doorList[0].toward == 'top') {
  147. let obj = calculateDoorPoint(newMapList[j], newMapList[i], 'top')
  148. lx = obj.x
  149. ly = obj.y
  150. } else if (newMapList[i].doorList[0].toward == 'bottom') {
  151. let obj = calculateDoorPoint(newMapList[j], newMapList[i], 'bottom')
  152. lx = obj.x
  153. ly = obj.y
  154. } else if (newMapList[i].doorList[0].toward == 'left') {
  155. let obj = calculateDoorPoint(newMapList[j], newMapList[i], 'left')
  156. lx = obj.x
  157. ly = obj.y
  158. } else if (newMapList[i].doorList[0].toward == 'right') {
  159. let obj = calculateDoorPoint(newMapList[j], newMapList[i], 'right')
  160. lx = obj.x
  161. ly = obj.y
  162. }
  163. newMapList[j].lightList.push({
  164. // key:newMapList[i].type == 1 ? 'lab'+labNum : 'escape'+escapeNum,
  165. key:newMapList[i].key,
  166. type: newMapList[i].type == 1 ? 'lab' : 'escape',
  167. w: 4,
  168. h: 4,
  169. x: lx,
  170. y: ly
  171. })
  172. }
  173. }
  174. }
  175. } else if (newMapList[i].type == 2) {
  176. evacuationList[i].key = 'corridor'+corridorNum;
  177. corridorNum++
  178. //生成交通点
  179. let x1 = null
  180. let y1 = null
  181. let x2 = null
  182. let y2 = null
  183. if (newMapList[i].w > newMapList[i].h) {
  184. x1 = newMapList[i].x - tentaclesLength
  185. y1 = newMapList[i].y + newMapList[i].h / 2
  186. x2 = newMapList[i].x + newMapList[i].w + tentaclesLength
  187. y2 = newMapList[i].y + newMapList[i].h / 2
  188. } else {
  189. x1 = newMapList[i].x + newMapList[i].w / 2
  190. y1 = newMapList[i].y - tentaclesLength
  191. x2 = newMapList[i].x + newMapList[i].w / 2
  192. y2 = newMapList[i].y + newMapList[i].h + tentaclesLength
  193. }
  194. for (let j = 0; j < newMapList.length; j++) {
  195. if (newMapList[j].type == 2) {
  196. let lx = null
  197. let ly = null
  198. if (x1 > newMapList[j].x && x1 < (newMapList[j].x + newMapList[j].w) &&
  199. y1 > newMapList[j].y && y1 < (newMapList[j].y + newMapList[j].h)) {
  200. let obj = calculateTrafficPoint(x1, y1, newMapList[j])
  201. lx = obj.x
  202. ly = obj.y
  203. let num = 0
  204. for (let o = 0; o < newMapList[j].lightList.length; o++) {
  205. if (newMapList[j].lightList[o].x == lx && newMapList[j].lightList[o].y == ly) {
  206. num++
  207. }
  208. }
  209. if (num == 0) {
  210. newMapList[j].lightList.push({
  211. type: 'traffic',
  212. w: 4,
  213. h: 4,
  214. x: lx,
  215. y: ly
  216. })
  217. }
  218. if (newMapList[i].w > newMapList[i].h) {
  219. newMapList[i].lightList.push({
  220. type: 'connect',
  221. w: 4,
  222. h: 4,
  223. x: 0,
  224. y: newMapList[i].h / 2
  225. })
  226. } else {
  227. newMapList[i].lightList.push({
  228. type: 'connect',
  229. w: 4,
  230. h: 4,
  231. x: newMapList[i].w / 2,
  232. y: 0
  233. })
  234. }
  235. } else if (x2 > newMapList[j].x && x2 < (newMapList[j].x + newMapList[j].w) &&
  236. y2 > newMapList[j].y && y2 < (newMapList[j].y + newMapList[j].h)) {
  237. let obj = calculateTrafficPoint(x2, y2, newMapList[j])
  238. lx = obj.x
  239. ly = obj.y
  240. let num = 0
  241. for (let o = 0; o < newMapList[j].lightList.length; o++) {
  242. if (newMapList[j].lightList[o].x == lx && newMapList[j].lightList[o].y == ly) {
  243. num++
  244. }
  245. }
  246. if (num == 0) {
  247. newMapList[j].lightList.push({
  248. type: 'traffic',
  249. w: 4,
  250. h: 4,
  251. x: lx,
  252. y: ly
  253. })
  254. }
  255. if (newMapList[i].w > newMapList[i].h) {
  256. newMapList[i].lightList.push({
  257. type: 'connect',
  258. w: 4,
  259. h: 4,
  260. x: newMapList[i].w - 4,
  261. y: newMapList[i].h / 2
  262. })
  263. } else {
  264. newMapList[i].lightList.push({
  265. type: 'connect',
  266. w: 4,
  267. h: 4,
  268. x: newMapList[i].w / 2,
  269. y: newMapList[i].h - 4
  270. })
  271. }
  272. }
  273. }
  274. }
  275. for (let s = 0; s < newMapList[i].lightList.length; s++){
  276. if( newMapList[i].lightList[s].type == "light"){
  277. newMapList[i].lightList[s].key = 'light'+lightNum;
  278. evacuationList[i].lightList[s].key = 'light'+lightNum;
  279. lightNum++
  280. }
  281. }
  282. }
  283. }
  284. // return console.log(newMapList);
  285. return { mapList: newMapList, newList: connectionPoint(newMapList),evacuationList:evacuationList }
  286. }
  287. /*
  288. * 计算目标交通点位置
  289. * 传入:x-落点X,y-落点Y,obj-目标数据,
  290. * 返回:一个对象,里面包含x与y
  291. * 示例: (本方法没有再外部引用,只在本JS内由 addDoorPoint 方法引用)
  292. * let obj = calculateTrafficPoint(x1,y1,newMapList[j]);
  293. */
  294. export function calculateTrafficPoint(x, y, obj) {
  295. let newObj = { x: null, y: null }
  296. if (obj.w > obj.h) {
  297. newObj.x = x - obj.x
  298. newObj.y = obj.h / 2
  299. } else {
  300. newObj.x = obj.w / 2
  301. newObj.y = y - obj.y
  302. }
  303. return newObj
  304. }
  305. /*
  306. * 计算门点位置
  307. * 传入:bigObj-父级对象,minObj-子级对象,type-朝向,
  308. * 返回:一个对象,里面包含x与y
  309. * 示例: (本方法没有再外部引用,只在本JS内由 addDoorPoint 方法引用)
  310. * let obj = calculateDoorPoint(newMapList[j],newMapList[i],'right')
  311. */
  312. export function calculateDoorPoint(bigObj, minObj, type) {
  313. //bigObj 范围大的一方 minObj范围小的一方
  314. let obj = { x: null, y: null }
  315. if (bigObj.w > bigObj.h) {
  316. if (type == 'top' || type == 'bottom') {
  317. obj.x = minObj.x - bigObj.x + minObj.doorList[0].x + doorWidth / 2
  318. obj.y = bigObj.h / 2
  319. } else if (type == 'left') {
  320. obj.x = bigObj.w - 6
  321. obj.y = bigObj.h / 2
  322. } else if (type == 'right') {
  323. obj.x = 2
  324. obj.y = bigObj.h / 2
  325. }
  326. } else {
  327. if (type == 'top') {
  328. obj.x = bigObj.w / 2
  329. obj.y = bigObj.h - 6
  330. } else if (type == 'bottom') {
  331. obj.x = bigObj.w / 2
  332. obj.y = 2
  333. } else if (type == 'left' || type == 'right') {
  334. obj.x = bigObj.w / 2
  335. obj.y = minObj.y - bigObj.y + minObj.doorList[0].y + doorHeight / 2
  336. }
  337. }
  338. return obj
  339. }
  340. /*
  341. * 连接点路径
  342. * 传入:newMapList-布局数据
  343. * 返回:返回连接好路径的数组
  344. * 示例: (本方法没有再外部引用,只在本JS内由 addDoorPoint 方法引用)
  345. * connectionPoint(newMapList);
  346. */
  347. export function connectionPoint(newMapList) {
  348. let list = []
  349. let doorNum = 0
  350. let escapeNum = 0
  351. let lightNum = 0
  352. let trafficNum = 0
  353. let trafficNumOne = 0
  354. // 绑定名称
  355. for (let i = 0; i < newMapList.length; i++) {
  356. if (newMapList[i].type == 2) {
  357. for (let j = 0; j < newMapList[i].lightList.length; j++) {
  358. if (newMapList[i].lightList[j].type == 'lab') {
  359. // newMapList[i].lightList[j].name = 'lab' + doorNum
  360. newMapList[i].lightList[j].name = newMapList[i].lightList[j].key
  361. newMapList[i].lightList[j].type = 'lab'
  362. doorNum++
  363. }
  364. if (newMapList[i].lightList[j].type == 'escape') {
  365. // newMapList[i].lightList[j].name = 'escape' + escapeNum
  366. newMapList[i].lightList[j].name = newMapList[i].lightList[j].key
  367. newMapList[i].lightList[j].type = 'escape'
  368. escapeNum++
  369. } else if (newMapList[i].lightList[j].type == 'light') {
  370. // newMapList[i].lightList[j].name = 'light' + lightNum
  371. newMapList[i].lightList[j].name = newMapList[i].lightList[j].key
  372. newMapList[i].lightList[j].type = 'light'
  373. lightNum++
  374. } else if (newMapList[i].lightList[j].type == 'traffic') {
  375. newMapList[i].lightList[j].name = 'traffic' + trafficNum
  376. newMapList[i].lightList[j].type = 'traffic'
  377. trafficNum++
  378. } else if (newMapList[i].lightList[j].type == 'connect') {
  379. newMapList[i].lightList[j].name = 'connect' + trafficNumOne
  380. newMapList[i].lightList[j].type = 'connect'
  381. trafficNumOne++
  382. }
  383. }
  384. }
  385. }
  386. for (let i = 0; i < newMapList.length; i++) {
  387. if (newMapList[i].type == 2) {
  388. for (let j = 0; j < newMapList[i].lightList.length; j++) {
  389. list.push(calculateAssociatedLength(newMapList, newMapList[i], newMapList[i].lightList[j]))
  390. }
  391. }
  392. }
  393. return list
  394. }
  395. /*
  396. * 计算关联/长度
  397. * 传入:newMapList-布局数据,bigObj-父级对象,minObj-子级对象
  398. * 返回:处理好关系的对象
  399. * 示例: (本方法没有再外部引用,只在本JS内由 connectionPoint 方法引用)
  400. * calculateAssociatedLength(newMapList,newMapList[i],newMapList[i].lightList[j])
  401. */
  402. export function calculateAssociatedLength(newMapList, bigObj, minObj) {
  403. let obj = {
  404. pointName: minObj.name,
  405. pointDistance: -1,
  406. pointAttribute: minObj.type == 'escape' ? 1 : (minObj.type == 'light' ? 2 : minObj.type == 'lab' ? 4 : 3),
  407. pointVOList: []
  408. }
  409. if(minObj.type == 'escape' || minObj.type == 'lab'){
  410. obj.key = minObj.key;
  411. }else if(minObj.type == 'light'){
  412. obj.key = minObj.key;
  413. }
  414. //按顺序写入假数据
  415. for (let i = 0; i < newMapList.length; i++) {
  416. if (newMapList[i].type == 2) {
  417. for (let j = 0; j < newMapList[i].lightList.length; j++) {
  418. obj.pointVOList.push({
  419. pointName: newMapList[i].lightList[j].name,
  420. pointDistance: newMapList[i].lightList[j].name === minObj.name ? 0 : 65535,
  421. pointAttribute: newMapList[i].lightList[j].type == 'escape' ? 1 : (newMapList[i].lightList[j].type == 'light' ? 2 : newMapList[i].lightList[j].type == 'lab' ? 4 : 3)
  422. })
  423. }
  424. }
  425. }
  426. const x = minObj.x
  427. const y = minObj.y
  428. //行径方向判定
  429. if (bigObj.w > bigObj.h) {
  430. //横向查找最近点
  431. let min = null
  432. let max = null
  433. for (let i = 0; i < bigObj.lightList.length; i++) {
  434. if (bigObj.lightList[i].x > x) {
  435. //右最近
  436. if (max) {
  437. if (max.x > bigObj.lightList[i].x) {
  438. if (bigObj.lightList[i].name !== minObj.name) {
  439. if (bigObj.lightList[i].type == 'light') {
  440. if (bigObj.lightList[i].state != '3') {
  441. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  442. }
  443. } else {
  444. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  445. }
  446. }
  447. }
  448. } else {
  449. if (bigObj.lightList[i].name !== minObj.name) {
  450. if (bigObj.lightList[i].type == 'light') {
  451. if (bigObj.lightList[i].state != '3') {
  452. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  453. }
  454. } else {
  455. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  456. }
  457. }
  458. }
  459. } else {
  460. //左最近
  461. if (min) {
  462. if (min.x < bigObj.lightList[i].x) {
  463. if (bigObj.lightList[i].name !== minObj.name) {
  464. if (bigObj.lightList[i].type == 'light') {
  465. if (bigObj.lightList[i].state != '4') {
  466. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  467. }
  468. } else {
  469. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  470. }
  471. }
  472. }
  473. } else {
  474. if (bigObj.lightList[i].name !== minObj.name) {
  475. if (bigObj.lightList[i].type == 'light') {
  476. if (bigObj.lightList[i].state != '4') {
  477. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  478. }
  479. } else {
  480. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  481. }
  482. }
  483. }
  484. }
  485. }
  486. if (min != null) {
  487. obj.pointVOList[lookingTargetReturnSubscript(min.name, obj.pointVOList)].pointDistance = minObj.x - min.x
  488. }
  489. if (max != null) {
  490. obj.pointVOList[lookingTargetReturnSubscript(max.name, obj.pointVOList)].pointDistance = max.x - minObj.x
  491. }
  492. //如果是交通端点-进行跨域连接
  493. if (minObj.type == 'connect') {
  494. for (let j = 0; j < newMapList.length; j++) {
  495. if (newMapList[j].type == 2) {
  496. for (let k = 0; k < newMapList[j].lightList.length; k++) {
  497. if (newMapList[j].lightList[k].type == 'traffic') {
  498. let lx = newMapList[j].x + newMapList[j].lightList[k].x
  499. let ly = newMapList[j].y + newMapList[j].lightList[k].y
  500. if (minObj.x > (bigObj.w / 2)) {
  501. //向右延展
  502. if (lx > (bigObj.x + bigObj.w) && lx < (bigObj.x + bigObj.w + minWidth) && ly > (bigObj.y + minObj.y - 1) && ly < (bigObj.y + minObj.y + 1)) {
  503. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = lx - bigObj.x - minObj.x
  504. }
  505. } else {
  506. //向左延展
  507. if (lx > (bigObj.x - minWidth) && lx < bigObj.x && ly > (bigObj.y + minObj.y - 1) && ly < (bigObj.y + minObj.y + 1)) {
  508. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = (bigObj.x + minObj.x) - lx
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. } else if (minObj.type == 'traffic') {
  516. for (let j = 0; j < newMapList.length; j++) {
  517. if (newMapList[j].type == 2) {
  518. for (let k = 0; k < newMapList[j].lightList.length; k++) {
  519. if (newMapList[j].lightList[k].type == 'connect') {
  520. let lx = newMapList[j].x + newMapList[j].lightList[k].x
  521. let ly = newMapList[j].y + newMapList[j].lightList[k].y
  522. //向下延展
  523. if (lx >= (bigObj.x + minObj.x - 1) && lx <= (bigObj.x + minObj.x + 1) && ly >= (bigObj.y + bigObj.h) && ly <= (bigObj.y + bigObj.h + tentaclesLength)) {
  524. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = ly - bigObj.y - minObj.y
  525. }
  526. //向上延展
  527. if (lx >= (bigObj.x + minObj.x - 1) && lx <= (bigObj.x + minObj.x + 1) && ly >= bigObj.y - tentaclesLength && ly <= bigObj.y) {
  528. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = bigObj.y - ly
  529. }
  530. }
  531. }
  532. }
  533. }
  534. }
  535. } else {
  536. //竖向查找最近点
  537. let min = null
  538. let max = null
  539. for (let i = 0; i < bigObj.lightList.length; i++) {
  540. if (bigObj.lightList[i].y > y) {
  541. //下最近
  542. if (max) {
  543. if (max.y > bigObj.lightList[i].y) {
  544. if (bigObj.lightList[i].name !== minObj.name) {
  545. if (bigObj.lightList[i].type == 'light') {
  546. if (bigObj.lightList[i].state != '1') {
  547. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  548. }
  549. } else {
  550. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  551. }
  552. }
  553. }
  554. } else {
  555. if (bigObj.lightList[i].name !== minObj.name) {
  556. if (bigObj.lightList[i].type == 'light') {
  557. if (bigObj.lightList[i].state != '1') {
  558. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  559. }
  560. } else {
  561. max = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  562. }
  563. }
  564. }
  565. } else {
  566. //上最近
  567. if (min) {
  568. if (min.y < bigObj.lightList[i].y) {
  569. if (bigObj.lightList[i].name !== minObj.name) {
  570. if (bigObj.lightList[i].type == 'light') {
  571. if (bigObj.lightList[i].state != '2') {
  572. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  573. }
  574. } else {
  575. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  576. }
  577. }
  578. }
  579. } else {
  580. if (bigObj.lightList[i].name !== minObj.name) {
  581. if (bigObj.lightList[i].type == 'light') {
  582. if (bigObj.lightList[i].state != '2') {
  583. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  584. }
  585. } else {
  586. min = JSON.parse(JSON.stringify(bigObj.lightList[i]))
  587. }
  588. }
  589. }
  590. }
  591. }
  592. if (min != null) {
  593. obj.pointVOList[lookingTargetReturnSubscript(min.name, obj.pointVOList)].pointDistance = minObj.y - min.y
  594. }
  595. if (max != null) {
  596. obj.pointVOList[lookingTargetReturnSubscript(max.name, obj.pointVOList)].pointDistance = max.y - minObj.y
  597. }
  598. //如果是交通端点-进行跨域连接
  599. if (minObj.type == 'connect') {
  600. for (let j = 0; j < newMapList.length; j++) {
  601. if (newMapList[j].type == 2) {
  602. for (let k = 0; k < newMapList[j].lightList.length; k++) {
  603. if (newMapList[j].lightList[k].type == 'traffic') {
  604. let lx = newMapList[j].x + newMapList[j].lightList[k].x
  605. let ly = newMapList[j].y + newMapList[j].lightList[k].y
  606. if (minObj.y > (bigObj.h / 2)) {
  607. //向下延展
  608. if (lx >= (bigObj.x + minObj.x - 1) && lx <= (bigObj.x + minObj.x + 1) && ly >= (bigObj.y + bigObj.h) && ly <= (bigObj.y + bigObj.h + minHeight)) {
  609. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = ly - bigObj.y - minObj.y
  610. }
  611. } else {
  612. //向上延展
  613. if (lx >= (bigObj.x + minObj.x - 1) && lx <= (bigObj.x + minObj.x + 1) && ly >= bigObj.y - minHeight && ly <= bigObj.y) {
  614. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = bigObj.y - ly
  615. }
  616. }
  617. }
  618. }
  619. }
  620. }
  621. } else if (minObj.type == 'traffic') {
  622. for (let j = 0; j < newMapList.length; j++) {
  623. if (newMapList[j].type == 2) {
  624. for (let k = 0; k < newMapList[j].lightList.length; k++) {
  625. if (newMapList[j].lightList[k].type == 'connect') {
  626. let lx = newMapList[j].x + newMapList[j].lightList[k].x
  627. let ly = newMapList[j].y + newMapList[j].lightList[k].y
  628. //向右延展
  629. if (lx >= (bigObj.x + bigObj.w) && lx <= (bigObj.x + bigObj.w + tentaclesLength) && ly >= (bigObj.y + minObj.y - 1) && ly <= (bigObj.y + minObj.y + 1)) {
  630. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = lx - bigObj.x - minObj.x
  631. }
  632. //向左延展
  633. if (lx >= (bigObj.x - tentaclesLength) && lx <= bigObj.x && ly >= (bigObj.y + minObj.y - 1) && ly <= (bigObj.y + minObj.y + 1)) {
  634. obj.pointVOList[lookingTargetReturnSubscript(newMapList[j].lightList[k].name, obj.pointVOList)].pointDistance = (bigObj.x + minObj.x) - lx
  635. }
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. return obj
  643. }
  644. /*
  645. * 寻找目标位置
  646. * 传入:name-匹配名称,list-目标数组
  647. * 返回:返回下标
  648. * 示例: (本方法没有再外部引用,只在本JS内由 calculateAssociatedLength 方法引用)
  649. * lookingTargetReturnSubscript(min.name,obj.pointVOList)
  650. */
  651. export function lookingTargetReturnSubscript(name, list) {
  652. for (let i = 0; i < list.length; i++) {
  653. if (list[i].pointName == name) {
  654. return i
  655. }
  656. }
  657. }
  658. /*
  659. * 房间内-门的拖拽判定与移动结果
  660. * 传入:mapList-布局数据,boxIndex-当前选中index,minIndex-子类下标,event-鼠标坐标数据,scrollLeft-画布ref.scrollLeft坐标,scrollTop-画布ref.scrollTop坐标
  661. * 返回:一个对象 包含 朝向-toward,坐标X-x,坐标Y-y
  662. * 示例:
  663. * let obj = doorMoveJudge(this.mapList,this.boxIndex,this.minIndex,event,scrollLeft,scrollTop);
  664. */
  665. export function doorMoveJudge(mapList, boxIndex,minIndex, event, scrollLeft, scrollTop) {
  666. let x = event.clientX + scrollLeft - borderLeft
  667. let y = event.clientY + scrollTop - borderTop
  668. let yt = y - mapList[boxIndex].y
  669. let yb = mapList[boxIndex].y + mapList[boxIndex].h - y
  670. let xl = x - mapList[boxIndex].x
  671. let xr = mapList[boxIndex].x + mapList[boxIndex].w - x
  672. let num = Math.min(yt, yb, xl, xr)
  673. let obj = JSON.parse(JSON.stringify(mapList[boxIndex]))
  674. //计算靠近方向
  675. if (num === yt) {
  676. obj.h = doorHeight;
  677. obj.w = doorWidth;
  678. obj.doorList[minIndex].toward = 'top';
  679. obj.doorList[minIndex].x = (x - mapList[boxIndex].x - (doorWidth / 2)) < 0 ? 0 : (
  680. (x - mapList[boxIndex].x + (doorWidth / 2)) > mapList[boxIndex].w ? mapList[boxIndex].w - doorWidth :
  681. x - mapList[boxIndex].x - (doorWidth / 2))
  682. obj.doorList[minIndex].y = 2
  683. if(childrenOverlapCheck(obj)){
  684. return obj.doorList[minIndex]
  685. }else{
  686. return false
  687. }
  688. } else if (num === yb) {
  689. obj.h = doorHeight;
  690. obj.w = doorWidth;
  691. obj.doorList[minIndex].toward = 'bottom';
  692. obj.doorList[minIndex].x = (x - mapList[boxIndex].x - (doorWidth / 2)) < 0 ? 0 : (
  693. (x - mapList[boxIndex].x + (doorWidth / 2)) > mapList[boxIndex].w ? mapList[boxIndex].w - doorWidth :
  694. x - mapList[boxIndex].x - (doorWidth / 2))
  695. obj.doorList[minIndex].y = mapList[boxIndex].h - doorHeight - 2
  696. if(childrenOverlapCheck(obj)){
  697. return obj.doorList[minIndex]
  698. }else{
  699. return false
  700. }
  701. } else if (num === xl) {
  702. obj.h = doorHeight;
  703. obj.w = doorWidth;
  704. obj.doorList[minIndex].toward = 'left';
  705. obj.doorList[minIndex].x = 2
  706. obj.doorList[minIndex].y = (y - mapList[boxIndex].y - (doorHeight / 2)) < 0 ? 0 : (
  707. (y - mapList[boxIndex].y + (doorHeight / 2)) > mapList[boxIndex].h ? mapList[boxIndex].h - doorHeight :
  708. y - mapList[boxIndex].y - (doorHeight / 2))
  709. if(childrenOverlapCheck(obj)){
  710. return obj.doorList[minIndex]
  711. }else{
  712. return false
  713. }
  714. } else if (num === xr) {
  715. obj.h = maxWidth;
  716. obj.w = minWidth;
  717. obj.doorList[minIndex].toward = 'right';
  718. obj.doorList[minIndex].x = mapList[boxIndex].w - doorWidth - 2
  719. obj.doorList[minIndex].y = (y - mapList[boxIndex].y - (doorHeight / 2)) < 0 ? 0 : (
  720. (y - mapList[boxIndex].y + (doorHeight / 2)) > mapList[boxIndex].h ? mapList[boxIndex].h - doorHeight :
  721. y - mapList[boxIndex].y - (doorHeight / 2))
  722. if(childrenOverlapCheck(obj)){
  723. return obj.doorList[minIndex]
  724. }else{
  725. return false
  726. }
  727. }
  728. }
  729. /*
  730. * 房间内-灯的拖拽判定与移动结果
  731. * 传入:mapList-布局数据,boxIndex-当前选中index,minIndex-子类下标,event-鼠标坐标数据,scrollLeft-画布ref.scrollLeft坐标,scrollTop-画布ref.scrollTop坐标
  732. * 返回:一个对象 包含 坐标X-x,坐标Y-y
  733. * 示例:
  734. * let obj = lightMoveJudge(this.mapList,this.boxIndex,this.minIndex,event,scrollLeft,scrollTop);
  735. */
  736. export function lightMoveJudge(mapList, boxIndex, minIndex, event, scrollLeft, scrollTop) {
  737. let x = event.clientX + scrollLeft - borderLeft
  738. let y = event.clientY + scrollTop - borderTop
  739. let obj = JSON.parse(JSON.stringify(mapList[boxIndex]))
  740. if (mapList[boxIndex].w > mapList[boxIndex].h) {
  741. obj.lightList[minIndex].x = x - mapList[boxIndex].x - (maxLightNum / 2) < 10 ? 10 : (
  742. x - mapList[boxIndex].x - (maxLightNum / 2) + maxLightNum > mapList[boxIndex].w - 10 ? mapList[boxIndex].w - maxLightNum - 10 :
  743. x - mapList[boxIndex].x - (maxLightNum / 2))
  744. obj.lightList[minIndex].y = (mapList[boxIndex].h / 2) - (maxLightNum / 2)
  745. if(childrenOverlapCheck(obj)){
  746. return obj.lightList[minIndex]
  747. }else{
  748. return false
  749. }
  750. } else if (mapList[boxIndex].h > mapList[boxIndex].w) {
  751. obj.lightList[minIndex].x = (mapList[boxIndex].w / 2) - (maxLightNum / 2)
  752. obj.lightList[minIndex].y = y - mapList[boxIndex].y - (maxLightNum / 2) < 10 ? 10 : (
  753. y - mapList[boxIndex].y - (maxLightNum / 2) + maxLightNum > mapList[boxIndex].h - 10 ? mapList[boxIndex].h - maxLightNum - 10 :
  754. y - mapList[boxIndex].y - (maxLightNum / 2))
  755. if(childrenOverlapCheck(obj)){
  756. return obj.lightList[minIndex]
  757. }else{
  758. return false
  759. }
  760. }
  761. }
  762. /*
  763. * 房间移动
  764. * 传入:mapList-布局数据,boxIndex-当前选中index,clientX-当前X坐标,clientY-当前Y坐标,event-鼠标数据
  765. * 返回:一个对象 包含 坐标X-x,坐标Y-y
  766. * 示例:
  767. * let obj = roomMove(this.mapList,this.boxIndex,this.clientX,this.clientY,event)
  768. * if(obj.x){
  769. * this.$set(this.mapList[this.boxIndex], 'x', obj.x)
  770. * }
  771. * if (obj.y){
  772. * this.$set(this.mapList[this.boxIndex], 'y', obj.y)
  773. * }
  774. */
  775. export function roomMove(mapList, boxIndex, clientX, clientY, event) {
  776. let obj = {
  777. x: null,
  778. y: null
  779. }
  780. if (clientX > event.clientX) {
  781. if (moveBoundaryCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left') &&
  782. moveOverlapCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left', mapList, boxIndex)) {
  783. obj.x = mapList[boxIndex].x - (clientX - event.clientX)
  784. }
  785. } else if (event.clientX > clientX) {
  786. if (moveBoundaryCheck(mapList[boxIndex].x + (event.clientX - clientX) + mapList[boxIndex].w, 'right') &&
  787. moveOverlapCheck(mapList[boxIndex].x + (event.clientX - clientX), 'right', mapList, boxIndex)) {
  788. obj.x = mapList[boxIndex].x + (event.clientX - clientX)
  789. }
  790. }
  791. if (clientY > event.clientY) {
  792. if (moveBoundaryCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top') &&
  793. moveOverlapCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top', mapList, boxIndex)) {
  794. obj.y = mapList[boxIndex].y - (clientY - event.clientY)
  795. }
  796. } else if (event.clientY > clientY) {
  797. if (moveBoundaryCheck(mapList[boxIndex].y + (event.clientY - clientY) + mapList[boxIndex].h, 'bottom') &&
  798. moveOverlapCheck(mapList[boxIndex].y + (event.clientY - clientY), 'bottom', mapList, boxIndex)) {
  799. obj.y = mapList[boxIndex].y + (event.clientY - clientY)
  800. }
  801. }
  802. return obj
  803. }
  804. /*
  805. * 添加房间
  806. * 传入:e-鼠标数据,mapList-布局数据,borderLeft-左侧边界,borderLeft-上方边界-最小宽度,grab-抓取类型,scrollLeft-画布ref.scrollLeft坐标,scrollTop-画布ref.scrollTop坐标
  807. * 返回:完整的房间对象数据
  808. * 示例:
  809. * let obj = roomAdd(e,this.mapList,this.grab,this.$refs.maxBigBox.scrollLeft,this.$refs.maxBigBox.scrollTop,);
  810. if(obj){
  811. this.mapList.push(obj);
  812. }
  813. */
  814. export function roomAdd(e, mapList, grab, scrollLeft, scrollTop) {
  815. let x = e.clientX + scrollLeft
  816. let y = e.clientY + scrollTop
  817. if (x > borderLeft && x < (borderLeft + layerWidth) &&
  818. y > borderTop && y < (borderTop + layerHeight)) {
  819. let newX = x - borderLeft - (minWidth / 2)
  820. let newY = y - borderTop - (minHeight / 2)
  821. if (moveBoundaryCheck(newX, 'left') && moveBoundaryCheck(newX + minWidth, 'right') && moveBoundaryCheck(newY, 'top') && moveBoundaryCheck(newY + minHeight, 'bottom') &&
  822. placementOverlapCheck(newX, newY, 'left', mapList) && placementOverlapCheck(newX, newY, 'right', mapList) && placementOverlapCheck(newX, newY, 'top', mapList) && placementOverlapCheck(newX, newY, 'bottom', mapList)) {
  823. let obj = {
  824. x: newX,
  825. y: newY,
  826. w: minWidth,
  827. h: minHeight,
  828. type: grab//1房间2楼道3疏散通道
  829. }
  830. if (grab == 1 || grab == 3) {
  831. obj.doorList = []
  832. } else if (grab == 2) {
  833. obj.lightList = []
  834. }
  835. return obj
  836. } else {
  837. return false
  838. }
  839. } else {
  840. return false
  841. }
  842. }
  843. /*
  844. * 添加灯
  845. * 传入:event-鼠标坐标数据,scrollLeft-画布ref.scrollLeft坐标,scrollTop-画布ref.scrollTop坐标,mapList-画布数据,grab-抓取类型
  846. * 返回:完整的房间对象数据
  847. * 示例:
  848. * let obj = lightAdd(event,this.$refs.maxBigBox.scrollLeft,this.$refs.maxBigBox.scrollTop,this.mapList,this.grab);
  849. if (obj){
  850. this.mapList[obj.index].lightList.push({
  851. type:obj.type,
  852. state:obj.state,
  853. w:obj.w,
  854. h:obj.h,
  855. x:obj.x,
  856. y:obj.y,
  857. });
  858. }
  859. */
  860. export function lightAdd(event, scrollLeft, scrollTop, mapList, grab) {
  861. let x = event.clientX + scrollLeft - borderLeft
  862. let y = event.clientY + scrollTop - borderTop
  863. for (let i = 0; i < mapList.length; i++) {
  864. if (x > mapList[i].x && x < (mapList[i].x + mapList[i].w) &&
  865. y > mapList[i].y && y < (mapList[i].y + mapList[i].h)) {
  866. if (mapList[i].type == '1') {
  867. //房间
  868. if (grab != '4' && grab != '5') {
  869. Message({
  870. message: '房间只可添加门',
  871. type: 'error',
  872. offset: 100
  873. })
  874. return
  875. }
  876. } else if (mapList[i].type == '2') {
  877. //走廊
  878. if (grab != '6') {
  879. Message({
  880. message: '走廊只可添加疏散灯',
  881. type: 'error',
  882. offset: 100
  883. })
  884. return
  885. }
  886. } else if (mapList[i].type == '3') {
  887. //疏散通道
  888. if (grab != '4' && grab != '5') {
  889. Message({
  890. message: '楼道只可添加门',
  891. type: 'error',
  892. offset: 100
  893. })
  894. return
  895. }
  896. return
  897. }
  898. if (mapList[i].w > mapList[i].h) {
  899. // 横向
  900. let obj = { index: i, type: 'light', state: '', w: maxLightNum, h: maxLightNum, x: x - mapList[i].x - (maxLightNum / 2), y: (mapList[i].h / 2) - (maxLightNum / 2) }
  901. let newObj = {w: maxLightNum, h: maxLightNum, x: x - mapList[i].x - (maxLightNum / 2), y: (mapList[i].h / 2) - (maxLightNum / 2)};
  902. if(mapList[i].lightList[0]){
  903. let newList = JSON.parse(JSON.stringify(mapList[i]))
  904. newList.lightList.push(newObj);
  905. if(childrenOverlapCheck(newList)){
  906. return obj;
  907. }else{
  908. return false
  909. }
  910. }else{
  911. return obj;
  912. }
  913. } else {
  914. let obj ={ index: i, type: 'light', state: '', w: maxLightNum, h: maxLightNum, x: (mapList[i].w / 2) - (maxLightNum / 2), y: y - mapList[i].y - (maxLightNum / 2) }
  915. let newObj = {w: maxLightNum, h: maxLightNum, x: (mapList[i].w / 2) - (maxLightNum / 2), y: y - mapList[i].y - (maxLightNum / 2)}
  916. if(mapList[i].lightList[0]){
  917. let newList = JSON.parse(JSON.stringify(mapList[i]))
  918. newList.lightList.push(newObj);
  919. if(childrenOverlapCheck(newList)){
  920. return obj;
  921. }else{
  922. return false
  923. }
  924. }else{
  925. return obj;
  926. }
  927. }
  928. }
  929. }
  930. }
  931. /*
  932. * 添加门
  933. * 传入:e-鼠标数据,mapList-布局数据,scrollLeft-画布ref.scrollLeft坐标,scrollTop-画布ref.scrollTop坐标,grab-抓取类型,
  934. * 返回:完整的房间对象数据
  935. * 示例:
  936. * let obj = addDoor(e,this.mapList,this.$refs.maxBigBox.scrollLeft,this.$refs.maxBigBox.scrollTop,this.grab);
  937. if(obj){
  938. this.mapList.push(obj);
  939. }
  940. */
  941. export function addDoor(event, mapList, scrollLeft, scrollTop, grab) {
  942. let x = event.clientX + scrollLeft - borderLeft
  943. let y = event.clientY + scrollTop - borderTop
  944. for (let i = 0; i < mapList.length; i++) {
  945. if (x > mapList[i].x && x < (mapList[i].x + mapList[i].w) &&
  946. y > mapList[i].y && y < (mapList[i].y + mapList[i].h)) {
  947. if (mapList[i].type == '1' || mapList[i].type == '3') {
  948. //房间
  949. if (grab != '4' && grab != '5') {
  950. this.msgError('房间与楼道只可添加门窗')
  951. return
  952. }
  953. } else if (mapList[i].type == '2') {
  954. //走廊
  955. if (grab != '6') {
  956. this.msgError('走廊只可添加疏散灯')
  957. return
  958. }
  959. }
  960. let yt = y - mapList[i].y
  961. let yb = mapList[i].y + mapList[i].h - y
  962. let xl = x - mapList[i].x
  963. let xr = mapList[i].x + mapList[i].w - x
  964. let num = Math.min(yt, yb, xl, xr)
  965. //计算靠近方向
  966. if (num === yt) {
  967. return {
  968. index: i,
  969. type: 'door',
  970. toward: 'top',
  971. w: doorWidth,
  972. h: doorHeight,
  973. x: x - mapList[i].x - (doorWidth / 2),
  974. y: 2
  975. }
  976. } else if (num === yb) {
  977. return {
  978. index: i,
  979. type: 'door',
  980. toward: 'bottom',
  981. w: doorWidth,
  982. h: doorHeight,
  983. x: x - mapList[i].x - (doorWidth / 2),
  984. y: mapList[i].h - doorHeight - 2
  985. }
  986. } else if (num === xl) {
  987. return {
  988. index: i,
  989. type: 'door',
  990. toward: 'left',
  991. w: doorWidth,
  992. h: doorHeight,
  993. x: 2,
  994. y: y - mapList[i].y - (doorHeight / 2)
  995. }
  996. } else if (num === xr) {
  997. return {
  998. index: i,
  999. type: 'door',
  1000. toward: 'right',
  1001. w: doorWidth,
  1002. h: doorHeight,
  1003. x: mapList[i].w - doorWidth - 2,
  1004. y: y - mapList[i].y - (doorHeight / 2)
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. /*
  1011. * 四角缩放
  1012. * 传入:mapList-布局数据,boxIndex-当前选中index,event-鼠标数据,clientX-当前X坐标,clientY-当前Y坐标,type-拖拽方向状态
  1013. * 返回:true 或者 false
  1014. * 示例:let obj = fourCornersZoom(this.mapList,this.boxIndex,event,this.clientX,this.clientY,this.moveType);
  1015. if(obj){
  1016. this.$set(this.mapList[this.boxIndex],'x',obj.x?obj.x:this.mapList[this.boxIndex].x);
  1017. }
  1018. */
  1019. export function fourCornersZoom(mapList, boxIndex, event, clientX, clientY, type) {
  1020. let obj = {}
  1021. if (type == '4') {
  1022. if (clientX > event.clientX) {
  1023. if (moveBoundaryCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left') &&
  1024. moveOverlapCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left', mapList, boxIndex) &&
  1025. sizeCheck(mapList[boxIndex].w + (clientX - event.clientX), 'w', '+')) {
  1026. obj.x = mapList[boxIndex].x - (clientX - event.clientX)
  1027. obj.w = mapList[boxIndex].w + (clientX - event.clientX)
  1028. }
  1029. } else if (event.clientX > clientX) {
  1030. if (sizeCheck(mapList[boxIndex].w - (event.clientX - clientX), 'w', '-')) {
  1031. obj.x = mapList[boxIndex].x + (event.clientX - clientX)
  1032. obj.w = mapList[boxIndex].w - (event.clientX - clientX)
  1033. }
  1034. }
  1035. if (clientY > event.clientY) {
  1036. if (moveBoundaryCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top') &&
  1037. moveOverlapCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top', mapList, boxIndex) &&
  1038. sizeCheck(mapList[boxIndex].h + (clientY - event.clientY), 'h', '+')) {
  1039. obj.y = mapList[boxIndex].y - (clientY - event.clientY)
  1040. obj.h = mapList[boxIndex].h + (clientY - event.clientY)
  1041. }
  1042. } else if (event.clientY > clientY) {
  1043. if (sizeCheck(mapList[boxIndex].h - (event.clientY - clientY), 'h', '-')) {
  1044. obj.y = mapList[boxIndex].y + (event.clientY - clientY)
  1045. obj.h = mapList[boxIndex].h - (event.clientY - clientY)
  1046. }
  1047. }
  1048. } else if (type == '3') {
  1049. if (clientX > event.clientX) {
  1050. if (moveBoundaryCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left') &&
  1051. moveOverlapCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left', mapList, boxIndex) &&
  1052. sizeCheck(mapList[boxIndex].w + (clientX - event.clientX), 'w', '+')) {
  1053. obj.x = mapList[boxIndex].x - (clientX - event.clientX)
  1054. obj.w = mapList[boxIndex].w + (clientX - event.clientX)
  1055. }
  1056. } else if (event.clientX > clientX) {
  1057. if (sizeCheck(mapList[boxIndex].w - (event.clientX - clientX), 'w', '-')) {
  1058. obj.x = mapList[boxIndex].x + (event.clientX - clientX)
  1059. obj.w = mapList[boxIndex].w - (event.clientX - clientX)
  1060. }
  1061. }
  1062. if (clientY > event.clientY) {
  1063. if (sizeCheck(mapList[boxIndex].h - (clientY - event.clientY), 'h', '-')) {
  1064. obj.h = mapList[boxIndex].h - (clientY - event.clientY)
  1065. }
  1066. } else if (event.clientY > clientY) {
  1067. if (moveBoundaryCheck(mapList[boxIndex].y + (event.clientY - clientY) + mapList[boxIndex].h, 'bottom') &&
  1068. moveOverlapCheck(mapList[boxIndex].y + (event.clientY - clientY), 'bottom', mapList, boxIndex) &&
  1069. sizeCheck(mapList[boxIndex].h + (event.clientY - clientY), 'h', '+')) {
  1070. obj.h = mapList[boxIndex].h + (event.clientY - clientY)
  1071. }
  1072. }
  1073. } else if (type == '2') {
  1074. if (clientX > event.clientX) {
  1075. if (sizeCheck(mapList[boxIndex].w - (clientX - event.clientX), 'w', '-')) {
  1076. obj.w = mapList[boxIndex].w - (clientX - event.clientX)
  1077. }
  1078. } else if (event.clientX > clientX) {
  1079. if (moveBoundaryCheck(mapList[boxIndex].x + (event.clientX - clientX) + mapList[boxIndex].w, 'right') &&
  1080. moveOverlapCheck(mapList[boxIndex].x + (event.clientX - clientX), 'right', mapList, boxIndex) &&
  1081. sizeCheck(mapList[boxIndex].w + (event.clientX - clientX), 'w', '+')) {
  1082. obj.w = mapList[boxIndex].w + (event.clientX - clientX)
  1083. }
  1084. }
  1085. if (clientY > event.clientY) {
  1086. if (sizeCheck(mapList[boxIndex].h - (clientY - event.clientY), 'h', '-')) {
  1087. obj.h = mapList[boxIndex].h - (clientY - event.clientY)
  1088. }
  1089. } else if (event.clientY > clientY) {
  1090. if (moveBoundaryCheck(mapList[boxIndex].y + (event.clientY - clientY) + mapList[boxIndex].h, 'bottom') &&
  1091. moveOverlapCheck(mapList[boxIndex].y + (event.clientY - clientY), 'bottom', mapList, boxIndex) &&
  1092. sizeCheck(mapList[boxIndex].h + (event.clientY - clientY), 'h', '+')) {
  1093. obj.h = mapList[boxIndex].h + (event.clientY - clientY)
  1094. }
  1095. }
  1096. } else if (type == '1') {
  1097. if (clientX > event.clientX) {
  1098. if (sizeCheck(mapList[boxIndex].w - (clientX - event.clientX), 'w', '-')) {
  1099. obj.w = mapList[boxIndex].w - (clientX - event.clientX)
  1100. }
  1101. } else if (event.clientX > clientX) {
  1102. if (moveBoundaryCheck(mapList[boxIndex].x + (event.clientX - clientX) + mapList[boxIndex].w, 'right') &&
  1103. moveOverlapCheck(mapList[boxIndex].x + (event.clientX - clientX), 'right', mapList, boxIndex) &&
  1104. sizeCheck(mapList[boxIndex].w + (event.clientX - clientX), 'w', '+')) {
  1105. obj.w = mapList[boxIndex].w + (event.clientX - clientX)
  1106. }
  1107. }
  1108. if (clientY > event.clientY) {
  1109. if (moveBoundaryCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top') &&
  1110. moveOverlapCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top', mapList, boxIndex) &&
  1111. sizeCheck(mapList[boxIndex].h + (clientY - event.clientY), 'h', '+')) {
  1112. obj.y = mapList[boxIndex].y - (clientY - event.clientY)
  1113. obj.h = mapList[boxIndex].h + (clientY - event.clientY)
  1114. }
  1115. } else if (event.clientY > clientY) {
  1116. if (sizeCheck(mapList[boxIndex].h - (event.clientY - clientY), 'h', '-')) {
  1117. obj.y = mapList[boxIndex].y + (event.clientY - clientY)
  1118. obj.h = mapList[boxIndex].h - (event.clientY - clientY)
  1119. }
  1120. }
  1121. }
  1122. if (mapList[boxIndex].type == '1' || mapList[boxIndex].type == '3') {
  1123. let newList = JSON.parse(JSON.stringify(mapList[boxIndex]))
  1124. newList.w = obj.w ? obj.w : newList.w
  1125. newList.h = obj.h ? obj.h : newList.h
  1126. obj.doorList = doorDragJudge(newList)
  1127. if (!obj.doorList) {
  1128. return false
  1129. }
  1130. }
  1131. if (mapList[boxIndex].type == '2') {
  1132. let newList = JSON.parse(JSON.stringify(mapList[boxIndex]))
  1133. newList.w = obj.w ? obj.w : newList.w
  1134. newList.h = obj.h ? obj.h : newList.h
  1135. obj.lightList = lightDragJudge(newList)
  1136. if (!obj.lightList) {
  1137. return false
  1138. }
  1139. }
  1140. return obj
  1141. }
  1142. /*
  1143. * 四边缩放
  1144. * 传入:mapList-布局数据,boxIndex-当前选中index,event-鼠标数据,clientX-当前X坐标,clientY-当前Y坐标,type-拖拽方向状态
  1145. * 返回:true 或者 false
  1146. * 示例:let obj = fourCornersZoom(this.mapList,this.boxIndex,event,this.clientX,this.clientY,this.moveType);
  1147. if(obj){
  1148. this.$set(this.mapList[this.boxIndex],'x',obj.x?obj.x:this.mapList[this.boxIndex].x);
  1149. }
  1150. */
  1151. export function fourEdgeZoom(mapList, boxIndex, event, clientX, clientY, type) {
  1152. let obj = {}
  1153. if (type == '4') {
  1154. if (clientX > event.clientX) {
  1155. if (moveBoundaryCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left') &&
  1156. moveOverlapCheck(mapList[boxIndex].x - (clientX - event.clientX), 'left', mapList, boxIndex) &&
  1157. sizeCheck(mapList[boxIndex].w + (clientX - event.clientX), 'w', '+')) {
  1158. obj.x = mapList[boxIndex].x - (clientX - event.clientX)
  1159. obj.w = mapList[boxIndex].w + (clientX - event.clientX)
  1160. }
  1161. } else if (event.clientX > clientX) {
  1162. if (sizeCheck(mapList[boxIndex].w - (event.clientX - clientX), 'w', '-')) {
  1163. obj.x = mapList[boxIndex].x + (event.clientX - clientX)
  1164. obj.w = mapList[boxIndex].w - (event.clientX - clientX)
  1165. }
  1166. }
  1167. } else if (type == '3') {
  1168. if (clientY > event.clientY) {
  1169. if (sizeCheck(mapList[boxIndex].h - (clientY - event.clientY), 'h', '-')) {
  1170. obj.h = mapList[boxIndex].h - (clientY - event.clientY)
  1171. }
  1172. } else if (event.clientY > clientY) {
  1173. if (moveBoundaryCheck(mapList[boxIndex].y + (event.clientY - clientY) + mapList[boxIndex].h, 'bottom') &&
  1174. moveOverlapCheck(mapList[boxIndex].y + (event.clientY - clientY), 'bottom', mapList, boxIndex) &&
  1175. sizeCheck(mapList[boxIndex].h + (event.clientY - clientY), 'h', '+')) {
  1176. obj.h = mapList[boxIndex].h + (event.clientY - clientY)
  1177. }
  1178. }
  1179. } else if (type == '2') {
  1180. if (clientX > event.clientX) {
  1181. if (sizeCheck(mapList[boxIndex].w - (clientX - event.clientX), 'w', '-')) {
  1182. obj.w = mapList[boxIndex].w - (clientX - event.clientX)
  1183. }
  1184. } else if (event.clientX > clientX) {
  1185. if (moveBoundaryCheck(mapList[boxIndex].x + (event.clientX - clientX) + mapList[boxIndex].w, 'right') &&
  1186. moveOverlapCheck(mapList[boxIndex].x + (event.clientX - clientX), 'right', mapList, boxIndex) &&
  1187. sizeCheck(mapList[boxIndex].w + (event.clientX - clientX), 'w', '+')) {
  1188. obj.w = mapList[boxIndex].w + (event.clientX - clientX)
  1189. }
  1190. }
  1191. } else if (type == '1') {
  1192. if (clientY > event.clientY) {
  1193. if (moveBoundaryCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top') &&
  1194. moveOverlapCheck(mapList[boxIndex].y - (clientY - event.clientY), 'top', mapList, boxIndex) &&
  1195. sizeCheck(mapList[boxIndex].h + (clientY - event.clientY), 'h', '+')) {
  1196. obj.y = mapList[boxIndex].y - (clientY - event.clientY)
  1197. obj.h = mapList[boxIndex].h + (clientY - event.clientY)
  1198. }
  1199. } else if (event.clientY > clientY) {
  1200. if (sizeCheck(mapList[boxIndex].h - (event.clientY - clientY), 'h', '-')) {
  1201. obj.y = mapList[boxIndex].y + (event.clientY - clientY)
  1202. obj.h = mapList[boxIndex].h - (event.clientY - clientY)
  1203. }
  1204. }
  1205. }
  1206. if (mapList[boxIndex].type == '1' || mapList[boxIndex].type == '3') {
  1207. let newList = JSON.parse(JSON.stringify(mapList[boxIndex]))
  1208. newList.w = obj.w ? obj.w : newList.w
  1209. newList.h = obj.h ? obj.h : newList.h
  1210. obj.doorList = doorDragJudge(newList)
  1211. if (!obj.doorList) {
  1212. return false
  1213. }
  1214. }
  1215. if (mapList[boxIndex].type == '2') {
  1216. let newList = JSON.parse(JSON.stringify(mapList[boxIndex]))
  1217. newList.w = obj.w ? obj.w : newList.w
  1218. newList.h = obj.h ? obj.h : newList.h
  1219. obj.lightList = lightDragJudge(newList)
  1220. if (!obj.lightList) {
  1221. return false
  1222. }
  1223. }
  1224. return obj
  1225. }
  1226. /*
  1227. * 门列表坐标修正
  1228. * 传入:obj-当前拖拽对象
  1229. * 返回:修正后的门列表数组
  1230. * 示例:obj.doorList = doorDragJudge(newList);
  1231. */
  1232. export function doorDragJudge(obj) {
  1233. for (let i = 0; i < obj.doorList.length; i++) {
  1234. if (obj.doorList[i].toward == 'left') {
  1235. obj.doorList[i].x = 0
  1236. obj.doorList[i].y = (obj.doorList[i].y + doorHeight) >= obj.h ? obj.h - doorHeight : obj.doorList[i].y
  1237. } else if (obj.doorList[i].toward == 'right') {
  1238. obj.doorList[i].x = obj.w - doorWidth
  1239. obj.doorList[i].y = (obj.doorList[i].y + doorHeight) >= obj.h ? obj.h - doorHeight : obj.doorList[i].y
  1240. } else if (obj.doorList[i].toward == 'top') {
  1241. obj.doorList[i].x = (obj.doorList[i].x + doorWidth) >= obj.w ? obj.w - doorWidth : obj.doorList[i].x
  1242. obj.doorList[i].y = 0
  1243. } else if (obj.doorList[i].toward == 'bottom') {
  1244. obj.doorList[i].x = (obj.doorList[i].x + doorWidth) >= obj.w ? parseInt(obj.w - doorWidth) : parseInt(obj.doorList[i].x)
  1245. obj.doorList[i].y = obj.h - doorHeight
  1246. }
  1247. }
  1248. if (childrenOverlapCheck(obj)) {
  1249. return obj.doorList[0] ? obj.doorList : []
  1250. } else {
  1251. return false
  1252. }
  1253. }
  1254. /*
  1255. * 灯列表坐标修正
  1256. * 传入:obj-当前拖拽对象
  1257. * 返回:修正后的灯列表数组
  1258. * 示例:obj.lightList = lightDragJudge(newList);
  1259. */
  1260. export function lightDragJudge(obj) {
  1261. if (obj.w > obj.h) {
  1262. zoomType = 1
  1263. if (obj.lightList[1]) {
  1264. if (obj.lightList[0].x == obj.lightList[1].x) {
  1265. for (let o = 0; o < obj.lightList.length; o++) {
  1266. obj.lightList[o].x = JSON.parse(JSON.stringify(obj.lightList[o].y))
  1267. obj.lightList[o].y = obj.h / 2 - maxLightNum / 2
  1268. }
  1269. } else {
  1270. for (let i = 0; i < obj.lightList.length; i++) {
  1271. obj.lightList[i].y = (obj.h / 2) - (maxLightNum / 2)
  1272. obj.lightList[i].x =
  1273. obj.lightList[i].x <= 10 ? 10 : (
  1274. (obj.lightList[i].x + maxLightNum) >= (obj.w - 10) ? (obj.w - maxLightNum - 10) :
  1275. obj.lightList[i].x)
  1276. }
  1277. }
  1278. } else {
  1279. for (let i = 0; i < obj.lightList.length; i++) {
  1280. obj.lightList[i].y = (obj.h / 2) - (maxLightNum / 2)
  1281. obj.lightList[i].x =
  1282. obj.lightList[i].x <= 10 ? 10 : (
  1283. (obj.lightList[i].x + maxLightNum) >= (obj.w - 10) ? (obj.w - maxLightNum - 10) :
  1284. obj.lightList[i].x)
  1285. }
  1286. }
  1287. } else if (obj.h > obj.w) {
  1288. zoomType = 2
  1289. if (obj.lightList[1]) {
  1290. if (obj.lightList[0].y == obj.lightList[1].y) {
  1291. for (let o = 0; o < obj.lightList.length; o++) {
  1292. obj.lightList[o].y = JSON.parse(JSON.stringify(obj.lightList[o].x))
  1293. obj.lightList[o].x = obj.w / 2 - maxLightNum / 2
  1294. }
  1295. } else {
  1296. for (let i = 0; i < obj.lightList.length; i++) {
  1297. obj.lightList[i].x = (obj.w / 2) - (maxLightNum / 2)
  1298. obj.lightList[i].y =
  1299. obj.lightList[i].y <= 10 ? 10 : (
  1300. (obj.lightList[i].y + maxLightNum) >= (obj.h - 10) ? (obj.h - maxLightNum - 10) :
  1301. obj.lightList[i].y)
  1302. }
  1303. }
  1304. } else {
  1305. for (let i = 0; i < obj.lightList.length; i++) {
  1306. obj.lightList[i].x = (obj.w / 2) - (maxLightNum / 2)
  1307. obj.lightList[i].y =
  1308. obj.lightList[i].y <= 10 ? 10 : (
  1309. (obj.lightList[i].y + maxLightNum) >= (obj.h - 10) ? (obj.h - maxLightNum - 10) :
  1310. obj.lightList[i].y)
  1311. }
  1312. }
  1313. } else {
  1314. if (zoomType == 1) {
  1315. obj.w = obj.w - 1
  1316. obj.h = obj.h + 1
  1317. } else if (zoomType == 2) {
  1318. obj.w = obj.w + 1
  1319. obj.h = obj.h - 1
  1320. }
  1321. }
  1322. let num1 = 0
  1323. let num2 = 0
  1324. for (let o = 0; o < obj.lightList.length; o++) {
  1325. num1 = num1 < obj.lightList[o].x ? obj.lightList[o].x : num1
  1326. num2 = num2 < obj.lightList[o].y ? obj.lightList[o].y : num2
  1327. }
  1328. console.log('w',obj.w);
  1329. console.log('obj.x',obj.x);
  1330. console.log('num1',num1);
  1331. console.log('maxLightNum',maxLightNum);
  1332. console.log('num1 + maxLightNum',num1 + maxLightNum);
  1333. console.log('h',obj.h);
  1334. console.log('obj.y',obj.y);
  1335. console.log('num2',num2);
  1336. console.log('maxLightNum',maxLightNum);
  1337. console.log('num2 + maxLightNum',num2 + maxLightNum);
  1338. if (zoomType == 1 && ((num2 + maxLightNum) > obj.h - 10)) {
  1339. return false
  1340. } else if (zoomType == 2 && ((num1 + maxLightNum) > obj.w - 10)) {
  1341. return false
  1342. }
  1343. if (childrenOverlapCheck(obj)) {
  1344. return obj.lightList[0] ? obj.lightList : []
  1345. } else {
  1346. return false
  1347. }
  1348. }
  1349. /************************************ 检查相关 ************************************/
  1350. /*
  1351. * 检查门朝向附近是否有楼道
  1352. * 传入:mapList-布局数据
  1353. * 返回:true 或者 false并提示错误
  1354. * 示例:
  1355. * if(checkDoorTo(this.mapList)){}
  1356. */
  1357. export function checkDoorTo(mapList) {
  1358. for (let i = 0; i < mapList.length; i++) {
  1359. if (mapList[i].type == 1 || mapList[i].type == 3) {
  1360. let x = 0
  1361. let y = 0
  1362. if (mapList[i].doorList[0].toward == 'top') {
  1363. x = mapList[i].x + mapList[i].doorList[0].x + (doorWidth / 2)
  1364. y = mapList[i].y - (minHeight / 2)
  1365. } else if (mapList[i].doorList[0].toward == 'bottom') {
  1366. x = mapList[i].x + mapList[i].doorList[0].x + (doorWidth / 2)
  1367. y = mapList[i].y + mapList[i].h + (minHeight / 2)
  1368. } else if (mapList[i].doorList[0].toward == 'left') {
  1369. x = mapList[i].x - (minHeight / 2)
  1370. y = mapList[i].y + mapList[i].doorList[0].y + (doorHeight / 2)
  1371. } else if (mapList[i].doorList[0].toward == 'right') {
  1372. x = mapList[i].x + mapList[i].w + (minHeight / 2)
  1373. y = mapList[i].y + mapList[i].doorList[0].y + (doorHeight / 2)
  1374. }
  1375. let num = 0
  1376. for (let j = 0; j < mapList.length; j++) {
  1377. if (mapList[j].type == 2) {
  1378. if (x > mapList[j].x && x < (mapList[j].x + mapList[j].w) &&
  1379. y > mapList[j].y && y < (mapList[j].y + mapList[j].h)) {
  1380. num++
  1381. }
  1382. }
  1383. }
  1384. if (num == 0) {
  1385. Message({
  1386. message: '有门的位置朝向不正确',
  1387. type: 'error',
  1388. offset: 100
  1389. })
  1390. return false
  1391. }
  1392. }
  1393. }
  1394. return true
  1395. }
  1396. /*
  1397. * 检查通道内灯是否都已绑定朝向
  1398. * 传入:mapList-布局数据
  1399. * 返回:true 或者 false并提示错误
  1400. * 示例:
  1401. * if(checkLightDirection(this.mapList){}
  1402. */
  1403. export function checkLightDirection(mapList) {
  1404. for (let i = 0; i < mapList.length; i++) {
  1405. if (mapList[i].type == 2) {
  1406. for (let j = 0; j < mapList[i].lightList.length; j++) {
  1407. if (!mapList[i].lightList[j].state) {
  1408. Message({
  1409. message: '请检查所有的灯是否都已选择朝向',
  1410. type: 'error',
  1411. offset: 100
  1412. })
  1413. return false
  1414. }
  1415. }
  1416. }
  1417. }
  1418. return true
  1419. }
  1420. /*
  1421. * 检查楼层是否有房间/逃生通道/楼道
  1422. * mapList-布局数据
  1423. * 返回:true 或者 false并提示错误
  1424. * 示例:
  1425. * if(checkRoom(this.mapList){}
  1426. */
  1427. export function checkRoom(mapList) {
  1428. //实验室数量
  1429. let num1 = 0
  1430. //逃生点数量
  1431. let num2 = 0
  1432. //楼道数量
  1433. let num3 = 0
  1434. //实验室门数量
  1435. let num4 = 0
  1436. for (let i = 0; i < mapList.length; i++) {
  1437. if (mapList[i].type == 1 || mapList[i].type == 3) {
  1438. if (mapList[i].type == 1) {
  1439. num1++
  1440. } else if (mapList[i].type == 3) {
  1441. num2++
  1442. }
  1443. if (mapList[i].doorList[0]) {
  1444. num4++
  1445. }
  1446. } else if (mapList[i].type == 2) {
  1447. num3++
  1448. }
  1449. }
  1450. if (num1 === 0) {
  1451. Message({
  1452. message: '请添加房间',
  1453. type: 'error',
  1454. offset: 100
  1455. })
  1456. return false
  1457. }
  1458. if (num2 === 0) {
  1459. Message({
  1460. message: '请添加应急出口',
  1461. type: 'error',
  1462. offset: 100
  1463. })
  1464. return false
  1465. }
  1466. if (num3 == 0) {
  1467. Message({
  1468. message: '请添加楼道',
  1469. type: 'error',
  1470. offset: 100
  1471. })
  1472. return false
  1473. }
  1474. if (num4 < (num1 + num2)) {
  1475. Message({
  1476. message: '请在每个房间与应急出口内添加门',
  1477. type: 'error',
  1478. offset: 100
  1479. })
  1480. return false
  1481. }
  1482. return true
  1483. }
  1484. /*
  1485. * 移动边界检查
  1486. * 传入:px-目标坐标,type-方向
  1487. * 返回:true 或者 false
  1488. * 示例:(本JS内部调用)
  1489. * if(moveBoundaryCheck(mapList[boxIndex].y + (event.clientY - clientY)+mapList[boxIndex].h,'bottom'){}
  1490. */
  1491. export function moveBoundaryCheck(px, type) {
  1492. if (type == 'left') {
  1493. return px > 0
  1494. } else if (type == 'right') {
  1495. return px < layerWidth
  1496. } else if (type == 'top') {
  1497. return px > 0
  1498. } else if (type == 'bottom') {
  1499. return px < layerHeight
  1500. }
  1501. }
  1502. /*
  1503. * 移动重叠检查
  1504. * 传入:px-目标坐标,type-方向,mapList-布局数据,boxIndex-当前选中index
  1505. * 返回:true 或者 false
  1506. * 示例:(本JS内部调用)
  1507. * if(moveOverlapCheck(mapList[boxIndex].x - (clientX - event.clientX),'left',mapList,boxIndex)){}
  1508. */
  1509. export function moveOverlapCheck(px, type, mapList, boxIndex) {
  1510. let num = 0
  1511. let x1 = null
  1512. let y1 = null
  1513. let x2 = null
  1514. let y2 = null
  1515. if (type == 'left') {
  1516. x1 = px
  1517. y1 = mapList[boxIndex].y
  1518. x2 = px
  1519. y2 = mapList[boxIndex].y + mapList[boxIndex].h
  1520. } else if (type == 'right') {
  1521. x1 = px + mapList[boxIndex].w
  1522. y1 = mapList[boxIndex].y
  1523. x2 = px + mapList[boxIndex].w
  1524. y2 = mapList[boxIndex].y + mapList[boxIndex].h
  1525. } else if (type == 'top') {
  1526. x1 = mapList[boxIndex].x
  1527. y1 = px
  1528. x2 = mapList[boxIndex].x + mapList[boxIndex].w
  1529. y2 = px
  1530. } else if (type == 'bottom') {
  1531. x1 = mapList[boxIndex].x
  1532. y1 = px + mapList[boxIndex].h
  1533. x2 = mapList[boxIndex].x + mapList[boxIndex].w
  1534. y2 = px + mapList[boxIndex].h
  1535. }
  1536. for (let i = 0; i < mapList.length; i++) {
  1537. if (boxIndex != i) {
  1538. if (
  1539. (x1 > mapList[i].x && x1 < (mapList[i].x + mapList[i].w) && y1 > mapList[i].y && y1 < (mapList[i].y + mapList[i].h)) ||
  1540. (x2 > mapList[i].x && x2 < (mapList[i].x + mapList[i].w) && y2 > mapList[i].y && y2 < (mapList[i].y + mapList[i].h))
  1541. ) {
  1542. num++
  1543. }
  1544. if (type == 'top' && x1 <= mapList[i].x && x2 >= (mapList[i].x + mapList[i].w) && y1 < (mapList[i].y + mapList[i].h) && y1 > mapList[i].y) {
  1545. num++
  1546. }
  1547. if (type == 'bottom' && x1 <= mapList[i].x && x2 >= (mapList[i].x + mapList[i].w) && y1 > mapList[i].y && y1 < (mapList[i].y + mapList[i].h)) {
  1548. num++
  1549. }
  1550. if (type == 'left' && y1 <= mapList[i].y && y2 >= (mapList[i].y + mapList[i].h) && x1 < (mapList[i].x + mapList[i].w) && x1 > mapList[i].x) {
  1551. num++
  1552. }
  1553. if (type == 'right' && y1 <= mapList[i].y && y2 >= (mapList[i].y + mapList[i].h) && x1 > mapList[i].x && x1 < (mapList[i].x + mapList[i].w)) {
  1554. num++
  1555. }
  1556. }
  1557. }
  1558. return num == 0
  1559. }
  1560. /*
  1561. * 尺寸检查
  1562. * 传入:px-目标尺寸,type-宽高类型,state-加减类型
  1563. * 返回:true 或者 false
  1564. * 示例:(本JS内部调用)
  1565. * if(sizeCheck(px,type,state)){}
  1566. */
  1567. export function sizeCheck(px, type, state) {
  1568. let num = 0
  1569. if (type == 'w' && state == '+') {
  1570. if (px > maxWidth) {
  1571. num++
  1572. }
  1573. } else if (type == 'w' && state == '-') {
  1574. if (px < minWidth) {
  1575. num++
  1576. }
  1577. } else if (type == 'h' && state == '+') {
  1578. if (px > maxHeight) {
  1579. num++
  1580. }
  1581. } else if (type == 'h' && state == '-') {
  1582. if (px < minHeight) {
  1583. num++
  1584. }
  1585. }
  1586. return num == 0
  1587. }
  1588. /*
  1589. * 放置重叠检查
  1590. * 传入:x-目标X坐标,y-目标Y坐标,type-方向,mapList-画布数据
  1591. * 返回:true 或者 false
  1592. * 示例:(本JS内部调用)
  1593. * if(placementOverlapCheck(x,y,type,mapList)){}
  1594. */
  1595. export function placementOverlapCheck(x, y, type, mapList) {
  1596. let num = 0
  1597. let x1 = null
  1598. let y1 = null
  1599. let x2 = null
  1600. let y2 = null
  1601. let xOne = x
  1602. let xTwo = x + minWidth
  1603. let yOne = y
  1604. let yTwo = y + minHeight
  1605. if (type == 'left') {
  1606. x1 = x
  1607. y1 = y
  1608. x2 = x
  1609. y2 = y + minHeight
  1610. } else if (type == 'right') {
  1611. x1 = x + minWidth
  1612. y1 = y
  1613. x2 = x + minWidth
  1614. y2 = y + minHeight
  1615. } else if (type == 'top') {
  1616. x1 = x
  1617. y1 = y
  1618. x2 = x + minWidth
  1619. y2 = y
  1620. } else if (type == 'bottom') {
  1621. x1 = x
  1622. y1 = y + minHeight
  1623. x2 = x + minWidth
  1624. y2 = y + minHeight
  1625. }
  1626. for (let i = 0; i < mapList.length; i++) {
  1627. // if(this.boxIndex != i){
  1628. if (
  1629. (xOne > mapList[i].x && xOne < (mapList[i].x + mapList[i].w) && yOne > mapList[i].y && yOne < (mapList[i].y + mapList[i].h)) ||
  1630. (xOne > mapList[i].x && xOne < (mapList[i].x + mapList[i].w) && yTwo > mapList[i].y && yTwo < (mapList[i].y + mapList[i].h)) ||
  1631. (xTwo > mapList[i].x && xTwo < (mapList[i].x + mapList[i].w) && yOne > mapList[i].y && yOne < (mapList[i].y + mapList[i].h)) ||
  1632. (xTwo > mapList[i].x && xTwo < (mapList[i].x + mapList[i].w) && yTwo > mapList[i].y && yTwo < (mapList[i].y + mapList[i].h))
  1633. ) {
  1634. num++
  1635. }
  1636. if (type == 'top' && x1 <= mapList[i].x && x2 >= (mapList[i].x + mapList[i].w) && y1 < (mapList[i].y + mapList[i].h) && y1 > mapList[i].y) {
  1637. num++
  1638. }
  1639. if (type == 'bottom' && x1 <= mapList[i].x && x2 >= (mapList[i].x + mapList[i].w) && y1 > mapList[i].y && y1 < (mapList[i].y + mapList[i].h)) {
  1640. num++
  1641. }
  1642. if (type == 'left' && y1 <= mapList[i].y && y2 >= (mapList[i].y + mapList[i].h) && x1 < (mapList[i].x + mapList[i].w) && x1 > mapList[i].x) {
  1643. num++
  1644. }
  1645. if (type == 'right' && y1 <= mapList[i].y && y2 >= (mapList[i].y + mapList[i].h) && x1 > mapList[i].x && x1 < (mapList[i].x + mapList[i].w)) {
  1646. num++
  1647. }
  1648. // }
  1649. }
  1650. return num == 0
  1651. }
  1652. /*
  1653. * 门/灯 重叠检查
  1654. * 传入:bigObj-父数据,minObj-子数据,index-当前下标
  1655. * 返回:true 或者 false
  1656. * 示例:(本JS内部调用)
  1657. * if(placementOverlapCheck(x,y,type,mapList)){}
  1658. */
  1659. export function childrenOverlapCheck(bigObj) {
  1660. if (bigObj.type == 1 || bigObj.type == 3) {
  1661. let num = 0
  1662. for (let i = 0; i < bigObj.doorList.length; i++) {
  1663. let x1 = bigObj.doorList[i].x
  1664. let y1 = bigObj.doorList[i].y
  1665. let x2 = bigObj.doorList[i].x + bigObj.doorList[i].w
  1666. let y2 = bigObj.doorList[i].y + bigObj.doorList[i].h
  1667. for (let o = 0; o < bigObj.doorList.length; o++) {
  1668. if (i != o) {
  1669. if (x1 >= bigObj.doorList[o].x && x1 <= (bigObj.doorList[o].x + bigObj.doorList[o].w) &&
  1670. y1 >= bigObj.doorList[o].y && y1 <= (bigObj.doorList[o].y + bigObj.doorList[o].h)) {
  1671. num++
  1672. }
  1673. if (x1 >= bigObj.doorList[o].x && x1 <= (bigObj.doorList[o].x + bigObj.doorList[o].w) &&
  1674. y2 >= bigObj.doorList[o].y && y2 <= (bigObj.doorList[o].y + bigObj.doorList[o].h)) {
  1675. num++
  1676. }
  1677. if (x2 >= bigObj.doorList[o].x && x2 <= (bigObj.doorList[o].x + bigObj.doorList[o].w) &&
  1678. y1 >= bigObj.doorList[o].y && y1 <= (bigObj.doorList[o].y + bigObj.doorList[o].h)) {
  1679. num++
  1680. }
  1681. if (x2 >= bigObj.doorList[o].x && x2 <= (bigObj.doorList[o].x + bigObj.doorList[o].w) &&
  1682. y2 >= bigObj.doorList[o].y && y2 <= (bigObj.doorList[o].y + bigObj.doorList[o].h)) {
  1683. num++
  1684. }
  1685. }
  1686. }
  1687. }
  1688. return num == 0
  1689. } else if (bigObj.type == 2) {
  1690. let num = 0
  1691. for (let i = 0; i < bigObj.lightList.length; i++) {
  1692. let x1 = bigObj.lightList[i].x
  1693. let y1 = bigObj.lightList[i].y
  1694. let x2 = bigObj.lightList[i].x + bigObj.lightList[i].w
  1695. let y2 = bigObj.lightList[i].y + bigObj.lightList[i].h
  1696. for (let o = 0; o < bigObj.lightList.length; o++) {
  1697. if (i != o) {
  1698. if (x1 >= bigObj.lightList[o].x && x1 <= (bigObj.lightList[o].x + bigObj.lightList[o].w) &&
  1699. y1 >= bigObj.lightList[o].y && y1 <= (bigObj.lightList[o].y + bigObj.lightList[o].h)) {
  1700. num++
  1701. }
  1702. if (x1 >= bigObj.lightList[o].x && x1 <= (bigObj.lightList[o].x + bigObj.lightList[o].w) &&
  1703. y2 >= bigObj.lightList[o].y && y2 <= (bigObj.lightList[o].y + bigObj.lightList[o].h)) {
  1704. num++
  1705. }
  1706. if (x2 >= bigObj.lightList[o].x && x2 <= (bigObj.lightList[o].x + bigObj.lightList[o].w) &&
  1707. y1 >= bigObj.lightList[o].y && y1 <= (bigObj.lightList[o].y + bigObj.lightList[o].h)) {
  1708. num++
  1709. }
  1710. if (x2 >= bigObj.lightList[o].x && x2 <= (bigObj.lightList[o].x + bigObj.lightList[o].w) &&
  1711. y2 >= bigObj.lightList[o].y && y2 <= (bigObj.lightList[o].y + bigObj.lightList[o].h)) {
  1712. num++
  1713. }
  1714. }
  1715. }
  1716. }
  1717. return num == 0
  1718. }
  1719. }
  1720. /*
  1721. * 检查实验室/灯设置
  1722. * 传入:mapList-布局数据
  1723. * 返回:true 或者 false
  1724. * 示例:(本JS内部调用)
  1725. * if(checkInstall(this.mapList){}
  1726. */
  1727. export function checkInstall(mapList){
  1728. for(let i=0;i<mapList.length;i++){
  1729. if(mapList[i].type == 1){
  1730. if(!mapList[i].roomType){
  1731. Message({
  1732. message: '请给每一个房间设定参数',
  1733. type: 'error',
  1734. offset: 100
  1735. })
  1736. return false
  1737. }
  1738. }else if(mapList[i].type == 2){
  1739. for(let o=0;o<mapList[i].lightList.length;o++){
  1740. if(!mapList[i].lightList[o].state){
  1741. Message({
  1742. message: '请给每一个灯设定参数',
  1743. type: 'error',
  1744. offset: 100
  1745. })
  1746. return false
  1747. }
  1748. }
  1749. }
  1750. }
  1751. return true
  1752. }