unocss.config.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. 'b-radius': 'radius-16',
  8. },
  9. ],
  10. rules: [
  11. [/^mg-([\.\d]+)$/, ([_, num]) => ({ margin: `${num}rpx` })],
  12. [/^pd-([\.\d]+)$/, ([_, num]) => ({ padding: `${num}rpx` })],
  13. [/^bg-([\w#-]+)$/, ([_, color]) => ({ 'background-color': color })],
  14. [/^c-([\w#-]+)$/, ([_, color]) => ({ color: color })],
  15. // bc-#fafafa
  16. [/^bc-([\w#-]+)$/, ([_, color]) => ({ 'border-color': color })],
  17. // 下边距
  18. [/^mb-([\.\d]+)$/, ([_, num]) => ({ 'margin-bottom': `${num}rpx` })],
  19. // 上边距
  20. [/^mt-([\.\d]+)$/, ([_, num]) => ({ 'margin-top': `${num}rpx` })],
  21. // 左边距
  22. [/^ml-([\.\d]+)$/, ([_, num]) => ({ 'margin-left': `${num}rpx` })],
  23. // 右边距
  24. [/^mr-([\.\d]+)$/, ([_, num]) => ({ 'margin-right': `${num}rpx` })],
  25. // 上padding
  26. [/^pt-([\.\d]+)$/, ([_, num]) => ({ 'padding-top': `${num}rpx` })],
  27. // 下padding
  28. [/^pb-([\.\d]+)$/, ([_, num]) => ({ 'padding-bottom': `${num}rpx` })],
  29. // pd3-40-0-20
  30. // padding
  31. [
  32. /^pd3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  33. ([_, top, right, bottom]) => ({
  34. padding: `${top}rpx ${right}rpx ${bottom}rpx`,
  35. }),
  36. ],
  37. // pd2-40-20
  38. [
  39. /^pd2-([\.\d]+)-([\.\d]+)$/,
  40. ([_, top, right]) => ({
  41. padding: `${top}rpx ${right}rpx`,
  42. }),
  43. ],
  44. // pd4-40-20-10-5
  45. [
  46. /^pd4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  47. ([_, top, right, bottom, left]) => ({
  48. padding: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
  49. }),
  50. ],
  51. // mg2-40-20
  52. [
  53. /^mg2-([\.\d]+)-([\.\d]+)$/,
  54. ([_, top, right]) => ({
  55. margin: `${top}rpx ${right}rpx`,
  56. }),
  57. ],
  58. // mg3-40-20-10
  59. [
  60. /^mg3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  61. ([_, top, right, bottom]) => ({
  62. margin: `${top}rpx ${right}rpx ${bottom}rpx`,
  63. }),
  64. ],
  65. // mg4-40-20-10-5
  66. [
  67. /^mg4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  68. ([_, top, right, bottom, left]) => ({
  69. margin: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
  70. }),
  71. ],
  72. // ab2-40-20
  73. [
  74. /^ab2-([\.\d]+)-([\.\d]+)$/,
  75. ([_, top, right]) => ({
  76. position: 'absolute',
  77. top: `${top}rpx`,
  78. right: `${right}rpx`,
  79. }),
  80. ],
  81. // ab4-40-20-10-5
  82. [
  83. /^ab4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
  84. ([_, top, right, bottom, left]) => ({
  85. position: 'absolute',
  86. top: `${top}rpx`,
  87. right: `${right}rpx`,
  88. bottom: `${bottom}rpx`,
  89. left: `${left}rpx`,
  90. }),
  91. ],
  92. // 左padding
  93. [/^pl-([\.\d]+)$/, ([_, num]) => ({ 'padding-left': `${num}rpx` })],
  94. // 右padding
  95. [/^pr-([\.\d]+)$/, ([_, num]) => ({ 'padding-right': `${num}rpx` })],
  96. // 字体大小
  97. [/^f-s-([\.\d]+)$/, ([_, num]) => ({ 'font-size': `${num}rpx` })],
  98. // 字体加粗
  99. [/^f-w-([\.\d]+)$/, ([_, num]) => ({ 'font-weight': `${num > 100 ? num : num * 100}` })],
  100. // 宽
  101. [/^w-([\.\d]+)$/, ([_, num]) => ({ width: `${num}rpx` })],
  102. // 高
  103. [/^h-([\.\d]+)$/, ([_, num]) => ({ height: `${num}rpx` })],
  104. // 带透明度的可传入颜色计算rgba值加背景
  105. // 行高
  106. [/^lh-([\.\d]+)$/, ([_, num]) => ({ 'line-height': `${num}` })],
  107. // 黑色透明度
  108. [
  109. /^bg-black-([\.\d]+)$/,
  110. ([_, num]) => ({
  111. 'background-color': `rgba(0, 0, 0, ${num})`,
  112. }),
  113. ],
  114. [/^radius-([\.\d]+)$/, ([_, num]) => ({ 'border-radius': `${num}rpx` })],
  115. [/^radius-([\.\d]+)%$/, ([_, num]) => ({ 'border-radius': `${num}%` })],
  116. // 透明度
  117. [
  118. /^opacity-([\.\d]+)$/,
  119. ([_, num]) => ({
  120. opacity: `${num}`,
  121. }),
  122. ],
  123. // z-index
  124. [
  125. /^z-index-([\.\d]+)$/,
  126. ([_, num]) => ({
  127. 'z-index': `${num}`,
  128. }),
  129. ],
  130. // 百分比高度
  131. [/^h-([\.\d]+)%$/, ([_, num]) => ({ height: `${num}%` })],
  132. [/^w-([\.\d]+)%$/, ([_, num]) => ({ width: `${num}%` })],
  133. [
  134. /^wrapper-([\.\d]+)-([\.\d]+)$/,
  135. ([_, maxWidth, minWidth]) => ({
  136. 'max-width': `${maxWidth}rpx`,
  137. 'min-width': `${minWidth}rpx`,
  138. margin: '0 auto',
  139. padding: '0 20px',
  140. }),
  141. ],
  142. // 最大宽
  143. [/^max-w-([\.\d]+)$/, ([_, num]) => ({ 'max-width': `${num}rpx` })],
  144. // 最小宽
  145. [/^min-w-([\.\d]+)$/, ([_, num]) => ({ 'min-width': `${num}rpx` })],
  146. // 最大高
  147. [/^max-h-([\.\d]+)$/, ([_, num]) => ({ 'max-height': `${num}rpx` })],
  148. // 最小高
  149. [/^min-h-([\.\d]+)$/, ([_, num]) => ({ 'min-height': `${num}rpx` })],
  150. // 栅格 30份
  151. [/^hcol-([\.\d]+)$/, ([_, num]) => ({ width: `${(+num / 30) * 100}%` })],
  152. // border-w-4
  153. // gcol-10-10 后面的数字是gap宽度
  154. // 栅格30份加gap宽度
  155. [
  156. /^border-w-([\.\d]+)$/,
  157. ([_, num]) => ({
  158. 'border-width': `${num}rpx`,
  159. }),
  160. ],
  161. // 顶部边框
  162. [
  163. /^border-top-([\w#-]+)$/,
  164. ([_, color]) => ({
  165. 'border-top-color': color,
  166. 'border-top-style': 'solid',
  167. 'border-top-width': '1rpx',
  168. transform: 'rotate(360deg)',
  169. }),
  170. ],
  171. // 尾部边框
  172. [
  173. /^border-bottom-([\w#-]+)$/,
  174. ([_, color]) => ({
  175. 'border-bottom-color': color,
  176. 'border-bottom-style': 'solid',
  177. 'border-bottom-width': '1rpx',
  178. transform: 'rotate(360deg)',
  179. }),
  180. ],
  181. //边框
  182. [
  183. /^border-([\w#-]+)$/,
  184. ([_, color]) => ({
  185. 'border-color': color,
  186. 'border-style': 'solid',
  187. 'border-width': '1rpx',
  188. transform: 'rotate(360deg)',
  189. }),
  190. ],
  191. // 旋转度数
  192. [
  193. /^rotate-([\-\.\d]+)$/,
  194. ([_, num]) => ({
  195. transform: `rotate(${num}deg)`,
  196. }),
  197. ],
  198. // gap-20
  199. [
  200. /^gap-([\.\d]+)$/,
  201. ([_, num]) => ({
  202. gap: `${num}rpx`,
  203. }),
  204. ],
  205. // 黑色透明度颜色
  206. [
  207. /^bg-black-op-([\.\d]+)$/,
  208. ([_, num]) => ({
  209. 'background-color': `rgba(0, 0, 0, ${num})`,
  210. }),
  211. ],
  212. ],
  213. transformers: [
  214. {
  215. name: 'remove-custom-classes',
  216. enforce: 'pre',
  217. transform(code, id) {
  218. // 只在相关文件中处理
  219. if (id.endsWith('.vue')) {
  220. // 移除特定的类名
  221. const modified = code.replace(/\bclass=["']([^"']*)u-popup__content—transition([^"']*)["']/g, (match, before, after) => {
  222. return `class="${before}${after}"`;
  223. });
  224. return {
  225. code: modified,
  226. map: null,
  227. };
  228. }
  229. return { code, map: null };
  230. },
  231. },
  232. ],
  233. theme: {
  234. colors: {
  235. /** 主题色,用法如: text-primary */
  236. primary: 'var(--wot-color-theme,#0957DE)',
  237. },
  238. fontSize: {
  239. /** 提供更小号的字体,用法如:text-2xs */
  240. '2xs': ['20rpx', '28rpx'],
  241. '3xs': ['18rpx', '26rpx'],
  242. },
  243. },
  244. });