_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. //遍历主题map
  84. @mixin themeify {
  85. @each $theme-name, $theme-map in $themes {
  86. //!global 把局部变量强升为全局变量
  87. $theme-map: $theme-map !global;
  88. //判断html的data-theme的属性值 #{}是sass的插值表达式
  89. //& sass嵌套里的父容器标识 @content是混合器插槽,像vue的slot
  90. [data-theme="#{$theme-name}"] & {
  91. @content;
  92. }
  93. }
  94. }
  95. //声明一个根据Key获取颜色的function
  96. @function themed($key) {
  97. @return map-get($theme-map, $key);
  98. }
  99. .font1{
  100. @include themeify{
  101. font-size: themed('font-size1');
  102. }
  103. }
  104. .font2{
  105. @include themeify{
  106. font-size: themed('font-size2');
  107. }
  108. }
  109. .font3{
  110. @include themeify{
  111. font-size: themed('font-size3');
  112. }
  113. }
  114. .font4{
  115. @include themeify{
  116. font-size: themed('font-size4');
  117. }
  118. }
  119. .font5{
  120. @include themeify{
  121. font-size: themed('font-size5');
  122. }
  123. }
  124. .font6{
  125. @include themeify{
  126. font-size: themed('font-size6');
  127. }
  128. }
  129. .font7{
  130. @include themeify{
  131. font-size: themed('font-size7');
  132. }
  133. }
  134. .font8{
  135. @include themeify{
  136. font-size: themed('font-size8');
  137. }
  138. }
  139. .font9{
  140. @include themeify{
  141. font-size: themed('font-size9');
  142. }
  143. }
  144. .font10{
  145. @include themeify{
  146. font-size: themed('font-size10');
  147. }
  148. }
  149. .font-weight1{
  150. @include themeify{
  151. font-size: themed('font-size1');
  152. font-weight:themed('font-weight1');
  153. letter-spacing: themed('letterSpacing');
  154. }
  155. }
  156. .font-weight2{
  157. @include themeify{
  158. font-size: themed('font-size2');
  159. font-weight:themed('fontWeight');
  160. letter-spacing: themed('letterSpacing');
  161. }
  162. }
  163. .font-weight3{
  164. @include themeify{
  165. font-size: themed('font-size3');
  166. font-weight:themed('fontWeight');
  167. letter-spacing: themed('letterSpacing');
  168. }
  169. }
  170. .font-weight4{
  171. @include themeify{
  172. font-size: themed('font-size4');
  173. font-weight:themed('fontWeight');
  174. letter-spacing: themed('letterSpacing');
  175. }
  176. }
  177. .font-weight5{
  178. @include themeify{
  179. font-size: themed('font-size5');
  180. font-weight:themed('fontWeight');
  181. letter-spacing: themed('letterSpacing');
  182. }
  183. }
  184. .font-weight6{
  185. @include themeify{
  186. font-size: themed('font-size6');
  187. font-weight:themed('fontWeight');
  188. letter-spacing: themed('letterSpacing');
  189. }
  190. }
  191. .font-weight7{
  192. @include themeify{
  193. font-size: themed('font-size7');
  194. font-weight:themed('fontWeight');
  195. letter-spacing: themed('letterSpacing');
  196. }
  197. }
  198. .font-weight8{
  199. @include themeify{
  200. font-size: themed('font-size8');
  201. font-weight:themed('fontWeight');
  202. letter-spacing: themed('letterSpacing');
  203. }
  204. }
  205. .font-weight9{
  206. @include themeify{
  207. font-size: themed('font-size9');
  208. font-weight:themed('fontWeight');
  209. letter-spacing: themed('letterSpacing');
  210. }
  211. }
  212. .font-weight10{
  213. @include themeify{
  214. font-size: themed('font-size10');
  215. font-weight:themed('fontWeight');
  216. letter-spacing: themed('letterSpacing');
  217. }
  218. }