uview-plus组件库全面升级更新,订单结算判断支付方式是否可用代码调整,公众号关注二维码修改
This commit is contained in:
45
uni_modules/lime-shared/cssToObj/index.ts
Normal file
45
uni_modules/lime-shared/cssToObj/index.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// @ts-nocheck
|
||||
// #ifndef UNI-APP-X
|
||||
type UTSJSONObject = Record<string, any>
|
||||
// #endif
|
||||
|
||||
|
||||
/**
|
||||
* 将 CSS 字符串转换为样式对象
|
||||
* @param css CSS 字符串,例如 "color: red; font-size: 16px;"
|
||||
* @returns CSSProperties 对象
|
||||
*/
|
||||
export function cssToObj(css : string | UTSJSONObject | null) : UTSJSONObject {
|
||||
// #ifdef APP-ANDROID
|
||||
if(css == null) return {}
|
||||
// #endif
|
||||
// #ifndef APP-ANDROID
|
||||
if(!css) return {}
|
||||
// #endif
|
||||
if(typeof css == 'object') return css as UTSJSONObject
|
||||
|
||||
|
||||
const style : UTSJSONObject = {};
|
||||
|
||||
(css as string).split(';').forEach(decl => {
|
||||
// #ifdef APP-ANDROID
|
||||
const res = decl.split(':').map(s => s.trim());
|
||||
if(res.length > 1) {
|
||||
const [prop, val] = res;
|
||||
if (prop != '' && val != '') {
|
||||
const camelProp = prop!.replace(/-([a-z])/g, (_: string, _offset: number,c: string):string => c.toUpperCase());
|
||||
style[camelProp] = val!;
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
// #ifndef APP-ANDROID
|
||||
const [prop, val] = decl.split(':').map(s => s.trim());
|
||||
if (prop && val) {
|
||||
const camelProp = prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
||||
style[camelProp] = val;
|
||||
}
|
||||
// #endif
|
||||
});
|
||||
|
||||
return style;
|
||||
}
|
||||
Reference in New Issue
Block a user