提交 1560e76c 编写于 作者: Y yurj26

fix(h5): get storage when cookie enabled (question/164775)

上级 b31e20f8
...@@ -45,7 +45,9 @@ export const setLocale = defineSyncApi<typeof uni.setLocale>( ...@@ -45,7 +45,9 @@ export const setLocale = defineSyncApi<typeof uni.setLocale>(
weex.requireModule('plus').setLanguage(locale) weex.requireModule('plus').setLanguage(locale)
} }
if (__PLATFORM__ === 'h5') { if (__PLATFORM__ === 'h5') {
window.localStorage && (localStorage[UNI_STORAGE_LOCALE] = locale) navigator.cookieEnabled &&
window.localStorage &&
(localStorage[UNI_STORAGE_LOCALE] = locale)
} }
// 执行 uni.onLocaleChange // 执行 uni.onLocaleChange
UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale }) UniServiceJSBridge.invokeOnCallback(API_ON_LOCALE_CHANGE, { locale })
......
...@@ -92,7 +92,9 @@ export function useI18n() { ...@@ -92,7 +92,9 @@ export function useI18n() {
if (__NODE_JS__) { if (__NODE_JS__) {
locale = getEnvLocale() as BuiltInLocale locale = getEnvLocale() as BuiltInLocale
} else { } else {
locale = ((window.localStorage && localStorage[UNI_STORAGE_LOCALE]) || locale = ((navigator.cookieEnabled &&
window.localStorage &&
localStorage[UNI_STORAGE_LOCALE]) ||
__uniConfig.locale || __uniConfig.locale ||
navigator.language) as BuiltInLocale navigator.language) as BuiltInLocale
} }
......
const UUID_KEY = '__DC_STAT_UUID' const UUID_KEY = '__DC_STAT_UUID'
const storage = window.localStorage || window.sessionStorage || {} const storage: Record<string, string> =
(navigator.cookieEnabled && (window.localStorage || window.sessionStorage)) ||
{}
let deviceId: string let deviceId: string
export default function () { export default function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册