1 line
3.2 KiB
JSON
1 line
3.2 KiB
JSON
{"ast":null,"code":"import store from \"@/store\";\nexport default {\n data() {\n return {\n timeOutEvent: 0,\n longClick: 0,\n // 手指原始位置\n oldMousePos: {},\n // 元素原始位置\n oldNodePos: {},\n btnType: \"right\"\n };\n },\n computed: {\n Lang() {\n return store.state.config.$lang;\n },\n Type() {\n return store.state.config.$Type;\n }\n },\n methods: {\n touchstart(ev) {\n // 定时器控制长按时间,超过500毫秒开始进行拖拽\n this.timeOutEvent = setTimeout(() => {\n this.longClick = 1;\n }, 500);\n const selectDom = ev.currentTarget;\n const {\n pageX,\n pageY\n } = ev.touches[0]; // 手指位置\n const {\n offsetLeft,\n offsetTop\n } = selectDom; // 元素位置\n // 手指原始位置\n this.oldMousePos = {\n x: pageX,\n y: pageY\n };\n // 元素原始位置\n this.oldNodePos = {\n x: offsetLeft,\n y: offsetTop\n };\n selectDom.style.left = `${offsetLeft}px`;\n selectDom.style.top = `${offsetTop}px`;\n },\n touchMove(ev) {\n // 未达到500毫秒就移动则不触发长按,清空定时器\n clearTimeout(this.timeOutEvent);\n if (this.longClick === 1) {\n const selectDom = ev.currentTarget;\n // x轴偏移量\n const lefts = this.oldMousePos.x - this.oldNodePos.x;\n // y轴偏移量\n const tops = this.oldMousePos.y - this.oldNodePos.y;\n const {\n pageX,\n pageY\n } = ev.touches[0]; // 手指位置\n selectDom.style.left = `${pageX - lefts}px`;\n selectDom.style.top = `${pageY - tops}px`;\n }\n },\n touchEnd(ev) {\n // 清空定时器\n clearTimeout(this.timeOutEvent);\n if (this.longClick === 1) {\n this.longClick = 0;\n const selectDom = ev.currentTarget;\n const {\n clientWidth,\n clientHeight\n } = document.documentElement;\n const {\n offsetLeft,\n offsetTop\n } = selectDom;\n if (offsetTop < -10) {\n selectDom.style.top = \"-10px\";\n } else if (offsetTop + 30 > clientHeight) {\n selectDom.style.top = `${clientHeight - 30}px`;\n }\n if (offsetLeft < -10) {\n selectDom.style.left = \"-10px\";\n } else if (offsetLeft + 30 > clientWidth) {\n selectDom.style.left = `${clientWidth - 30}px`;\n }\n }\n },\n back() {\n // showConfirmDialog({\n // title: \"提示\",\n // message: \"您确认要退出游戏?\"\n // })\n // .then(() => {\n const protocol = document.location.protocol;\n const hostname = document.location.hostname;\n const port = document.location.port;\n let url = \"\";\n if (port) {\n url = `${protocol}//${hostname}:${port}`;\n } else {\n url = `${protocol}//${hostname}`;\n }\n window.location.href = url;\n // })\n // .catch(() => {})\n }\n }\n};","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]} |