_theme.scss 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //当HTML的data-theme为dark时,样式引用dark
  2. //data-theme为其他值时,就采用组件库的默认样式
  3. //这里我只定义了两套主题方案,想要再多只需在`$themes`里加就行了
  4. //注意一点是,每套配色方案里的key可以自定义但必须一致,不然就会混乱
  5. $themes: (
  6. elder: (
  7. //字体
  8. font-size0: 24rpx,
  9. font-size1: 28rpx,
  10. font-size2: 32rpx,
  11. font-size3: 36rpx,
  12. font-size4: 40rpx,
  13. font-size5: 44rpx,
  14. font-size6: 48rpx,
  15. font-size7: 52rpx,
  16. font-size8: 56rpx,
  17. font-size9: 60rpx,
  18. font-size10: 64rpx,
  19. font-size11: 68rpx,
  20. font-size12: 72rpx,
  21. font-size13: 76rpx,
  22. font-size14: 80rpx,
  23. font-size15: 84rpx,
  24. font-size16: 88rpx,
  25. font-size17: 92rpx,
  26. font-size18: 96rpx,
  27. font-size19: 100rpx,
  28. buttonWidth: 300rpx,
  29. fontWeight: bold!important,
  30. font_color1: #410311,
  31. font_color2: white,
  32. font_colorLabel:#000000,
  33. letterSpacing:2px,
  34. cardHeight:390rpx,
  35. //背景
  36. background_color1: #3422ff,
  37. background_color2: #f0f2f5,
  38. background_color3: red,
  39. background_color4: #2674e7,
  40. //边框
  41. border_color1: #3d414a,
  42. ),
  43. standard: (
  44. //字体
  45. font-size0: 20rpx,
  46. font-size1: 24rpx,
  47. font-size2: 28rpx,
  48. font-size3: 32rpx,
  49. font-size4: 36rpx,
  50. font-size5: 40rpx,
  51. font-size6: 44rpx,
  52. font-size7: 48rpx,
  53. font-size8: 52rpx,
  54. font-size9: 56rpx,
  55. font-size10: 60rpx,
  56. font-size11: 64rpx,
  57. font-size12: 68rpx,
  58. font-size13: 72rpx,
  59. font-size14: 76rpx,
  60. font-size15: 80rpx,
  61. font-size16: 84rpx,
  62. font-size17: 88rpx,
  63. font-size18: 92rpx,
  64. font-size19: 96rpx,
  65. font_color1: #a77439,
  66. font_color2: white,
  67. fontWeight: normal,
  68. font_colorLabel:#9f9c99,
  69. letterSpacing:0px,
  70. buttonWidth: 260rpx,
  71. cardHeight:360rpx,
  72. //背景
  73. background_color1: #1b2531,
  74. background_color2: #283142,
  75. background_color3: #1e6ceb,
  76. background_color4: #323e4e,
  77. //边框
  78. border_color1: #3d414a,
  79. )
  80. );
  81. //遍历主题map
  82. @mixin themeify {
  83. @each $theme-name, $theme-map in $themes {
  84. //!global 把局部变量强升为全局变量
  85. $theme-map: $theme-map !global;
  86. //判断html的data-theme的属性值 #{}是sass的插值表达式
  87. //& sass嵌套里的父容器标识 @content是混合器插槽,像vue的slot
  88. [data-theme="#{$theme-name}"] & {
  89. @content;
  90. }
  91. }
  92. }
  93. //声明一个根据Key获取颜色的function
  94. @function themed($key) {
  95. @return map-get($theme-map, $key);
  96. }
  97. .font1{
  98. @include themeify{
  99. font-size: themed('font-size1');
  100. }
  101. }
  102. .font2{
  103. @include themeify{
  104. font-size: themed('font-size2');
  105. }
  106. }
  107. .font3{
  108. @include themeify{
  109. font-size: themed('font-size3');
  110. }
  111. }
  112. .font4{
  113. @include themeify{
  114. font-size: themed('font-size4');
  115. }
  116. }
  117. .font5{
  118. @include themeify{
  119. font-size: themed('font-size5');
  120. }
  121. }
  122. .font6{
  123. @include themeify{
  124. font-size: themed('font-size6');
  125. }
  126. }
  127. .font7{
  128. @include themeify{
  129. font-size: themed('font-size7');
  130. }
  131. }
  132. .font8{
  133. @include themeify{
  134. font-size: themed('font-size8');
  135. }
  136. }
  137. .font9{
  138. @include themeify{
  139. font-size: themed('font-size9');
  140. }
  141. }
  142. .font10{
  143. @include themeify{
  144. font-size: themed('font-size10');
  145. }
  146. }
  147. .font-weight1{
  148. @include themeify{
  149. font-size: themed('font-size1');
  150. font-weight:themed('font-weight1');
  151. letter-spacing: themed('letterSpacing');
  152. }
  153. }
  154. .font-weight2{
  155. @include themeify{
  156. font-size: themed('font-size2');
  157. font-weight:themed('fontWeight');
  158. letter-spacing: themed('letterSpacing');
  159. }
  160. }
  161. .font-weight3{
  162. @include themeify{
  163. font-size: themed('font-size3');
  164. font-weight:themed('fontWeight');
  165. letter-spacing: themed('letterSpacing');
  166. }
  167. }
  168. .font-weight4{
  169. @include themeify{
  170. font-size: themed('font-size4');
  171. font-weight:themed('fontWeight');
  172. letter-spacing: themed('letterSpacing');
  173. }
  174. }
  175. .font-weight5{
  176. @include themeify{
  177. font-size: themed('font-size5');
  178. font-weight:themed('fontWeight');
  179. letter-spacing: themed('letterSpacing');
  180. }
  181. }
  182. .font-weight6{
  183. @include themeify{
  184. font-size: themed('font-size6');
  185. font-weight:themed('fontWeight');
  186. letter-spacing: themed('letterSpacing');
  187. }
  188. }
  189. .font-weight7{
  190. @include themeify{
  191. font-size: themed('font-size7');
  192. font-weight:themed('fontWeight');
  193. letter-spacing: themed('letterSpacing');
  194. }
  195. }
  196. .font-weight8{
  197. @include themeify{
  198. font-size: themed('font-size8');
  199. font-weight:themed('fontWeight');
  200. letter-spacing: themed('letterSpacing');
  201. }
  202. }
  203. .font-weight9{
  204. @include themeify{
  205. font-size: themed('font-size9');
  206. font-weight:themed('fontWeight');
  207. letter-spacing: themed('letterSpacing');
  208. }
  209. }
  210. .font-weight10{
  211. @include themeify{
  212. font-size: themed('font-size10');
  213. font-weight:themed('fontWeight');
  214. letter-spacing: themed('letterSpacing');
  215. }
  216. }