123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <template>
- <div style="height: 98%;background: #fff;width: 98%;margin: 10px auto;">
- <div class="tip">
- <img src="../assets/img/tips.png" alt="" />
- </div>
- <div class="img">
- <div
- id="screan"
- ref="dv"
- v-drag="{ go, getK, setk, getC, setC, getA, setA, setPan, getPan }"
- >
- <img src="../assets/img/light/screan.png" alt="" />
- </div>
- <div
- id="tou"
- v-drag="{ go, getK, setk, getC, setC, getA, setA, setPan, getPan }"
- >
- <img src="../assets/img/tou1.png" alt="" />
- </div>
- <div
- id="ai"
- v-drag="{ go, getK, setk, getC, setC, getA, setA, setPan, getPan }"
- >
- <img src="../assets/img/ai.png" alt="" />
- </div>
- <div
- id="police"
- v-drag="{ go, getK, setk, getC, setC, getA, setA, setPan, getPan }"
- >
- <img src="../assets/img/policeNew.png" alt="" />
- </div>
- </div>
- <div class="right"><img src="../assets/img/right.png" alt="" /></div>
- <div class="button">进入CocoBlockly编程平台</div>
- <video
- id="musicC"
- :src="require('../assets/music/click.mp3')"
- v-show="false"
- ></video>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- that: this,
- kkk: 0,
- ccc: 0,
- aaa: 0,
- };
- },
- directives: {
- drag: {
- // 指令的定义
- inserted: function (el, binding) {
- // el.drag();
- console.log(el);
- //获取元素
- // var dv = document.getElementById("dv");
- let x = 0;
- let y = 0;
- let l = 0;
- let t = 0;
- let Count = 0;
- let isDown = false;
- var dv = document.getElementById("screan");
- var dv1 = document.getElementById("tou");
- var dv2 = document.getElementById("ai");
- var dv3 = document.getElementById("police");
- var musicC = document.getElementById("musicC");
- //鼠标按下事件
- el.onmousedown = function (e) {
- //获取x坐标和y坐标
- e.preventDefault();
- x = e.clientX;
- y = e.clientY;
- //获取左部和顶部的偏移量
- l = el.offsetLeft;
- t = el.offsetTop;
- //开关打开
- isDown = true;
- //设置样式
- el.style.cursor = "move";
- subiao(el);
- };
- function subiao(cdiv) {
- document.onmousemove = function (e) {
- if (isDown == false) {
- return;
- }
- //获取x和y
- var nx = e.clientX;
- var ny = e.clientY;
- //计算移动后的左偏移量和顶部的偏移量
- var nl = nx - (x - l);
- var nt = ny - (y - t);
- cdiv.style.left = nl + "px";
- cdiv.style.top = nt + "px";
- if (el.id == "screan") {
- binding.value.setPan("screan");
- moveP(nl, nt, 1);
- }
- if (el.id == "tou") {
- binding.value.setPan("tou");
- moveP(nl, nt, 2);
- }
- if (el.id == "ai") {
- binding.value.setPan("ai");
- moveP(nl, nt, 4);
- }
- if (el.id == "police") {
- binding.value.setPan("police");
- moveP(nl, nt, 3);
- }
- };
- }
- //鼠标抬起事件
- el.onmouseup = function (e) {
- //开关关闭
- isDown = false;
- el.style.cursor = "default";
- document.onmousemove = null;
- var nx = e.clientX;
- var ny = e.clientY;
- var nl = nx - (x - l);
- var nt = ny - (y - t);
- if (binding.value.getPan() == "screan") {
- st(nl, nt, 1);
- }
- if (binding.value.getPan() == "tou") {
- st(nl, nt, 2);
- }
- if (binding.value.getPan() == "ai") {
- st(nl, nt, 4);
- }
- if (binding.value.getPan() == "police") {
- st(nl, nt, 3);
- }
- pan();
- };
- function pan() {
- var _panL = dv.offsetLeft;
- var _panT = dv.offsetTop;
- var touL = dv1.offsetLeft;
- var touT = dv1.offsetTop;
- var aiL = dv2.offsetLeft;
- var aiT = dv2.offsetTop;
- var policeL = dv3.offsetLeft;
- var policeT = dv3.offsetTop;
- var stL = _panL - touL;
- var saL = _panL - aiL;
- var spL = _panL - policeL;
- var stP = _panT - touT;
- var saP = _panT - aiT;
- var spP = _panT - policeT;
- var btn = document.getElementsByClassName("button")[0];
- var right = document.getElementsByClassName("right")[0];
- if (
- binding.value.getA() == 1 &&
- binding.value.getC() == 1 &&
- binding.value.getK() == 1
- ) {
- btn.className = "button dark";
- btn.onclick = function () {
- binding.value.go();
- };
- right.style.display = "block";
- right.style.left = policeL + 240 + "px";
- right.style.top = policeT + 100 + "px";
- } else {
- btn.className = "button";
- btn.onclick = null;
- right.style.display = "none";
- }
- }
- function st(nl, nt, type) {
- var _panL = dv.offsetLeft;
- var _panT = dv.offsetTop;
- var touL = dv1.offsetLeft;
- var touT = dv1.offsetTop;
- var policeL = dv3.offsetLeft;
- var policeT = dv3.offsetTop;
- var aiL = dv2.offsetLeft;
- var aiT = dv2.offsetTop;
- var stL = _panL - touL;
- var stP = _panT - touT;
- var spL = policeL - _panL;
- var spP = policeT - _panT;
- var saL = _panL - aiL;
- var saP = _panT - aiT;
- var saL2 = policeL - aiL;
- var saP2 = policeT - aiT;
- if (
- -222 < saL2 &&
- saL2 < 52 &&
- -33 < saP2 &&
- saP2 < 240 &&
- type == 4
- ) {
- dv2.style.left = policeL + 56 + "px";
- dv2.style.top = policeT - 75 + "px";
- binding.value.setA(1);
- playMusic();
- } else if (type == 4) {
- binding.value.setA(0);
- }
- if (-203 < spL && spL < 60 && -41 < spP && spP < 254 && type == 1) {
- dv.style.left = policeL + 51 + "px";
- dv.style.top = policeT - 75 + "px";
- if (binding.value.getK() == 1) {
- dv1.style.left = policeL + 98 + "px";
- dv1.style.top = policeT - 153 + "px";
- }
- binding.value.setC(1);
- playMusic();
- } else if (type == 1) {
- binding.value.setC(0);
- }
- if (-101 < stL && stL < -34 && 68 < stP && stP < 130 && type == 2) {
- dv1.style.left = _panL + 47 + "px";
- dv1.style.top = _panT - 79 + "px";
- binding.value.setk(1);
- playMusic();
- } else if (type == 2) {
- binding.value.setk(0);
- }
- }
- function playMusic() {
- musicC.play();
- }
- function moveP(nl, nt, type) {
- if (binding.value.getK() == 1 && type == 1) {
- dv1.style.left = nl + 47 + "px";
- dv1.style.top = nt - 79 + "px";
- }
- if (binding.value.getC() == 1 && type == 3) {
- dv.style.left = nl + 51 + "px";
- dv.style.top = nt - 75 + "px";
- }
- if (
- binding.value.getC() == 1 &&
- binding.value.getK() == 1 &&
- type == 3
- ) {
- dv.style.left = nl + 51 + "px";
- dv.style.top = nt - 75 + "px";
- dv1.style.left = nl + 98 + "px";
- dv1.style.top = nt - 153 + "px";
- }
- if (binding.value.getA() == 1 && type == 3) {
- dv2.style.left = nl + 56 + "px";
- dv2.style.top = nt - 75 + "px";
- }
- if (
- binding.value.getC() == 1 &&
- binding.value.getA() == 1 &&
- binding.value.getK() == 1 &&
- type == 3
- ) {
- dv.style.left = nl + 51 + "px";
- dv.style.top = nt - 75 + "px";
- dv1.style.left = nl + 98 + "px";
- dv1.style.top = nt - 153 + "px";
- dv2.style.left = nl + 56 + "px";
- dv2.style.top = nt - 75 + "px";
- }
- }
- },
- },
- },
- methods: {
- go() {
- this.$router.push("/blockly");
- },
- setk(value) {
- this.kkk = value;
- },
- getK() {
- return this.kkk;
- },
- setC(value) {
- this.ccc = value;
- },
- getC() {
- return this.ccc;
- },
- setA(value) {
- this.aaa = value;
- },
- getA() {
- return this.aaa;
- },
- setPan(value) {
- this.panThing = value;
- },
- getPan() {
- return this.panThing;
- },
- },
- };
- </script>
- <style scoped>
- html,
- body {
- margin: 0;
- padding: 0;
- width: 100%;
- }
- .tip {
- margin: 25px 0 30px 20px;
- width: 300px;
- }
- .tip>img,
- #screan > img,
- #tou > img,
- #ai > img,
- #police > img,
- .right > img {
- width: 100%;
- height: 100%;
- user-select: none;
- }
- .img {
- display: flex;
- flex-direction: row;
- justify-content: flex-end;
- margin: auto;
- width: 70%;
- /* position: relative; */
- }
- #screan {
- width: 150px;
- position: absolute;
- left: 10%;
- top: 50%;
- transform: translateY(-50%);
- z-index: 5;
- }
- #ai {
- width: 150px;
- position: absolute;
- top: 50%;
- left: 30%;
- transform: translateY(-50%);
- z-index: 3;
- }
- #tou {
- width: 55px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translateY(-50%);
- z-index: 4;
- }
- #police {
- width: 250px;
- position: absolute;
- left: 70%;
- top: 50%;
- transform: translateY(-50%);
- z-index: 2;
- }
- .button {
- color: #fff;
- background: #8ca1de;
- width: 550px;
- height: 55px;
- border-radius: 10px;
- font-size: 20px;
- text-align: center;
- line-height: 55px;
- position: absolute;
- bottom: 10%;
- left: 50%;
- transform: translateX(-50%);
- user-select: none;
- }
- .right {
- width: 40px;
- position: absolute;
- left: 55%;
- top: 70%;
- display: none;
- }
- .dark {
- background: #5b79d0;
- cursor: pointer;
- }
- </style>
|