police.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div>
  3. <div class="tip">
  4. <img src="../assets/img/tips.png" alt="" />
  5. </div>
  6. <div class="img">
  7. <div id="screan" ref="dv" v-drag="go">
  8. <img src="../assets/img/screan.png" alt="" />
  9. </div>
  10. <div id="tou" ref="dv1" v-drag="go">
  11. <img src="../assets/img/tou.png" alt="" />
  12. </div>
  13. <div id="ai" ref="dv2" v-drag="go">
  14. <img src="../assets/img/ai.png" alt="" />
  15. </div>
  16. <div id="police" ref="dv2" v-drag="go">
  17. <img src="../assets/img/police.png" alt="" />
  18. </div>
  19. </div>
  20. <div class="right"><img src="../assets/img/right.png" alt="" /></div>
  21. <div class="button">进入CocoBlockly编程平台</div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. that: this,
  29. };
  30. },
  31. directives: {
  32. drag: {
  33. // 指令的定义
  34. inserted: function (el, binding) {
  35. // el.drag();
  36. console.log(el);
  37. //获取元素
  38. // var dv = document.getElementById("dv");
  39. let x = 0;
  40. let y = 0;
  41. let l = 0;
  42. let t = 0;
  43. let isDown = false;
  44. var dv = document.getElementById("screan");
  45. var dv1 = document.getElementById("tou");
  46. var dv2 = document.getElementById("ai");
  47. var dv3 = document.getElementById("police");
  48. //鼠标按下事件
  49. el.onmousedown = function (e) {
  50. //获取x坐标和y坐标
  51. e.preventDefault();
  52. x = e.clientX;
  53. y = e.clientY;
  54. //获取左部和顶部的偏移量
  55. l = el.offsetLeft;
  56. t = el.offsetTop;
  57. //开关打开
  58. isDown = true;
  59. //设置样式
  60. el.style.cursor = "move";
  61. subiao(el);
  62. };
  63. function subiao(cdiv) {
  64. document.onmousemove = function (e) {
  65. if (isDown == false) {
  66. return;
  67. }
  68. //获取x和y
  69. var nx = e.clientX;
  70. var ny = e.clientY;
  71. //计算移动后的左偏移量和顶部的偏移量
  72. var nl = nx - (x - l);
  73. var nt = ny - (y - t);
  74. cdiv.style.left = nl + "px";
  75. cdiv.style.top = nt + "px";
  76. // cdiv.style.left = e.clientX + "px";
  77. // cdiv.style.top = e.clientY + "px";
  78. if (el.id == "screan") {
  79. st(nl, nt, 1);
  80. }
  81. if (el.id == "tou") {
  82. st(nl, nt, 2);
  83. }
  84. if (el.id == "ai") {
  85. st(nl, nt, 4);
  86. }
  87. if (el.id == "police") {
  88. st(nl, nt, 3);
  89. }
  90. pan();
  91. };
  92. }
  93. //鼠标抬起事件
  94. el.onmouseup = function () {
  95. //开关关闭
  96. isDown = false;
  97. el.style.cursor = "default";
  98. document.onmousemove = null;
  99. };
  100. function pan() {
  101. var _panL = dv.offsetLeft;
  102. var _panT = dv.offsetTop;
  103. var touL = dv1.offsetLeft;
  104. var touT = dv1.offsetTop;
  105. var aiL = dv2.offsetLeft;
  106. var aiT = dv2.offsetTop;
  107. var policeL = dv3.offsetLeft;
  108. var policeT = dv3.offsetTop;
  109. var stL = _panL - touL;
  110. var saL = _panL - aiL;
  111. var spL = _panL - policeL;
  112. var stP = _panT - touT;
  113. var saP = _panT - aiT;
  114. var spP = _panT - policeT;
  115. var btn = document.getElementsByClassName("button")[0];
  116. var right = document.getElementsByClassName("right")[0];
  117. if (
  118. -50 < stL &&
  119. stL < -35 &&
  120. 68 < stP &&
  121. stP < 80 &&
  122. -5 <= saL &&
  123. saL < 8 &&
  124. -5 <= saP &&
  125. saP < 8 &&
  126. 47 < spL &&
  127. spL < 65 &&
  128. -75 < spP &&
  129. spP < -62
  130. ) {
  131. btn.className = "button dark";
  132. btn.onclick = function () {
  133. binding.value();
  134. };
  135. right.style.display = "block";
  136. right.style.left = policeL + 240 + "px";
  137. right.style.top = policeT + "px";
  138. } else {
  139. btn.className = "button";
  140. btn.onclick = null;
  141. right.style.display = "none";
  142. }
  143. }
  144. function st(nl, nt, type) {
  145. var _panL = dv.offsetLeft;
  146. var _panT = dv.offsetTop;
  147. var touL = dv1.offsetLeft;
  148. var touT = dv1.offsetTop;
  149. var policeL = dv3.offsetLeft;
  150. var policeT = dv3.offsetTop;
  151. var aiL = dv2.offsetLeft;
  152. var aiT = dv2.offsetTop;
  153. var stL = _panL - touL;
  154. var stP = _panT - touT;
  155. var spL = _panL - policeL;
  156. var spP = _panT - policeT;
  157. var saL = _panL - aiL;
  158. var saP = _panT - aiT;
  159. var saL2 = aiL - policeL;
  160. var saP2 = aiT - policeT;
  161. if (
  162. -70 < stL &&
  163. stL < -15 &&
  164. 45 < stP &&
  165. stP < 100 &&
  166. 25 < spL &&
  167. spL < 85 &&
  168. -95 < spP &&
  169. spP < -40 &&
  170. 25 < saL2 &&
  171. saL2 < 85 &&
  172. -95 < saP2 &&
  173. saP2 < -40 &&
  174. type == 2
  175. ) {
  176. dv.style.left = nl - 42 + "px";
  177. dv.style.top = nt + 73 + "px";
  178. dv2.style.left = nl - 42 + "px";
  179. dv2.style.top = nt + 73 + "px";
  180. dv3.style.left = nl - 98 + "px";
  181. dv3.style.top = nt + 143 + "px";
  182. }
  183. if (
  184. -70 < stL &&
  185. stL < -15 &&
  186. 45 < stP &&
  187. stP < 100 &&
  188. 25 < spL &&
  189. spL < 85 &&
  190. -95 < spP &&
  191. spP < -40 &&
  192. 25 < saL2 &&
  193. saL2 < 85 &&
  194. -95 < saP2 &&
  195. saP2 < -40 &&
  196. type == 1
  197. ) {
  198. dv1.style.left = nl + 42 + "px";
  199. dv1.style.top = nt - 73 + "px";
  200. dv2.style.left = nl + "px";
  201. dv2.style.top = nt + "px";
  202. dv3.style.left = nl - 56 + "px";
  203. dv3.style.top = nt + 70 + "px";
  204. }
  205. if (
  206. -70 < stL &&
  207. stL < -15 &&
  208. 45 < stP &&
  209. stP < 100 &&
  210. 25 < spL &&
  211. spL < 85 &&
  212. -95 < spP &&
  213. spP < -40 &&
  214. -5 <= saL &&
  215. saL < 8 &&
  216. -5 <= saP &&
  217. saP < 8 &&
  218. 25 < saL2 &&
  219. saL2 < 85 &&
  220. -95 < saP2 &&
  221. saP2 < -40 &&
  222. type == 4
  223. ) {
  224. dv.style.left = nl + "px";
  225. dv.style.top = nt + "px";
  226. dv1.style.left = nl + 42 + "px";
  227. dv1.style.top = nt - 73 + "px";
  228. dv3.style.left = nl - 56 + "px";
  229. dv3.style.top = nt + 70 + "px";
  230. }
  231. if (25 < saL2 && saL2 < 85 && -95 < saP2 && saP2 < -40 && type == 4) {
  232. dv3.style.left = nl - 56 + "px";
  233. dv3.style.top = nt + 70 + "px";
  234. }
  235. if (
  236. -70 < stL &&
  237. stL < -15 &&
  238. 45 < stP &&
  239. stP < 100 &&
  240. 25 < spL &&
  241. spL < 85 &&
  242. -95 < spP &&
  243. spP < -40 &&
  244. -5 <= saL &&
  245. saL < 8 &&
  246. -5 <= saP &&
  247. saP < 8 &&
  248. type == 3
  249. ) {
  250. dv.style.left = nl + 56 + "px";
  251. dv.style.top = nt - 70 + "px";
  252. dv1.style.left = nl + 98 + "px";
  253. dv1.style.top = nt - 143 + "px";
  254. dv2.style.left = nl + 56 + "px";
  255. dv2.style.top = nt - 70 + "px";
  256. }
  257. if (
  258. -70 < stL &&
  259. stL < -15 &&
  260. 45 < stP &&
  261. stP < 100 &&
  262. 25 < spL &&
  263. spL < 85 &&
  264. -95 < spP &&
  265. spP < -40 &&
  266. type == 1
  267. ) {
  268. dv1.style.left = nl + 42 + "px";
  269. dv1.style.top = nt - 73 + "px";
  270. dv3.style.left = nl - 56 + "px";
  271. dv3.style.top = nt + 70 + "px";
  272. }
  273. if (
  274. -70 < stL &&
  275. stL < -15 &&
  276. 45 < stP &&
  277. stP < 100 &&
  278. 25 < spL &&
  279. spL < 85 &&
  280. -95 < spP &&
  281. spP < -40 &&
  282. type == 2
  283. ) {
  284. dv.style.left = nl - 42 + "px";
  285. dv.style.top = nt + 73 + "px";
  286. dv3.style.left = nl - 98 + "px";
  287. dv3.style.top = nt + 143 + "px";
  288. }
  289. if (
  290. -70 < stL &&
  291. stL < -15 &&
  292. 45 < stP &&
  293. stP < 100 &&
  294. 25 < spL &&
  295. spL < 85 &&
  296. -95 < spP &&
  297. spP < -40 &&
  298. type == 3
  299. ) {
  300. dv.style.left = nl + 56 + "px";
  301. dv.style.top = nt - 70 + "px";
  302. dv1.style.left = nl + 98 + "px";
  303. dv1.style.top = nt - 143 + "px";
  304. }
  305. if (-70 < stL && stL < -15 && 45 < stP && stP < 100 && type == 1) {
  306. dv1.style.left = nl + 42 + "px";
  307. dv1.style.top = nt - 73 + "px";
  308. }
  309. if (-70 < stL && stL < -15 && 45 < stP && stP < 100 && type == 2) {
  310. dv.style.left = nl - 42 + "px";
  311. dv.style.top = nt + 73 + "px";
  312. }
  313. }
  314. },
  315. },
  316. },
  317. methods: {
  318. go() {
  319. this.$router.push("/blockly");
  320. },
  321. },
  322. };
  323. </script>
  324. <style scoped>
  325. html,
  326. body {
  327. margin: 0;
  328. padding: 0;
  329. width: 100%;
  330. }
  331. .tip {
  332. margin: 25px 0 30px 20px;
  333. width: 419px;
  334. }
  335. .tip > img,
  336. #screan > img,
  337. #tou > img,
  338. #ai > img,
  339. #police > img,
  340. .right > img {
  341. width: 100%;
  342. height: 100%;
  343. user-select: none;
  344. }
  345. .img {
  346. display: flex;
  347. flex-direction: row;
  348. justify-content: flex-end;
  349. margin: auto;
  350. width: 70%;
  351. /* position: relative; */
  352. }
  353. #screan {
  354. width: 130px;
  355. position: absolute;
  356. left: 10%;
  357. top: 50%;
  358. transform: translateY(-50%);
  359. z-index: 4;
  360. }
  361. #ai {
  362. width: 130px;
  363. position: absolute;
  364. top: 50%;
  365. left: 30%;
  366. transform: translateY(-50%);
  367. z-index: 1;
  368. }
  369. #tou {
  370. width: 45px;
  371. position: absolute;
  372. top: 50%;
  373. left: 50%;
  374. transform: translateY(-50%);
  375. z-index: 3;
  376. }
  377. #police {
  378. width: 240px;
  379. position: absolute;
  380. left: 70%;
  381. top: 50%;
  382. transform: translateY(-50%);
  383. z-index: 2;
  384. }
  385. .button {
  386. color: #fff;
  387. background: #8ca1de;
  388. width: 550px;
  389. height: 55px;
  390. font-size: 20px;
  391. text-align: center;
  392. line-height: 55px;
  393. position: absolute;
  394. bottom: 10%;
  395. left: 50%;
  396. transform: translateX(-50%);
  397. user-select: none;
  398. }
  399. .right {
  400. width: 40px;
  401. position: absolute;
  402. left: 55%;
  403. top: 70%;
  404. display: none;
  405. }
  406. .dark {
  407. background: #5b79d0;
  408. cursor: pointer;
  409. }
  410. </style>