police.vue 8.4 KB

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