GamePortrait/node_modules/.cache/babel-loader/83899e1da2aefc220cec74068051807de42a3f6e596ff1fda6b861dd275b940a.json

1 line
5.2 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{"ast":null,"code":"import store from \"@/store\";\n// 挂载拖拽组件\nimport { createApp } from \"vue\";\nimport floatBtn from \"@/components/floatBtn\";\nconst showfloatBtn = options => {\n // 创建一个节点,并将组件挂载上去\n const mountNode = document.createElement(\"div\");\n document.body.appendChild(mountNode);\n const app = createApp(floatBtn, {\n ...options,\n visible: true,\n remove() {\n app.unmount(mountNode);\n document.body.removeChild(mountNode);\n }\n });\n return app.mount(mountNode);\n};\n\n// rem计算\nconst resizeWin = () => {\n const o = navigator.userAgent;\n const isAndroid = o.indexOf(\"Android\") > -1 || o.indexOf(\"Adr\") > -1; //android终端\n const isiOS = !!o.match(/\\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端\n let t = document,\n e,\n i,\n model;\n if (isAndroid) {\n // e = window.screen.width\n // i = window.screen.height\n e = t.documentElement.clientWidth;\n i = t.documentElement.clientHeight;\n model = \"android\";\n }\n if (isiOS == false && isAndroid == false) {\n e = t.documentElement.clientWidth - 30;\n i = t.documentElement.clientHeight - 30;\n model = \"pc\";\n }\n if (isiOS) {\n e = t.documentElement.clientWidth;\n i = t.documentElement.clientHeight;\n model = \"ios\";\n }\n Horizontal(e, i, model);\n};\n// 竖屏版本:始终使用竖屏布局\nconst Horizontal = (e, i, model) => {\n const portrait = `portrait_${model}`;\n const appDome = document.getElementById(\"app\");\n function hasClass(n, className) {\n return n.className.match(new RegExp(\"(\\\\s|^)\" + className + \"(\\\\s|$)\"));\n }\n function addClass(n, className) {\n hasClass(n, className) || (n.className += \"\" + className);\n }\n document.body.classList.remove(\"landscape_android\");\n document.body.classList.remove(\"portrait_android\");\n document.body.classList.remove(\"landscape_ios\");\n document.body.classList.remove(\"portrait_ios\");\n document.body.classList.remove(\"landscape_pc\");\n document.body.classList.remove(\"portrait_pc\");\n let s = 0;\n const screen = \"portrait\";\n addClass(document.body, portrait);\n if (model == \"ios\") {\n s = e / 16;\n } else {\n s = e / 12;\n }\n appDome.setAttribute(\"style\", `width: ${e}px;height: ${i}px;`);\n isFullScreen(model);\n document.documentElement.style.fontSize = s + \"px\";\n store.commit(\"config/resizeView\", s);\n store.commit(\"config/phoneScreen\", screen);\n store.commit(\"config/phoneModel\", model);\n};\n\n// 函数魔法糖\nconst throttle = (fn, delay, that) => {\n var timer = null;\n return function () {\n var context = that,\n args = arguments;\n clearTimeout(timer);\n timer = setTimeout(function () {\n fn.apply(context, args);\n }, delay);\n };\n};\n\n// 全屏事件\nconst requestFullScreen = () => {\n var element = document.documentElement;\n if (element.requestFullscreen) {\n element.requestFullscreen();\n } else if (element.mozRequestFullScreen) {\n element.mozRequestFullScreen();\n } else if (element.webkitRequestFullscreen) {\n element.webkitRequestFullscreen();\n } else if (element.msRequestFullscreen) {\n element.msRequestFullscreen();\n }\n store.commit(\"config/checkFullscreen\", true);\n};\n//退出全屏\nconst exitFullscreen = () => {\n if (document.exitFullScreen) {\n document.requestFullscreen();\n } else if (document.mozCancelFullScreen) {\n document.mozCancelFullScreen();\n } else if (document.webkitExitFullscreen) {\n document.webkitExitFullscreen();\n } else if (document.msExitFullscreen) {\n document.msExitFullscreen();\n }\n store.commit(\"config/checkFullscreen\", false);\n};\nfunction isFullScreen(model) {\n if (model == \"ios\" || model == \"pc\") {\n store.commit(\"config/checkFullscreen\", true);\n } else {\n if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {\n store.commit(\"config/checkFullscreen\", true);\n } else {\n store.commit(\"config/checkFullscreen\", false);\n }\n }\n}\nwindow.onresize = throttle(resizeWin, 100, this);\nresizeWin();\nfunction setupDocumentEvent() {\n // 禁止 ios 缩放屏幕\n document.addEventListener(\"gesturestart\", function (event) {\n event.preventDefault();\n });\n\n // 禁止移动端IOS双击页面变大\n let touchTime = 0;\n document.addEventListener(\"touchstart\", function (event) {\n if (event.touches.length > 1) {\n event.preventDefault();\n }\n });\n document.addEventListener(\"touchend\", function (event) {\n //记录当前点击的时间与下一次时间的间隔\n const nowTime = new Date();\n if (nowTime.getTime() - touchTime <= 300) {\n event.preventDefault();\n }\n touchTime = nowTime.getTime();\n }, false);\n}\nsetTimeout(() => {\n setupDocumentEvent();\n}, 2000);\n\n// document.documentElement.addEventListener(\n// \"touchstart\",\n// function (event) {\n// if (event.touches.length > 1) {\n// event.preventDefault()\n// }\n// },\n// false\n// )\n\nexport { resizeWin, throttle, requestFullScreen, exitFullscreen, showfloatBtn };","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}