police.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. -5 <= saL &&
  171. saL < 8 &&
  172. -5 <= saP &&
  173. saP < 8 &&
  174. 25 < saL2 &&
  175. saL2 < 85 &&
  176. -95 < saP2 &&
  177. saP2 < -40 &&
  178. type == 4
  179. ) {
  180. dv.style.left = nl + "px";
  181. dv.style.top = nt + "px";
  182. dv1.style.left = nl + 42 + "px";
  183. dv1.style.top = nt - 73 + "px";
  184. dv3.style.left = nl - 56 + "px";
  185. dv3.style.top = nt + 70 + "px";
  186. }
  187. if (25 < saL2 && saL2 < 85 && -95 < saP2 && saP2 < -40 && type == 4) {
  188. dv3.style.left = nl - 56 + "px";
  189. dv3.style.top = nt + 70 + "px";
  190. }
  191. if (
  192. -70 < stL &&
  193. stL < -15 &&
  194. 45 < stP &&
  195. stP < 100 &&
  196. 25 < spL &&
  197. spL < 85 &&
  198. -95 < spP &&
  199. spP < -40 &&
  200. -5 <= saL &&
  201. saL < 8 &&
  202. -5 <= saP &&
  203. saP < 8 &&
  204. type == 3
  205. ) {
  206. dv.style.left = nl + 56 + "px";
  207. dv.style.top = nt - 70 + "px";
  208. dv1.style.left = nl + 98 + "px";
  209. dv1.style.top = nt - 143 + "px";
  210. dv2.style.left = nl + 56 + "px";
  211. dv2.style.top = nt - 70 + "px";
  212. }
  213. if (
  214. -70 < stL &&
  215. stL < -15 &&
  216. 45 < stP &&
  217. stP < 100 &&
  218. 25 < spL &&
  219. spL < 85 &&
  220. -95 < spP &&
  221. spP < -40 &&
  222. type == 1
  223. ) {
  224. dv1.style.left = nl + 42 + "px";
  225. dv1.style.top = nt - 73 + "px";
  226. dv3.style.left = nl - 56 + "px";
  227. dv3.style.top = nt + 70 + "px";
  228. }
  229. if (
  230. -70 < stL &&
  231. stL < -15 &&
  232. 45 < stP &&
  233. stP < 100 &&
  234. 25 < spL &&
  235. spL < 85 &&
  236. -95 < spP &&
  237. spP < -40 &&
  238. type == 2
  239. ) {
  240. dv.style.left = nl + 42 + "px";
  241. dv.style.top = nt - 53 + "px";
  242. dv3.style.left = nl - 98 + "px";
  243. dv3.style.top = nt + 143 + "px";
  244. }
  245. if (
  246. -70 < stL &&
  247. stL < -15 &&
  248. 45 < stP &&
  249. stP < 100 &&
  250. 25 < spL &&
  251. spL < 85 &&
  252. -95 < spP &&
  253. spP < -40 &&
  254. type == 3
  255. ) {
  256. dv.style.left = nl + 56 + "px";
  257. dv.style.top = nt - 70 + "px";
  258. dv1.style.left = nl + 98 + "px";
  259. dv1.style.top = nt - 143 + "px";
  260. }
  261. if (-70 < stL && stL < -15 && 45 < stP && stP < 100 && type == 1) {
  262. dv1.style.left = nl + 42 + "px";
  263. dv1.style.top = nt - 73 + "px";
  264. }
  265. if (-70 < stL && stL < -15 && 45 < stP && stP < 100 && type == 2) {
  266. dv.style.left = nl - 42 + "px";
  267. dv.style.top = nt + 73 + "px";
  268. }
  269. }
  270. },
  271. },
  272. },
  273. methods: {
  274. go() {
  275. this.$router.push("/blockly");
  276. },
  277. },
  278. };
  279. </script>
  280. <style scoped>
  281. html,
  282. body {
  283. margin: 0;
  284. padding: 0;
  285. width: 100%;
  286. }
  287. .tip {
  288. margin: 25px 0 30px 20px;
  289. width: 419px;
  290. }
  291. .tip > img,
  292. #screan > img,
  293. #tou > img,
  294. #ai > img,
  295. #police > img,
  296. .right > img {
  297. width: 100%;
  298. height: 100%;
  299. user-select: none;
  300. }
  301. .img {
  302. display: flex;
  303. flex-direction: row;
  304. justify-content: flex-end;
  305. margin: auto;
  306. width: 70%;
  307. /* position: relative; */
  308. }
  309. #screan {
  310. width: 130px;
  311. position: absolute;
  312. left: 10%;
  313. top: 50%;
  314. transform: translateY(-50%);
  315. z-index: 4;
  316. }
  317. #ai {
  318. width: 130px;
  319. position: absolute;
  320. top: 50%;
  321. left: 30%;
  322. transform: translateY(-50%);
  323. z-index: 1;
  324. }
  325. #tou {
  326. width: 45px;
  327. position: absolute;
  328. top: 50%;
  329. left: 50%;
  330. transform: translateY(-50%);
  331. z-index: 3;
  332. }
  333. #police {
  334. width: 240px;
  335. position: absolute;
  336. left: 70%;
  337. top: 50%;
  338. transform: translateY(-50%);
  339. z-index: 2;
  340. }
  341. .button {
  342. color: #fff;
  343. background: #8ca1de;
  344. width: 550px;
  345. height: 55px;
  346. font-size: 20px;
  347. text-align: center;
  348. line-height: 55px;
  349. position: absolute;
  350. bottom: 10%;
  351. left: 50%;
  352. transform: translateX(-50%);
  353. user-select: none;
  354. }
  355. .right {
  356. width: 40px;
  357. position: absolute;
  358. left: 55%;
  359. top: 70%;
  360. display: none;
  361. }
  362. .dark {
  363. background: #5b79d0;
  364. cursor: pointer;
  365. }
  366. </style>