feat(card): 增加名片区块配置项,支持逐向内边距和独立成块样式

This commit is contained in:
2026-10-28 17:53:42 +08:00
parent d789dd7142
commit 1f642585d1
3 changed files with 129 additions and 1 deletions

View File

@@ -282,7 +282,17 @@ const DEFAULT_BLOCK_ORDER = 'bio,acts,rows,social,qr,meta';
*/
function blockCustomSpacing(c, prefix) {
if (!flagOn(c[prefix + 'SpacingCustom'], false)) return '';
const side = (k) => px2rpx(num(c[prefix + k], 0));
// 2.24 直配兜底: 逐向开关已开, 但四向值全为 0 且未被商家手动改过(touched=0)
// → 说明是「后端直写配置」而非编辑器接管(编辑器开逐向时会先把统一内边距铺进四向)
// → 此时逐向内边距回落统一内边距, 避免内边距被压成 0(独立成块看着「没内边距」)
const SIDES = ['Top', 'Right', 'Bottom', 'Left'];
const touched = num(c[prefix + 'SpacingTouched'], 0) === 1;
let padBase = 0;
if (!touched) {
const anySide = SIDES.some(s => num(c[prefix + 'Padding' + s], 0) !== 0 || num(c[prefix + 'Margin' + s], 0) !== 0);
if (!anySide) padBase = num(c[prefix + 'BlockPad'], 0);
}
const side = (k) => px2rpx(num(c[prefix + k], 0)) + (k.indexOf('Padding') === 0 ? px2rpx(padBase) : 0);
const m = [side('MarginTop'), side('MarginRight'), side('MarginBottom'), side('MarginLeft')];
const p = [side('PaddingTop'), side('PaddingRight'), side('PaddingBottom'), side('PaddingLeft')];
return 'margin: ' + m.join('rpx ') + 'rpx; padding: ' + p.join('rpx ') + 'rpx;';