// 方向映射配置 $spacing-map: ( 'm': 'margin', 'p': 'padding', ); $directions: ( 't': 'top', 'r': 'right', 'b': 'bottom', 'l': 'left', 'x': ( 'left', 'right', ), 'y': ( 'top', 'bottom', ), ); $directions1: ( 't': 'top', 'r': 'right', 'b': 'bottom', 'l': 'left', ); $font-map: ( 'size': 'font-size', ); $line-map: ( 'line': 'line-height', ); $radius-map: ( 'radius': 'border-radius', ); $weight-map: ( 'weight': 'font-weight', ); $wh-map: ( 'w_': 'width', 'h_': 'height', ); $zIndex-map: ( 'z-': 'z-index', ); // 生成工具类 @mixin gen-spacing($prefix, $property, $min: 1, $max: 300) { @for $i from $min through $max { // 单边样式 @each $dir-abbr, $dir-value in $directions { @if length($dir-value) == 1 { .#{$prefix}-#{$dir-abbr}-#{$i} { #{$property}-#{$dir-value}: #{$i}rpx !important; @if $prefix == 'p' { box-sizing: border-box !important; } } } } // 复合方向 .#{$prefix}-x-#{$i} { #{$property}-left: #{$i}rpx !important; #{$property}-right: #{$i}rpx !important; @if $prefix == 'p' { box-sizing: border-box !important; } } .#{$prefix}-y-#{$i} { #{$property}-top: #{$i}rpx !important; #{$property}-bottom: #{$i}rpx !important; @if $prefix == 'p' { box-sizing: border-box !important; } } // 全方向 .#{$prefix}-#{$i} { #{$property}: #{$i}rpx !important; @if $prefix == 'p' { box-sizing: border-box !important; } } } } // 新增字体工具类生成器 @mixin gen-font($prefix, $property, $min: 8, $max: 100) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i}rpx !important; } } } // 新增行高工具类生成器 @mixin gen-line-height($prefix, $property, $min: 8, $max: 100) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i}rpx !important; } } } // 新增字体粗细工具类生成器 @mixin gen-weight($prefix, $property, $min: 400, $max: 900) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i} !important; } } } // 新增宽高工具类生成器 @mixin gen-wh($prefix, $property, $min: 0, $max: 1000) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i}rpx !important; } } } // 新增方向工具类生成器 @mixin gen-direction($prefix, $property, $min: -1000, $max: 1000) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i}rpx !important; } } } // 新增z-index工具类生成器 @mixin gen-zIndex($prefix, $property, $min: -1000, $max: 1000) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i} !important; } } } // 新增宽高工具类 @each $abbr, $property in $wh-map { @include gen-wh($abbr, $property); } // 新增方向工具类 @each $abbr, $property in $directions1 { @include gen-direction($abbr, $property); } // 新增字体粗细工具类 @each $abbr, $property in $weight-map { @include gen-weight($abbr, $property); } // 生成圆角工具类 @mixin gen-radius($prefix, $property, $min: 0, $max: 100) { @for $i from $min through $max { .#{$prefix}#{$i} { #{$property}: #{$i}rpx !important; } } } // 生成所有工具类 @each $abbr, $property in $spacing-map { @include gen-spacing($abbr, $property); } // 生成字体工具类 @each $abbr, $property in $font-map { @include gen-font($abbr, $property); } // 生成圆角工具类 @each $abbr, $property in $radius-map { @include gen-radius($abbr, $property); } // 新增行高工具类 @each $abbr, $property in $line-map { @include gen-line-height($abbr, $property); } // 新增 z-index 工具类 @each $abbr, $property in $zIndex-map { @include gen-direction($abbr, $property); } // 特殊处理 border-box (已包含在 padding 类中) .border-box { box-sizing: border-box !important; }