Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
quantum-blocks
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
quantum-blocks
Commits
f47e6aed
Commit
f47e6aed
authored
Jun 09, 2022
by
郭志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: pxtorem
parent
cae8fb42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
transformStyle.mixin.ts
app/web/page/mixins/transformStyle.mixin.ts
+4
-3
utils.service.ts
app/web/service/utils.service.ts
+10
-2
No files found.
app/web/page/mixins/transformStyle.mixin.ts
View file @
f47e6aed
import
{
Component
,
Vue
}
from
'
vue-property-decorator
'
;
import
{
pick
,
omit
,
omitBy
}
from
'
lodash
'
;
import
{
transformStyle
}
from
'
@/service/utils.service
'
;
import
{
transformStyle
,
isPx
,
pxToRem
}
from
'
@/service/utils.service
'
;
@
Component
({
name
:
'
TransformStyleMixin
'
})
export
default
class
TransformStyleMixin
extends
Vue
{
...
...
@@ -13,16 +13,17 @@ export default class TransformStyleMixin extends Vue {
};
if
(
!
styleObj
)
{
return
style
;
}
for
(
const
key
of
Object
.
keys
(
styleObj
))
{
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
if
(
key
===
'
height
'
)
{
styleObj
[
key
]
=
Math
.
ceil
(
styleObj
[
key
]);
}
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
2
)}
rem`
;
}
else
{
style
[
key
]
=
styleObj
[
key
]?.
includes
(
'
px
'
)
?
`
${(
+
(
styleObj
[
key
].
slice
(
0
,
-
2
))
/
37.5
).
toFixed
(
2
)}
rem`
:
styleObj
[
key
];
style
[
key
]
=
isPx
(
styleObj
[
key
])
?
pxToRem
(
styleObj
[
key
])
:
styleObj
[
key
];
}
if
(
key
===
'
backgroundImage
'
&&
style
.
backgroundImage
)
{
style
.
backgroundImage
=
`url(
${
style
.
backgroundImage
}
)`
;
// style.background = `url(${style.backgroundImage}) no-repeat 0 0 / cover`;
}
}
if
(
element
!==
'
container
'
)
{
style
=
omit
(
style
,
[
'
position
'
,
'
top
'
,
'
left
'
]);
...
...
app/web/service/utils.service.ts
View file @
f47e6aed
...
...
@@ -88,7 +88,15 @@ export const convertPointStyle = (point, defaultStyle, directionKey = DK) => {
};
return
style
;
};
export
const
isPx
=
str
=>
/
(\d
+
(\.\d
*
)?)
+
(
px
)
/gi
.
test
(
str
);
export
const
pxToRem
=
(
str
,
width
=
37.5
)
=>
{
const
reg
=
/
(\d
+
(\.\d
*
)?)
+
(
px
)
/gi
;
//可以匹配浮点数
let
newStr
=
str
.
replace
(
reg
,
function
(
_x
)
{
_x
=
_x
.
replace
(
/px"/gi
,
''
);
return
parseFloat
(
parseFloat
(
_x
)
/
width
).
toFixed
(
2
)
+
'
rem
'
;
});
return
newStr
;
}
export
const
getStyle
=
function
(
oElement
,
sName
)
{
const
result
=
oElement
.
currentStyle
?
oElement
.
currentStyle
[
sName
]
:
getComputedStyle
(
oElement
,
null
)[
sName
];
return
result
.
includes
(
'
px
'
)
?
result
.
slice
(
0
,
-
2
)
:
result
;
...
...
@@ -110,7 +118,7 @@ export const transformStyle = function(styleObj = {}) {
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
3
)}
rem`
;
}
else
{
style
[
key
]
=
styleObj
[
key
].
includes
(
'
px
'
)
?
`
${(
+
(
styleObj
[
key
].
slice
(
0
,
-
2
))
/
37.5
).
toFixed
(
3
)}
rem`
:
styleObj
[
key
];
style
[
key
]
=
isPx
(
styleObj
[
key
])
?
pxToRem
(
styleObj
[
key
])
:
styleObj
[
key
];
}
if
(
key
===
'
backgroundImage
'
&&
style
.
backgroundImage
)
{
style
.
background
=
`url(
${
style
.
backgroundImage
}
) no-repeat 0 0 / cover`
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment