Skip to content

Commit

Permalink
Merge pull request #5229 from dcloudio/fix-mpweixin-getSystemInfo
Browse files Browse the repository at this point in the history
fix(mp-weixin): 修复微信小程序上的 getSystemInfo 警告
  • Loading branch information
GRCmade authored Dec 2, 2024
2 parents 602e22e + b9cccba commit 342b74c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/uni-api/src/service/base/upx2px.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ let baseWidth = 375
let includeWidth = 750

function checkDeviceWidth() {
const { platform, pixelRatio, windowWidth } = getBaseSystemInfo()
const { windowWidth, pixelRatio, platform } =
__PLATFORM__ === 'mp-weixin'
? Object.assign({}, wx.getWindowInfo(), {
platform: wx.getDeviceInfo().platform,
})
: getBaseSystemInfo()

deviceWidth = windowWidth as number
deviceDPR = pixelRatio as number
isIOS = (platform as string) === 'ios'
Expand Down
4 changes: 3 additions & 1 deletion packages/uni-mp-core/src/api/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const getLocale: typeof uni.getLocale = () => {
if (app && app.$vm) {
return app.$vm.$locale
}
return normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
return __PLATFORM__ === 'mp-weixin'
? normalizeLocale(__GLOBAL__.getAppBaseInfo().language) || LOCALE_EN
: normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
}

export const setLocale: typeof uni.setLocale = (locale) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/uni-mp-core/src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ export function initAppLifecycle(

function initLocale(appVm: ComponentPublicInstance) {
const locale = ref<string>(
normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
__PLATFORM__ === 'mp-weixin'
? normalizeLocale(__GLOBAL__.getAppBaseInfo().language) || LOCALE_EN
: normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN
)
Object.defineProperty(appVm, '$locale', {
get() {
Expand Down

0 comments on commit 342b74c

Please sign in to comment.