forked from dcloudio/uni-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
584 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const EPS = 1e-4 | ||
const BASE_DEVICE_WIDTH = 750 | ||
let isIOS = false | ||
let deviceWidth = 0 | ||
let deviceDPR = 0 | ||
|
||
export function checkDeviceWidth () { | ||
const { | ||
platform, | ||
pixelRatio, | ||
windowWidth | ||
} = __GLOBAL__.getSystemInfoSync() // uni=>__GLOBAL__ runtime 编译目标是 uni 对象,内部不允许直接使用 uni | ||
|
||
deviceWidth = windowWidth | ||
deviceDPR = pixelRatio | ||
isIOS = platform === 'ios' | ||
} | ||
|
||
export function upx2px (number, newDeviceWidth) { | ||
if (deviceWidth === 0) { | ||
checkDeviceWidth() | ||
} | ||
|
||
number = Number(number) | ||
if (number === 0) { | ||
return 0 | ||
} | ||
number = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth) | ||
number = Math.floor(number + EPS) | ||
if (number === 0) { | ||
if (deviceDPR === 1 || !isIOS) { | ||
return 1 | ||
} else { | ||
return 0.5 | ||
} | ||
} | ||
return number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.