横竖屏检测

This commit is contained in:
Andy Leong 2024-01-22 23:51:13 +08:00
parent adfb320fa2
commit 2ab7f2daab
5 changed files with 89 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

View File

@ -81,7 +81,7 @@ onMounted(() => {
</script> </script>
<template> <template>
<div class="IndexPage"> <div class="IndexPage" @touchmove.prevent>
<div class="index-bg"> <div class="index-bg">
<div class="index-clock-box"> <div class="index-clock-box">
<div class="index-clock-h"></div> <div class="index-clock-h"></div>

View File

@ -21,6 +21,8 @@ const page = [
'prize/no-prize.png', 'prize/no-prize.png',
'music-on.png', 'music-on.png',
'music-off.png', 'music-off.png',
'orientation-icon.png',
'share.jpg',
'index/title.png', 'index/title.png',
'index/start-btn.png', 'index/start-btn.png',
'index/rule-btn.png', 'index/rule-btn.png',

View File

@ -19,7 +19,7 @@ import MyPrize from "@/components/MyPrize";
import Draw from "@/components/Draw"; import Draw from "@/components/Draw";
import Result from "@/components/Result"; import Result from "@/components/Result";
import Rule from "@/components/Rule"; import Rule from "@/components/Rule";
import { createBGM, getQueryString } from "@/plugins"; import { createBGM, getQueryString, screenOrientation } from "@/plugins";
import { authorize, getUserInfo } from "@/api"; import { authorize, getUserInfo } from "@/api";
import { Toast } from "vant"; import { Toast } from "vant";
import { useMainStore } from "@/store"; import { useMainStore } from "@/store";
@ -77,7 +77,7 @@ const drawFn = (item) => {
} }
}; };
const showResult = ref(true); const showResult = ref(false);
const resultFn = (item) => { const resultFn = (item) => {
if (item.action == "hide") { if (item.action == "hide") {
showResult.value = false; showResult.value = false;
@ -95,6 +95,9 @@ const ruleFn = (item) => {
}; };
onMounted(() => { onMounted(() => {
fontAdpat(); //
screenOrientation(); //
let code = getQueryString("code"); let code = getQueryString("code");
let url = import.meta.env.VITE_URL; let url = import.meta.env.VITE_URL;
console.log("code:", code); console.log("code:", code);
@ -178,8 +181,6 @@ onMounted(() => {
} else { } else {
showLoad.value = true; showLoad.value = true;
} }
fontAdpat();
}); });
// //
@ -233,4 +234,22 @@ const fontAdpat = () => {
overflow: hidden; overflow: hidden;
margin: 0 auto; margin: 0 auto;
} }
.orientationPop {
@include fixed();
@include flexCen();
background-color: rgba($color: #000000, $alpha: 1);
visibility: hidden;
}
.orientation-icon {
@include box(60px, 60px);
@include bg_pos("orientation-icon.png");
margin-bottom: 20px;
}
.orientation-text {
color: #fff;
font-size: 30px;
margin-top: 10px;
}
</style> </style>

View File

@ -433,7 +433,7 @@ export function mostValue(arr) {
// 海报生成 // 海报生成
export function posterCreate(option, imageArr, textArr, theme,eqcode) { export function posterCreate(option, imageArr, textArr, theme, eqcode) {
let posterUrl = '' let posterUrl = ''
const { width, height } = option const { width, height } = option
Toast.loading({ Toast.loading({
@ -470,7 +470,7 @@ export function posterCreate(option, imageArr, textArr, theme,eqcode) {
imgList.map((item, index) => { imgList.map((item, index) => {
// console.log('item',imageArr[index]); // console.log('item',imageArr[index]);
if (imageArr[index].name != 'eqcode') { if (imageArr[index].name != 'eqcode') {
ctx.drawImage(item, imageArr[index].pos.x, imageArr[index].pos.y, imageArr[index].pos.w, imageArr[index].pos.h); //原生canvas的绘制图片方法直接百度搜索 `js drawImage`查看方法的参数 ctx.drawImage(item, imageArr[index].pos.x, imageArr[index].pos.y, imageArr[index].pos.w, imageArr[index].pos.h); //原生canvas的绘制图片方法直接百度搜索 `js drawImage`查看方法的参数
} }
}) })
@ -519,3 +519,61 @@ export function posterCreate(option, imageArr, textArr, theme,eqcode) {
return posterUrl return posterUrl
} }
// 横竖屏检测
export function screenOrientation() {
const orientationPopNode = createVNode(
'div',
{
class: 'orientationPop',
},
[
createVNode(
'div',
{
class: 'orientation-icon',
},
),
createVNode(
'div',
{
class: 'orientation-text',
},
'为了您的良好体验'
),
createVNode(
'div',
{
class: 'orientation-text',
},
'请将手机竖屏操作'
)
]
)
const orientationIconNode = createVNode(
'div',
{
class: 'orientation-icon',
},
[createVNode('span', {}, '为了您的良好体验')]
)
render(orientationPopNode, document.querySelector('.home'));
window.addEventListener(
"onorientationchange" in window ? "orientationchange" : "resize",
function () {
if (window.orientation === 180 || window.orientation === 0) {
// 竖屏
gsap.to('.orientationPop', { autoAlpha: 0 })
}
if (window.orientation === 90 || window.orientation === -90) {
// 横屏
gsap.to('.orientationPop', { autoAlpha: 1 })
}
},
false
);
}