mirror of
https://github.com/Coldsmiles/infstarweb.git
synced 2026-04-23 02:30:41 +08:00
feat: enhance mobile detection and responsiveness in SponsorPage
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue';
|
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue';
|
||||||
import BaseModal from '../components/base/BaseModal.vue';
|
import BaseModal from '../components/base/BaseModal.vue';
|
||||||
import EmptyState from '../components/base/EmptyState.vue';
|
import EmptyState from '../components/base/EmptyState.vue';
|
||||||
|
|
||||||
@@ -13,8 +13,27 @@ const modalOpen = ref(false);
|
|||||||
const isMobile = ref(false);
|
const isMobile = ref(false);
|
||||||
const qrLoaded = ref(false);
|
const qrLoaded = ref(false);
|
||||||
|
|
||||||
|
function detectMobileSponsorView() {
|
||||||
|
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userAgent = navigator.userAgent || '';
|
||||||
|
const matchesMobileUserAgent = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
|
||||||
|
const matchesMobileViewport = window.matchMedia('(max-width: 767.98px)').matches || window.innerWidth < 768;
|
||||||
|
|
||||||
|
return matchesMobileUserAgent || matchesMobileViewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMobileState() {
|
||||||
|
isMobile.value = detectMobileSponsorView();
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
isMobile.value = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth < 768;
|
updateMobileState();
|
||||||
|
window.addEventListener('resize', updateMobileState);
|
||||||
|
window.addEventListener('orientationchange', updateMobileState);
|
||||||
|
|
||||||
fetch('/data/sponsors.txt')
|
fetch('/data/sponsors.txt')
|
||||||
.then(r => r.text())
|
.then(r => r.text())
|
||||||
.then(text => {
|
.then(text => {
|
||||||
@@ -27,6 +46,20 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('resize', updateMobileState);
|
||||||
|
window.removeEventListener('orientationchange', updateMobileState);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(modalOpen, (open) => {
|
||||||
|
if (open) {
|
||||||
|
updateMobileState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qrLoaded.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
function parseSponsors(text) {
|
function parseSponsors(text) {
|
||||||
if (!text) return [];
|
if (!text) return [];
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user