_theme.scss 4.5 KB

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