// 需要单位转换的属性 const size = ['width', 'height', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', "borderRadius", "fontSize", "margin", "padding", "gap" ]; // 样式的key const keys = [...size, "fontWeight", "color", "backgroundColor"] /** * isCss: 是否需要判断当前属性是否css */ export const getStyle = (config) => { if (!config) return ''; // console.log('config = ', config) const styleObj = {} try { for (let key in config) { if (keys.includes(key)) { if (size.includes(key)) { styleObj[key] = uni.upx2px(config[key]) + 'px' } else { styleObj[key] = config[key]; } } } } catch (e) {} return styleObj; } export const getSingleStyle = (num) => { return uni.upx2px(num) + 'px' } // 样式单位rpx export const unit = (target) => { return `${target * 2}rpx` }