Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
quantum-blocks-h5
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-h5
Commits
c1a23000
Commit
c1a23000
authored
Jun 09, 2022
by
郭志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: pxtorem
parent
bb77d79b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
transformStyle.mixin.ts
app/web/page/mixins/transformStyle.mixin.ts
+2
-2
utils.service.ts
app/web/service/utils.service.ts
+10
-1
No files found.
app/web/page/mixins/transformStyle.mixin.ts
View file @
c1a23000
import
{
Component
,
Vue
}
from
'
vue-property-decorator
'
;
import
{
Component
,
Vue
}
from
'
vue-property-decorator
'
;
import
{
transformStyle
,
getStyle
}
from
'
@/service/utils.service
'
;
import
{
transformStyle
,
getStyle
,
isPx
,
pxToRem
}
from
'
@/service/utils.service
'
;
import
{
Mutation
}
from
'
vuex-class
'
;
import
{
Mutation
}
from
'
vuex-class
'
;
@
Component
({
name
:
'
TransformStyleMixin
'
})
@
Component
({
name
:
'
TransformStyleMixin
'
})
...
@@ -17,7 +17,7 @@ export default class TransformStyleMixin extends Vue {
...
@@ -17,7 +17,7 @@ export default class TransformStyleMixin extends Vue {
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
2
)}
rem`
;
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
2
)}
rem`
;
}
else
{
}
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
)
{
if
(
key
===
'
backgroundImage
'
&&
style
.
backgroundImage
)
{
style
.
backgroundImage
=
`url(
${
style
.
backgroundImage
}
)`
;
style
.
backgroundImage
=
`url(
${
style
.
backgroundImage
}
)`
;
...
...
app/web/service/utils.service.ts
View file @
c1a23000
...
@@ -108,6 +108,15 @@ export const validateType = function(obj) {
...
@@ -108,6 +108,15 @@ export const validateType = function(obj) {
return
typeof
obj
===
'
object
'
?
class2type
[
Object
.
prototype
.
toString
.
call
(
obj
)]
||
'
object
'
:
typeof
obj
;
return
typeof
obj
===
'
object
'
?
class2type
[
Object
.
prototype
.
toString
.
call
(
obj
)]
||
'
object
'
:
typeof
obj
;
};
};
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
transformStyle
=
function
(
styleObj
=
{})
{
export
const
transformStyle
=
function
(
styleObj
=
{})
{
// console.log('transformStyle', styleObj);
// console.log('transformStyle', styleObj);
const
style
=
{};
const
style
=
{};
...
@@ -115,7 +124,7 @@ export const transformStyle = function(styleObj = {}) {
...
@@ -115,7 +124,7 @@ export const transformStyle = function(styleObj = {}) {
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
if
(
typeof
styleObj
[
key
]
===
'
number
'
)
{
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
3
)}
rem`
;
style
[
key
]
=
`
${(
styleObj
[
key
]
/
37.5
).
toFixed
(
3
)}
rem`
;
}
else
{
}
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
)
{
if
(
key
===
'
backgroundImage
'
&&
style
.
backgroundImage
)
{
style
.
background
=
`url(
${
style
.
backgroundImage
}
) no-repeat 0 0 / cover`
;
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