isBrowser方法调整

This commit is contained in:
tangly1024.com
2023-08-01 12:47:33 +08:00
parent 115b43b429
commit 6eb50b1138
28 changed files with 41 additions and 42 deletions

View File

@@ -91,7 +91,7 @@ export function GlobalContextProvider(props) {
* @param {*} setTheme
*/
const initTheme = () => {
if (isBrowser()) {
if (isBrowser) {
setTimeout(() => {
const elements = document.querySelectorAll('[id^="theme-"]')
if (elements?.length > 1) {

View File

@@ -64,7 +64,7 @@ export function generateLocaleDict(langString) {
* 根据用户当前浏览器语言进行切换
*/
export function initLocale(lang, locale, changeLang, changeLocale) {
if (isBrowser()) {
if (isBrowser) {
const queryLang = getQueryVariable('lang') || loadLangFromCookies() || window.navigator.language
let currentLang = lang
if (queryLang !== lang) {

View File

@@ -1,6 +1,12 @@
// 封装异步加载资源的方法
import { memo } from 'react'
/**
* 判断是否客户端
* @returns {boolean}
*/
export const isBrowser = typeof window !== 'undefined'
/**
* 组件持久化
*/
@@ -58,7 +64,7 @@ export function loadExternalResource(url, type) {
* @returns
*/
export function getQueryVariable(key) {
const query = isBrowser() ? window.location.search.substring(1) : ''
const query = isBrowser ? window.location.search.substring(1) : ''
const vars = query.split('&')
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split('=')
@@ -143,12 +149,6 @@ export function deepClone(obj) {
*/
export const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
/**
* 判断是否客户端
* @returns {boolean}
*/
export const isBrowser = () => typeof window !== 'undefined'
/**
* 获取从第1页到指定页码的文章
* @param pageIndex 第几页
@@ -168,7 +168,7 @@ export const getListByPage = function (list, pageIndex, pageSize) {
*/
export const isMobile = () => {
let isMobile = false
if (!isBrowser()) {
if (!isBrowser) {
return isMobile
}