mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 13:32:24 +00:00
refactor: DeviceUtils
-> MediaQueryMixin
The transition to mixins has been made, as they can update themselves.
This commit is contained in:
parent
cd3760e650
commit
07ac755617
5 changed files with 44 additions and 35 deletions
|
@ -83,7 +83,7 @@ class PromiseUtil {
|
||||||
class RandomUtil {
|
class RandomUtil {
|
||||||
static getSeq({ type = "default", hasNumbers = true, hasLowercase = true, hasUppercase = true } = {}) {
|
static getSeq({ type = "default", hasNumbers = true, hasLowercase = true, hasUppercase = true } = {}) {
|
||||||
let seq = '';
|
let seq = '';
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "hex":
|
case "hex":
|
||||||
seq += "0123456789abcdef";
|
seq += "0123456789abcdef";
|
||||||
|
@ -488,7 +488,7 @@ class ClipboardManager {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const textarea = window.document.createElement('textarea');
|
const textarea = window.document.createElement('textarea');
|
||||||
|
|
||||||
textarea.style.fontSize = '12pt';
|
textarea.style.fontSize = '12pt';
|
||||||
textarea.style.border = '0';
|
textarea.style.border = '0';
|
||||||
textarea.style.padding = '0';
|
textarea.style.padding = '0';
|
||||||
|
@ -498,14 +498,14 @@ class ClipboardManager {
|
||||||
textarea.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`;
|
textarea.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`;
|
||||||
textarea.setAttribute('readonly', '');
|
textarea.setAttribute('readonly', '');
|
||||||
textarea.value = content;
|
textarea.value = content;
|
||||||
|
|
||||||
window.document.body.appendChild(textarea);
|
window.document.body.appendChild(textarea);
|
||||||
|
|
||||||
textarea.select();
|
textarea.select();
|
||||||
window.document.execCommand("copy");
|
window.document.execCommand("copy");
|
||||||
|
|
||||||
window.document.body.removeChild(textarea);
|
window.document.body.removeChild(textarea);
|
||||||
|
|
||||||
resolve(true)
|
resolve(true)
|
||||||
} catch {
|
} catch {
|
||||||
resolve(false)
|
resolve(false)
|
||||||
|
@ -558,7 +558,7 @@ class CPUFormatter {
|
||||||
static cpuSpeedFormat(speed) {
|
static cpuSpeedFormat(speed) {
|
||||||
return speed > 1000 ? (speed / 1000).toFixed(2) + " GHz" : speed.toFixed(2) + " MHz";
|
return speed > 1000 ? (speed / 1000).toFixed(2) + " GHz" : speed.toFixed(2) + " MHz";
|
||||||
}
|
}
|
||||||
|
|
||||||
static cpuCoreFormat(cores) {
|
static cpuCoreFormat(cores) {
|
||||||
return cores === 1 ? "1 Core" : cores + " Cores";
|
return cores === 1 ? "1 Core" : cores + " Cores";
|
||||||
}
|
}
|
||||||
|
@ -579,7 +579,7 @@ class NumberFormatter {
|
||||||
static addZero(num) {
|
static addZero(num) {
|
||||||
return num < 10 ? "0" + num : num;
|
return num < 10 ? "0" + num : num;
|
||||||
}
|
}
|
||||||
|
|
||||||
static toFixed(num, n) {
|
static toFixed(num, n) {
|
||||||
n = Math.pow(10, n);
|
n = Math.pow(10, n);
|
||||||
return Math.floor(num * n) / n;
|
return Math.floor(num * n) / n;
|
||||||
|
@ -610,7 +610,7 @@ class CookieManager {
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static setCookie(cname, cvalue, exdays) {
|
static setCookie(cname, cvalue, exdays) {
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
|
||||||
|
@ -630,7 +630,7 @@ class ColorUtils {
|
||||||
default: return "red";
|
default: return "red";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static clientUsageColor(clientStats, trafficDiff) {
|
static clientUsageColor(clientStats, trafficDiff) {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case !clientStats || clientStats.total == 0: return "#7a316f";
|
case !clientStats || clientStats.total == 0: return "#7a316f";
|
||||||
|
@ -639,7 +639,7 @@ class ColorUtils {
|
||||||
default: return "#cf3c3c";
|
default: return "#cf3c3c";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static userExpiryColor(threshold, client, isDark = false) {
|
static userExpiryColor(threshold, client, isDark = false) {
|
||||||
if (!client.enable) return isDark ? '#2c3950' : '#bcbcbc';
|
if (!client.enable) return isDark ? '#2c3950' : '#bcbcbc';
|
||||||
let now = new Date().getTime(), expiry = client.expiryTime;
|
let now = new Date().getTime(), expiry = client.expiryTime;
|
||||||
|
@ -665,7 +665,7 @@ class URLBuilder {
|
||||||
if (!host || host.length === 0) host = window.location.hostname;
|
if (!host || host.length === 0) host = window.location.hostname;
|
||||||
if (!port || port.length === 0) port = window.location.port;
|
if (!port || port.length === 0) port = window.location.port;
|
||||||
if (isTLS === undefined) isTLS = window.location.protocol === "https:";
|
if (isTLS === undefined) isTLS = window.location.protocol === "https:";
|
||||||
|
|
||||||
const protocol = isTLS ? "https:" : "http:";
|
const protocol = isTLS ? "https:" : "http:";
|
||||||
port = String(port);
|
port = String(port);
|
||||||
if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) {
|
if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) {
|
||||||
|
@ -673,7 +673,7 @@ class URLBuilder {
|
||||||
} else {
|
} else {
|
||||||
port = `:${port}`;
|
port = `:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${protocol}//${host}${port}${base}${path}`;
|
return `${protocol}//${host}${port}${base}${path}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,11 +744,11 @@ class LanguageManager {
|
||||||
|
|
||||||
static getLanguage() {
|
static getLanguage() {
|
||||||
let lang = CookieManager.getCookie("lang");
|
let lang = CookieManager.getCookie("lang");
|
||||||
|
|
||||||
if (!lang) {
|
if (!lang) {
|
||||||
if (window.navigator) {
|
if (window.navigator) {
|
||||||
lang = window.navigator.language || window.navigator.userLanguage;
|
lang = window.navigator.language || window.navigator.userLanguage;
|
||||||
|
|
||||||
if (LanguageManager.isSupportLanguage(lang)) {
|
if (LanguageManager.isSupportLanguage(lang)) {
|
||||||
CookieManager.setCookie("lang", lang, 150);
|
CookieManager.setCookie("lang", lang, 150);
|
||||||
} else {
|
} else {
|
||||||
|
@ -760,30 +760,43 @@ class LanguageManager {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lang;
|
return lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setLanguage(language) {
|
static setLanguage(language) {
|
||||||
if (!LanguageManager.isSupportLanguage(language)) {
|
if (!LanguageManager.isSupportLanguage(language)) {
|
||||||
language = "en-US";
|
language = "en-US";
|
||||||
}
|
}
|
||||||
|
|
||||||
CookieManager.setCookie("lang", language, 150);
|
CookieManager.setCookie("lang", language, 150);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSupportLanguage(language) {
|
static isSupportLanguage(language) {
|
||||||
const languageFilter = LanguageManager.supportedLanguages.filter((lang) => {
|
const languageFilter = LanguageManager.supportedLanguages.filter((lang) => {
|
||||||
return lang.value === language
|
return lang.value === language
|
||||||
})
|
})
|
||||||
|
|
||||||
return languageFilter.length > 0;
|
return languageFilter.length > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
},
|
||||||
}
|
}
|
|
@ -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) {
|
||||||
|
|
|
@ -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"}}') {
|
||||||
|
|
|
@ -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,
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue