Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
a1c6e0ed
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a1c6e0ed
编写于
5月 27, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(h5): useRem
上级
150e4bc5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
96 addition
and
2 deletion
+96
-2
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+4
-0
packages/uni-api/src/service/base/upx2px.ts
packages/uni-api/src/service/base/upx2px.ts
+12
-1
packages/uni-core/src/view/plugin/index.ts
packages/uni-core/src/view/plugin/index.ts
+2
-0
packages/uni-core/src/view/plugin/rem.ts
packages/uni-core/src/view/plugin/rem.ts
+38
-0
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+36
-1
packages/uni-h5/style/framework/base.css
packages/uni-h5/style/framework/base.css
+1
-0
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+1
-0
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+1
-0
packages/uni-shared/src/dom/style.ts
packages/uni-shared/src/dom/style.ts
+1
-0
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
a1c6e0ed
...
@@ -34,6 +34,10 @@ declare namespace UniApp {
...
@@ -34,6 +34,10 @@ declare namespace UniApp {
globalStyle
:
{
globalStyle
:
{
navigationBar
:
PageNavigationBar
navigationBar
:
PageNavigationBar
refreshOptions
?:
PageRefreshOptions
refreshOptions
?:
PageRefreshOptions
maxWidth
?:
number
rpxCalcMaxDeviceWidth
?:
number
rpxCalcBaseDeviceWidth
?:
number
// rpxCalcIncludeWidth?: number
}
}
topWindow
?:
LayoutWindowOptions
topWindow
?:
LayoutWindowOptions
leftWindow
?:
LayoutWindowOptions
leftWindow
?:
LayoutWindowOptions
...
...
packages/uni-api/src/service/base/upx2px.ts
浏览文件 @
a1c6e0ed
...
@@ -19,6 +19,11 @@ function checkDeviceWidth() {
...
@@ -19,6 +19,11 @@ function checkDeviceWidth() {
isIOS
=
platform
===
'
ios
'
isIOS
=
platform
===
'
ios
'
}
}
function
checkValue
(
value
:
unknown
,
defaultValue
:
number
)
{
const
newValue
=
Number
(
value
)
as
number
return
isNaN
(
newValue
)
?
defaultValue
:
newValue
}
export
const
upx2px
=
defineSyncApi
<
API_TYPE_UPX2PX
>
(
export
const
upx2px
=
defineSyncApi
<
API_TYPE_UPX2PX
>
(
API_UPX2PX
,
API_UPX2PX
,
(
number
,
newDeviceWidth
?:
number
)
=>
{
(
number
,
newDeviceWidth
?:
number
)
=>
{
...
@@ -34,7 +39,13 @@ export const upx2px = defineSyncApi<API_TYPE_UPX2PX>(
...
@@ -34,7 +39,13 @@ export const upx2px = defineSyncApi<API_TYPE_UPX2PX>(
if
(
number
===
0
)
{
if
(
number
===
0
)
{
return
0
return
0
}
}
let
result
=
(
number
/
BASE_DEVICE_WIDTH
)
*
(
newDeviceWidth
||
deviceWidth
)
const
config
=
__uniConfig
.
globalStyle
||
{}
// ignore rpxCalcIncludeWidth
const
maxWidth
=
checkValue
(
config
.
rpxCalcMaxDeviceWidth
,
960
)
const
baseWidth
=
checkValue
(
config
.
rpxCalcBaseDeviceWidth
,
375
)
let
width
=
newDeviceWidth
||
deviceWidth
width
=
width
<=
maxWidth
?
width
:
baseWidth
let
result
=
(
number
/
BASE_DEVICE_WIDTH
)
*
width
if
(
result
<
0
)
{
if
(
result
<
0
)
{
result
=
-
result
result
=
-
result
}
}
...
...
packages/uni-core/src/view/plugin/index.ts
浏览文件 @
a1c6e0ed
...
@@ -3,11 +3,13 @@ import { App } from 'vue'
...
@@ -3,11 +3,13 @@ import { App } from 'vue'
import
{
initLongPress
}
from
'
./longPress
'
import
{
initLongPress
}
from
'
./longPress
'
import
{
initAppConfig
}
from
'
./appConfig
'
import
{
initAppConfig
}
from
'
./appConfig
'
import
{
initCustomDataset
}
from
'
@dcloudio/uni-shared
'
import
{
initCustomDataset
}
from
'
@dcloudio/uni-shared
'
import
{
useRem
}
from
'
./rem
'
export
function
initView
(
app
:
App
)
{
export
function
initView
(
app
:
App
)
{
if
(
__NODE_JS__
)
{
if
(
__NODE_JS__
)
{
return
return
}
}
useRem
()
initCustomDataset
()
initCustomDataset
()
if
(
__UNI_FEATURE_LONGPRESS__
)
{
if
(
__UNI_FEATURE_LONGPRESS__
)
{
initLongPress
()
initLongPress
()
...
...
packages/uni-core/src/view/plugin/rem.ts
0 → 100644
浏览文件 @
a1c6e0ed
function
checkValue
(
value
:
unknown
,
defaultValue
:
number
)
{
const
newValue
=
Number
(
value
)
as
number
return
isNaN
(
newValue
)
?
defaultValue
:
newValue
}
function
getWindowWidth
()
{
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
'
number
'
const
landscape
=
screenFix
&&
Math
.
abs
(
window
.
orientation
as
number
)
===
90
var
screenWidth
=
screenFix
?
Math
[
landscape
?
'
max
'
:
'
min
'
](
screen
.
width
,
screen
.
height
)
:
screen
.
width
var
windowWidth
=
Math
.
min
(
window
.
innerWidth
,
document
.
documentElement
.
clientWidth
,
screenWidth
)
||
screenWidth
return
windowWidth
}
export
function
useRem
()
{
// TODO 与 upx2px 合并抽离逻辑到 shared,区分 service、view
function
updateRem
()
{
const
config
=
__uniConfig
.
globalStyle
||
{}
// ignore: rpxCalcIncludeWidth
const
maxWidth
=
checkValue
(
config
.
rpxCalcMaxDeviceWidth
,
960
)
const
baseWidth
=
checkValue
(
config
.
rpxCalcBaseDeviceWidth
,
375
)
let
width
=
getWindowWidth
()
width
=
width
<=
maxWidth
?
width
:
baseWidth
document
.
documentElement
.
style
.
fontSize
=
width
/
23.4375
+
'
px
'
}
updateRem
()
document
.
addEventListener
(
'
DOMContentLoaded
'
,
updateRem
)
window
.
addEventListener
(
'
load
'
,
updateRem
)
window
.
addEventListener
(
'
resize
'
,
updateRem
)
}
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
a1c6e0ed
...
@@ -967,7 +967,33 @@ function initAppConfig$1(appConfig) {
...
@@ -967,7 +967,33 @@ function initAppConfig$1(appConfig) {
globalProperties.$gcd = getComponentDescriptor;
globalProperties.$gcd = getComponentDescriptor;
}
}
}
}
function checkValue$1(value, defaultValue) {
const newValue = Number(value);
return isNaN(newValue) ? defaultValue : newValue;
}
function getWindowWidth$1() {
const screenFix = /^Apple/.test(navigator.vendor) && typeof window.orientation === "number";
const landscape = screenFix && Math.abs(window.orientation) === 90;
var screenWidth = screenFix ? Math[landscape ? "max" : "min"](screen.width, screen.height) : screen.width;
var windowWidth = Math.min(window.innerWidth, document.documentElement.clientWidth, screenWidth) || screenWidth;
return windowWidth;
}
function useRem() {
function updateRem() {
const config = __uniConfig.globalStyle || {};
const maxWidth = checkValue$1(config.rpxCalcMaxDeviceWidth, 960);
const baseWidth = checkValue$1(config.rpxCalcBaseDeviceWidth, 375);
let width = getWindowWidth$1();
width = width <= maxWidth ? width : baseWidth;
document.documentElement.style.fontSize = width / 23.4375 + "px";
}
updateRem();
document.addEventListener("DOMContentLoaded", updateRem);
window.addEventListener("load", updateRem);
window.addEventListener("resize", updateRem);
}
function initView(app) {
function initView(app) {
useRem();
initCustomDataset();
initCustomDataset();
if (__UNI_FEATURE_LONGPRESS__) {
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress();
initLongPress();
...
@@ -9881,6 +9907,10 @@ function checkDeviceWidth() {
...
@@ -9881,6 +9907,10 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio2;
deviceDPR = pixelRatio2;
isIOS = platform === "ios";
isIOS = platform === "ios";
}
}
function checkValue(value, defaultValue) {
const newValue = Number(value);
return isNaN(newValue) ? defaultValue : newValue;
}
const upx2px = /* @__PURE__ */ defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
const upx2px = /* @__PURE__ */ defineSyncApi(API_UPX2PX, (number, newDeviceWidth) => {
if (deviceWidth === 0) {
if (deviceWidth === 0) {
checkDeviceWidth();
checkDeviceWidth();
...
@@ -9889,7 +9919,12 @@ const upx2px = /* @__PURE__ */ defineSyncApi(API_UPX2PX, (number, newDeviceWidth
...
@@ -9889,7 +9919,12 @@ const upx2px = /* @__PURE__ */ defineSyncApi(API_UPX2PX, (number, newDeviceWidth
if (number === 0) {
if (number === 0) {
return 0;
return 0;
}
}
let result = number / BASE_DEVICE_WIDTH * (newDeviceWidth || deviceWidth);
const config = __uniConfig.globalStyle || {};
const maxWidth = checkValue(config.rpxCalcMaxDeviceWidth, 960);
const baseWidth = checkValue(config.rpxCalcBaseDeviceWidth, 375);
let width = newDeviceWidth || deviceWidth;
width = width <= maxWidth ? width : baseWidth;
let result = number / BASE_DEVICE_WIDTH * width;
if (result < 0) {
if (result < 0) {
result = -result;
result = -result;
}
}
...
...
packages/uni-h5/style/framework/base.css
浏览文件 @
a1c6e0ed
...
@@ -13,6 +13,7 @@ body {
...
@@ -13,6 +13,7 @@ body {
body
{
body
{
overflow-x
:
hidden
;
overflow-x
:
hidden
;
font-size
:
16px
;
}
}
uni-app
,
uni-app
,
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
a1c6e0ed
...
@@ -44,6 +44,7 @@ const defaultRpx2Unit = {
...
@@ -44,6 +44,7 @@ const defaultRpx2Unit = {
unitPrecision
:
5
,
unitPrecision
:
5
,
};
};
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
// ignore: rpxCalcIncludeWidth
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
if
(
!
$1
)
{
if
(
!
$1
)
{
return
m
;
return
m
;
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
a1c6e0ed
...
@@ -40,6 +40,7 @@ const defaultRpx2Unit = {
...
@@ -40,6 +40,7 @@ const defaultRpx2Unit = {
unitPrecision
:
5
,
unitPrecision
:
5
,
};
};
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
function
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
{
// ignore: rpxCalcIncludeWidth
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
return
(
val
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
if
(
!
$1
)
{
if
(
!
$1
)
{
return
m
;
return
m
;
...
...
packages/uni-shared/src/dom/style.ts
浏览文件 @
a1c6e0ed
...
@@ -22,6 +22,7 @@ export function createRpx2Unit(
...
@@ -22,6 +22,7 @@ export function createRpx2Unit(
unitRatio
:
number
,
unitRatio
:
number
,
unitPrecision
:
number
unitPrecision
:
number
)
{
)
{
// ignore: rpxCalcIncludeWidth
return
(
val
:
string
)
=>
return
(
val
:
string
)
=>
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
val
.
replace
(
unitRE
,
(
m
,
$1
)
=>
{
if
(
!
$1
)
{
if
(
!
$1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录