Skip to content

Commit

Permalink
fix style height when rotating + move cookie util to their specific file
Browse files Browse the repository at this point in the history
  • Loading branch information
hamid-gh98 committed May 8, 2023
1 parent 00777e3 commit d137dec
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 80 deletions.
20 changes: 19 additions & 1 deletion web/assets/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#app {
html,
body {
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
overflow: hidden;
}

#app {
height: 100%;
min-height: 100vh;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
overflow: auto;
}

.ant-space {
Expand Down
4 changes: 2 additions & 2 deletions web/assets/js/axios-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

axios.interceptors.request.use(
config => {
(config) => {
if (config.data instanceof FormData) {
config.headers['Content-Type'] = 'multipart/form-data';
} else {
Expand All @@ -12,5 +12,5 @@ axios.interceptors.request.use(
}
return config;
},
error => Promise.reject(error)
(error) => Promise.reject(error),
);
84 changes: 29 additions & 55 deletions web/assets/js/langs.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,63 @@
const supportLangs = [
{
name : "English",
value : "en-US",
icon : "🇺🇸"
name: 'English',
value: 'en-US',
icon: '🇺🇸',
},
{
name : "Farsi",
value : "fa_IR",
icon : "🇮🇷"
name: 'Farsi',
value: 'fa_IR',
icon: '🇮🇷',
},
{
name : "汉语",
value : "zh-Hans",
icon : "🇨🇳"
name: '汉语',
value: 'zh-Hans',
icon: '🇨🇳',
},
{
name : "Russian",
value : "ru_RU",
icon : "🇷🇺"
name: 'Russian',
value: 'ru_RU',
icon: '🇷🇺',
},
]
];

function getLang(){
let lang = getCookie('lang')
function getLang() {
let lang = getCookie('lang');

if (! lang){
if (window.navigator){
if (!lang) {
if (window.navigator) {
lang = window.navigator.language || window.navigator.userLanguage;

if (isSupportLang(lang)){
setCookie('lang' , lang , 150)
}else{
setCookie('lang' , 'en-US' , 150)
if (isSupportLang(lang)) {
setCookie('lang', lang, 150);
} else {
setCookie('lang', 'en-US', 150);
window.location.reload();
}
}else{
setCookie('lang' , 'en-US' , 150)
} else {
setCookie('lang', 'en-US', 150);
window.location.reload();
}
}

return lang;
}

function setLang(lang){

if (!isSupportLang(lang)){
function setLang(lang) {
if (!isSupportLang(lang)) {
lang = 'en-US';
}

setCookie('lang' , lang , 150)
setCookie('lang', lang, 150);
window.location.reload();
}

function isSupportLang(lang){
for (l of supportLangs){
if (l.value === lang){
function isSupportLang(lang) {
for (l of supportLangs) {
if (l.value === lang) {
return true;
}
}

return false;
}



function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
41 changes: 32 additions & 9 deletions web/assets/js/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,37 @@ function toFixed(num, n) {
return Math.round(num * n) / n;
}

function debounce (fn, delay) {
var timeoutID = null
function debounce(fn, delay) {
var timeoutID = null;
return function () {
clearTimeout(timeoutID)
var args = arguments
var that = this
timeoutID = setTimeout(function () {
fn.apply(that, args)
}, delay)
clearTimeout(timeoutID);
var args = arguments;
var that = this;
timeoutID = setTimeout(function () {
fn.apply(that, args);
}, delay);
};
}

function getCookie(cname) {
let name = cname + '=';
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
}
return '';
}

function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
let expires = 'expires=' + d.toUTCString();
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
}
5 changes: 2 additions & 3 deletions web/assets/js/util/date-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ Date.prototype.formatDateTime = function (split = ' ') {
};

class DateUtil {

// 字符串转 Date 对象
static parseDate(str) {
return new Date(str.replace(/-/g, '/'));
}

static formatMillis(millis) {
return moment(millis).format('YYYY-M-D H:m:s')
return moment(millis).format('YYYY-M-D H:m:s');
}

static firstDayOfMonth() {
Expand All @@ -144,4 +143,4 @@ class DateUtil {
date.setMinTime();
return date;
}
}
}
15 changes: 5 additions & 10 deletions web/assets/js/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ class HttpUtil {
}

class PromiseUtil {

static async sleep(timeout) {
await new Promise(resolve => {
setTimeout(resolve, timeout)
});
}

}

const seq = [
Expand All @@ -95,7 +93,6 @@ const shortIdSeq = [
];

class RandomUtil {

static randomIntRange(min, max) {
return parseInt(Math.random() * (max - min) + min, 10);
}
Expand Down Expand Up @@ -153,28 +150,27 @@ class RandomUtil {
static randomText() {
var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
var string = '';
var len = 6 + Math.floor(Math.random() * 5)
for(var ii=0; ii<len; ii++){
var len = 6 + Math.floor(Math.random() * 5);
for (var ii = 0; ii < len; ii++) {
string += chars[Math.floor(Math.random() * chars.length)];
}
return string;
}

static randowShortId() {
let str = '';
str += this.randomShortIdSeq(8)
str += this.randomShortIdSeq(8);
return str;
}
static randomShadowsocksPassword(){

static randomShadowsocksPassword() {
let array = new Uint8Array(32);
window.crypto.getRandomValues(array);
return btoa(String.fromCharCode.apply(null, array));
}
}

class ObjectUtil {

static getPropIgnoreCase(obj, prop) {
for (const name in obj) {
if (!obj.hasOwnProperty(name)) {
Expand Down Expand Up @@ -322,5 +318,4 @@ class ObjectUtil {
}
return true;
}

}

0 comments on commit d137dec

Please sign in to comment.