common.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { getUrlParam } from '@/utils/utils'
const IS_DEVELOPMENT_ENV = process.env.NODE_ENV === 'development'
const IS_PRODUCTION_ENV = process.env.NODE_ENV === 'production'
/**
* 页面跳转
* @param {string} pathname 路径跳转
* @param {object} queryObj 路径跳转携带参数
*/
export function goToPage (pathname, queryObj = {}) {
let pathSting = ''
if (IS_DEVELOPMENT_ENV) {
pathSting = `/${pathname}`
} else if (IS_PRODUCTION_ENV) {
const path = location.pathname
const prefix = path.slice(0, path.lastIndexOf('/'))
pathSting = `${prefix}/${pathname}.html`
}
const queryString = Object.keys(queryObj)
.reduce((prev, key) => [prev, `${key}=${queryObj[key]}`].join('&'), '')
.slice(1)
location.href = `${location.origin}${pathSting}${queryString ? `?${queryString}` : ''}`
}
/**
* 获取语言
* @returns language
*/
export function getLanguage () {
let language = localStorage.getItem('trtc-tuiPlayer-language') || getUrlParam('lang') || navigator.language || 'zh'
language = language.replace(/_/, '-').toLowerCase()
if (language === 'zh-cn' || language === 'zh') {
language = 'zh'
} else if (language === 'en' || language === 'en-us' || language === 'en-GB') {
language = 'en'
}
return language
}