Skip to content

Commit

Permalink
fix: 修复 window undefined 的情况,导致部署不成功
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed May 7, 2023
1 parent 5e4da0a commit 080c7e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/helpers/detect-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const windowIsDefined = () => {

export const getDevice = (): 'mobile' | 'pc' => {
return windowIsDefined() &&
/Android|webOS|iPhone|iPod|BlackBerry/i.test(window.navigator.userAgent)
/Android|webOS|iPhone|iPod|BlackBerry/i.test(window.navigator?.userAgent)
? 'mobile'
: 'pc';
};
6 changes: 5 additions & 1 deletion src/i18n/language.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { windowIsDefined } from '@/helpers/detect-device';
import { getSearchObj } from '@/helpers/location';

/**
* 获取语言
*/
export function getLanguage(): string {
const query = getSearchObj();
const lang = (query.lang as string) || navigator.language || 'zh-CN';
const lang =
(query.lang as string) ||
(windowIsDefined() ? navigator?.language : 'zh-CN') ||
'zh-CN';
typeof document !== 'undefined' && document.body.setAttribute('lang', lang);
return lang;
}

0 comments on commit 080c7e6

Please sign in to comment.