mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-15 23:16:48 +00:00
封装isBroswer()
This commit is contained in:
@@ -2,7 +2,7 @@ import zhCN from './lang/zh-CN'
|
||||
import enUS from './lang/en-US'
|
||||
import zhHK from './lang/zh-HK'
|
||||
import zhTW from './lang/zh-TW'
|
||||
import { mergeDeep } from './utils'
|
||||
import { isBrowser, mergeDeep } from './utils'
|
||||
const lang = {
|
||||
'en-US': enUS,
|
||||
'zh-CN': zhCN,
|
||||
@@ -45,7 +45,7 @@ export function generateLocaleDict (langString) {
|
||||
* 根据用户当前浏览器语言进行切换
|
||||
*/
|
||||
export function initLocale (locale, changeLocale) {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (isBrowser()) {
|
||||
const targetLocale = generateLocaleDict(window.navigator.language)
|
||||
if (JSON.stringify(locale) !== JSON.stringify(targetLocale)) {
|
||||
changeLocale(targetLocale)
|
||||
|
||||
@@ -38,6 +38,7 @@ async function getPageWithRetry(id, from, retryAttempts = 3) {
|
||||
console.info('[响应成功]:', `from:${from}`, `id:${id}`)
|
||||
return pageData
|
||||
} catch (e) {
|
||||
console.warn('[响应异常]:', e)
|
||||
await delay(1000)
|
||||
const cacheKey = 'page_block_' + id
|
||||
const pageBlock = await getDataFromCache(cacheKey)
|
||||
|
||||
@@ -32,7 +32,7 @@ export function loadExternalResource(url, type) {
|
||||
* @returns
|
||||
*/
|
||||
export function getQueryVariable(variable) {
|
||||
const query = typeof window !== 'undefined' ? 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('=')
|
||||
@@ -99,3 +99,9 @@ export function deepClone(obj) {
|
||||
* @returns
|
||||
*/
|
||||
export const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
/**
|
||||
* 判断是否客户端
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const isBrowser = () => typeof window !== 'undefined'
|
||||
|
||||
Reference in New Issue
Block a user