evacuationLayout.js 63 KB

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