unocss.config.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { defineConfig, presetUni } from 'uni-unocss';
  2. export default defineConfig({
  3. presets: [presetUni()],
  4. shortcuts: [
  5. {
  6. center: 'flex justify-center items-center',
  7. },
  8. ],
  9. rules: [
  10. [/^mg-([\.\d]+)$/, ([_, num]) => ({ margin: `${num}rpx` })],
  11. [/^pd-([\.\d]+)$/, ([_, num]) => ({ padding: `${num}rpx` })],
  12. [/^bg-([\w#-]+)$/, ([_, color]) => ({ 'background-color': color })],
  13. [/^c-([\w#-]+)$/, ([_, color]) => ({ color: color })],
  14. // bc-#fafafa
  15. [/^bc-([\w#-]+)$/, ([_, color]) => ({ 'border-color': color })],
  16. // 下边距
  17. [/^mb-([\.\d]+)$/, ([_, num]) => ({ 'margin-bottom': `${num}rpx` })],
  18. // 上边距
  19. [/^mt-([\.\d]+)$/, ([_, num]) => ({ 'margin-top': `${num}rpx` })],
  20. // 左边距
  21. [/^ml-([\.\d]+)$/, ([_, num]) => ({ 'margin-left': `${num}rpx` })],
  22. // 右边距
  23. [/^mr-([\.\d]+)$/, ([_, num]) => ({ 'margin-right': `${num}rpx` })],
  24. // 上padding
  25. [/^pt-([\.\d]+)$/, ([_, num]) => ({ 'padding-top': `${num}rpx` })],
  26. // 下padding
  27. [/^pb-([\.\d]+)$/, ([_, num]) => ({ 'padding-bottom': `${num}rpx` })],
  28. // pd3-40-0-20
  29. // padding
  30. [
  31. /^pd3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  32. ([_, top, right, bottom]) => ({
  33. padding: `${top}rpx ${right}rpx ${bottom}rpx`,
  34. }),
  35. ],
  36. // pd2-40-20
  37. [
  38. /^pd2-([\.\d]+)-([\.\d]+)$/,
  39. ([_, top, right]) => ({
  40. padding: `${top}rpx ${right}rpx`,
  41. }),
  42. ],
  43. // pd4-40-20-10-5
  44. [
  45. /^pd4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  46. ([_, top, right, bottom, left]) => ({
  47. padding: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
  48. }),
  49. ],
  50. // mg2-40-20
  51. [
  52. /^mg2-([\.\d]+)-([\.\d]+)$/,
  53. ([_, top, right]) => ({
  54. margin: `${top}rpx ${right}rpx`,
  55. }),
  56. ],
  57. // mg3-40-20-10
  58. [
  59. /^mg3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  60. ([_, top, right, bottom]) => ({
  61. margin: `${top}rpx ${right}rpx ${bottom}rpx`,
  62. }),
  63. ],
  64. // mg4-40-20-10-5
  65. [
  66. /^mg4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  67. ([_, top, right, bottom, left]) => ({
  68. margin: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
  69. }),
  70. ],
  71. // 左padding
  72. [/^pl-([\.\d]+)$/, ([_, num]) => ({ 'padding-left': `${num}rpx` })],
  73. // 右padding
  74. [/^pr-([\.\d]+)$/, ([_, num]) => ({ 'padding-right': `${num}rpx` })],
  75. // 字体大小
  76. [/^f-s-([\.\d]+)$/, ([_, num]) => ({ 'font-size': `${num}rpx` })],
  77. // 字体加粗
  78. [/^f-w-([\.\d]+)$/, ([_, num]) => ({ 'font-weight': `${num > 100 ? num : num * 100}` })],
  79. // 宽
  80. [/^w-([\.\d]+)$/, ([_, num]) => ({ width: `${num}rpx` })],
  81. // 高
  82. [/^h-([\.\d]+)$/, ([_, num]) => ({ height: `${num}rpx` })],
  83. // 带透明度的可传入颜色计算rgba值加背景
  84. // 行高
  85. [/^lh-([\.\d]+)$/, ([_, num]) => ({ 'line-height': `${num}` })],
  86. // 黑色透明度
  87. [
  88. /^bg-black-([\.\d]+)$/,
  89. ([_, num]) => ({
  90. 'background-color': `rgba(0, 0, 0, ${num})`,
  91. }),
  92. ],
  93. // 透明度
  94. [
  95. /^opacity-([\.\d]+)$/,
  96. ([_, num]) => ({
  97. opacity: `${num}`,
  98. }),
  99. ],
  100. // z-index
  101. [
  102. /^z-index-([\.\d]+)$/,
  103. ([_, num]) => ({
  104. 'z-index': `${num}`,
  105. }),
  106. ],
  107. // 百分比高度
  108. [/^h-([\.\d]+)%$/, ([_, num]) => ({ height: `${num}%` })],
  109. [
  110. /^wrapper-([\.\d]+)-([\.\d]+)$/,
  111. ([_, maxWidth, minWidth]) => ({
  112. 'max-width': `${maxWidth}rpx`,
  113. 'min-width': `${minWidth}rpx`,
  114. margin: '0 auto',
  115. padding: '0 20px',
  116. }),
  117. ],
  118. // 最大宽
  119. [/^max-w-([\.\d]+)$/, ([_, num]) => ({ 'max-width': `${num}rpx` })],
  120. // 最小宽
  121. [/^min-w-([\.\d]+)$/, ([_, num]) => ({ 'min-width': `${num}rpx` })],
  122. // 最大高
  123. [/^max-h-([\.\d]+)$/, ([_, num]) => ({ 'max-height': `${num}rpx` })],
  124. // 最小高
  125. [/^min-h-([\.\d]+)$/, ([_, num]) => ({ 'min-height': `${num}rpx` })],
  126. // 栅格 30份
  127. [/^hcol-([\.\d]+)$/, ([_, num]) => ({ width: `${(+num / 30) * 100}%` })],
  128. // border-radius-8
  129. [
  130. /^border-radius-([\.\d]+)$/,
  131. ([_, num]) => ({
  132. 'border-radius': `${num}rpx`,
  133. }),
  134. ],
  135. // border-w-4
  136. [
  137. /^border-w-([\.\d]+)$/,
  138. ([_, num]) => ({
  139. 'border-width': `${num}rpx`,
  140. }),
  141. ],
  142. // 旋转度数
  143. [
  144. /^rotate-([\-\.\d]+)$/,
  145. ([_, num]) => ({
  146. transform: `rotate(${num}deg)`,
  147. }),
  148. ],
  149. // gap-20
  150. [
  151. /^gap-([\.\d]+)$/,
  152. ([_, num]) => ({
  153. gap: `${num}rpx`,
  154. }),
  155. ],
  156. ],
  157. theme: {
  158. colors: {
  159. /** 主题色,用法如: text-primary */
  160. primary: 'var(--wot-color-theme,#0957DE)',
  161. },
  162. fontSize: {
  163. /** 提供更小号的字体,用法如:text-2xs */
  164. '2xs': ['20rpx', '28rpx'],
  165. '3xs': ['18rpx', '26rpx'],
  166. },
  167. },
  168. });