refactor: DeviceUtils -> MediaQueryMixin

The transition to mixins has been made, as they can update themselves.
This commit is contained in:
Shishkevich D. 2025-04-03 11:02:58 +00:00
parent cd3760e650
commit 07ac755617
5 changed files with 44 additions and 35 deletions

View file

@ -782,8 +782,21 @@ class LanguageManager {
} }
} }
class DeviceUtils { const MediaQueryMixin = {
static isMobile() { data() {
return window.innerWidth <= 768; return {
} isMobile: window.innerWidth <= 768,
};
},
methods: {
updateDeviceType() {
this.isMobile = window.innerWidth <= 768;
},
},
mounted() {
window.addEventListener('resize', this.updateDeviceType);
},
beforeDestroy() {
window.removeEventListener('resize', this.updateDeviceType);
},
} }

View file

@ -678,6 +678,7 @@
const app = new Vue({ const app = new Vue({
delimiters: ['[[', ']]'], delimiters: ['[[', ']]'],
el: '#app', el: '#app',
mixins: [MediaQueryMixin],
data: { data: {
themeSwitcher, themeSwitcher,
persianDatepicker, persianDatepicker,
@ -709,7 +710,6 @@
showAlert: false, showAlert: false,
ipLimitEnable: false, ipLimitEnable: false,
pageSize: 50, pageSize: 50,
isMobile: DeviceUtils.isMobile(),
}, },
methods: { methods: {
loading(spinning = true) { loading(spinning = true) {
@ -1471,9 +1471,6 @@
return p; return p;
} }
return false return false
},
onResize() {
this.isMobile = DeviceUtils.isMobile();
} }
}, },
watch: { watch: {
@ -1485,8 +1482,6 @@
if (window.location.protocol !== "https:") { if (window.location.protocol !== "https:") {
this.showAlert = true; this.showAlert = true;
} }
window.addEventListener('resize', this.onResize);
this.onResize();
this.loading(); this.loading();
this.getDefaultSettings(); this.getDefaultSettings();
if (this.isRefreshEnabled) { if (this.isRefreshEnabled) {

View file

@ -596,6 +596,7 @@
const app = new Vue({ const app = new Vue({
delimiters: ['[[', ']]'], delimiters: ['[[', ']]'],
el: '#app', el: '#app',
mixins: [MediaQueryMixin],
data: { data: {
themeSwitcher, themeSwitcher,
status: new Status(), status: new Status(),
@ -605,8 +606,7 @@
spinning: false, spinning: false,
loadingTip: '{{ i18n "loading"}}', loadingTip: '{{ i18n "loading"}}',
showAlert: false, showAlert: false,
showIp: false, showIp: false
isMobile: DeviceUtils.isMobile()
}, },
methods: { methods: {
loading(spinning, tip = '{{ i18n "loading"}}') { loading(spinning, tip = '{{ i18n "loading"}}') {

View file

@ -1,6 +1,6 @@
{{define "modals/qrcodeModal"}} {{define "modals/qrcodeModal"}}
<a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title" <a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
:dialog-style="DeviceUtils.isMobile() ? { top: '18px' } : {}" :dialog-style="isMobile ? { top: '18px' } : {}"
:closable="true" :closable="true"
:class="themeSwitcher.currentTheme" :class="themeSwitcher.currentTheme"
:footer="null" width="fit-content"> :footer="null" width="fit-content">
@ -73,6 +73,7 @@
const qrModalApp = new Vue({ const qrModalApp = new Vue({
delimiters: ['[[', ']]'], delimiters: ['[[', ']]'],
el: '#qrcode-modal', el: '#qrcode-modal',
mixins: [MediaQueryMixin],
data: { data: {
qrModal: qrModal, qrModal: qrModal,
}, },

View file

@ -192,6 +192,7 @@
const app = new Vue({ const app = new Vue({
delimiters: ['[[', ']]'], delimiters: ['[[', ']]'],
mixins: [MediaQueryMixin],
el: '#app', el: '#app',
data: { data: {
themeSwitcher, themeSwitcher,
@ -205,7 +206,6 @@
refreshing: false, refreshing: false,
restartResult: '', restartResult: '',
showAlert: false, showAlert: false,
isMobile: DeviceUtils.isMobile(),
advSettings: 'xraySetting', advSettings: 'xraySetting',
obsSettings: '', obsSettings: '',
cm: null, cm: null,