unocss.config.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // 左padding
  73. [/^pl-([\.\d]+)$/, ([_, num]) => ({ 'padding-left': `${num}rpx` })],
  74. // 右padding
  75. [/^pr-([\.\d]+)$/, ([_, num]) => ({ 'padding-right': `${num}rpx` })],
  76. // 字体大小
  77. [/^f-s-([\.\d]+)$/, ([_, num]) => ({ 'font-size': `${num}rpx` })],
  78. // 字体加粗
  79. [/^f-w-([\.\d]+)$/, ([_, num]) => ({ 'font-weight': `${num > 100 ? num : num * 100}` })],
  80. // 宽
  81. [/^w-([\.\d]+)$/, ([_, num]) => ({ width: `${num}rpx` })],
  82. // 高
  83. [/^h-([\.\d]+)$/, ([_, num]) => ({ height: `${num}rpx` })],
  84. // 带透明度的可传入颜色计算rgba值加背景
  85. // 行高
  86. [/^lh-([\.\d]+)$/, ([_, num]) => ({ 'line-height': `${num}` })],
  87. // 黑色透明度
  88. [
  89. /^bg-black-([\.\d]+)$/,
  90. ([_, num]) => ({
  91. 'background-color': `rgba(0, 0, 0, ${num})`,
  92. }),
  93. ],
  94. [/^radius-([\.\d]+)$/, ([_, num]) => ({ 'border-radius': `${num}rpx` })],
  95. [/^radius-([\.\d]+)%$/, ([_, num]) => ({ 'border-radius': `${num}%` })],
  96. // 透明度
  97. [
  98. /^opacity-([\.\d]+)$/,
  99. ([_, num]) => ({
  100. opacity: `${num}`,
  101. }),
  102. ],
  103. // z-index
  104. [
  105. /^z-index-([\.\d]+)$/,
  106. ([_, num]) => ({
  107. 'z-index': `${num}`,
  108. }),
  109. ],
  110. // 百分比高度
  111. [/^h-([\.\d]+)%$/, ([_, num]) => ({ height: `${num}%` })],
  112. [/^w-([\.\d]+)%$/, ([_, num]) => ({ width: `${num}%` })],
  113. [
  114. /^wrapper-([\.\d]+)-([\.\d]+)$/,
  115. ([_, maxWidth, minWidth]) => ({
  116. 'max-width': `${maxWidth}rpx`,
  117. 'min-width': `${minWidth}rpx`,
  118. margin: '0 auto',
  119. padding: '0 20px',
  120. }),
  121. ],
  122. // 最大宽
  123. [/^max-w-([\.\d]+)$/, ([_, num]) => ({ 'max-width': `${num}rpx` })],
  124. // 最小宽
  125. [/^min-w-([\.\d]+)$/, ([_, num]) => ({ 'min-width': `${num}rpx` })],
  126. // 最大高
  127. [/^max-h-([\.\d]+)$/, ([_, num]) => ({ 'max-height': `${num}rpx` })],
  128. // 最小高
  129. [/^min-h-([\.\d]+)$/, ([_, num]) => ({ 'min-height': `${num}rpx` })],
  130. // 栅格 30份
  131. [/^hcol-([\.\d]+)$/, ([_, num]) => ({ width: `${(+num / 30) * 100}%` })],
  132. // border-w-4
  133. [
  134. /^border-w-([\.\d]+)$/,
  135. ([_, num]) => ({
  136. 'border-width': `${num}rpx`,
  137. }),
  138. ],
  139. // 顶部边框
  140. [
  141. /^border-top-([\w#-]+)$/,
  142. ([_, color]) => ({
  143. 'border-top-color': color,
  144. 'border-top-style': 'solid',
  145. 'border-top-width': '1rpx',
  146. transform: 'rotate(360deg)',
  147. }),
  148. ],
  149. // 尾部边框
  150. [
  151. /^border-bottom-([\w#-]+)$/,
  152. ([_, color]) => ({
  153. 'border-bottom-color': color,
  154. 'border-bottom-style': 'solid',
  155. 'border-bottom-width': '1rpx',
  156. transform: 'rotate(360deg)',
  157. }),
  158. ],
  159. //边框
  160. [
  161. /^border-([\w#-]+)$/,
  162. ([_, color]) => ({
  163. 'border-color': color,
  164. 'border-style': 'solid',
  165. 'border-width': '1rpx',
  166. transform: 'rotate(360deg)',
  167. }),
  168. ],
  169. // 旋转度数
  170. [
  171. /^rotate-([\-\.\d]+)$/,
  172. ([_, num]) => ({
  173. transform: `rotate(${num}deg)`,
  174. }),
  175. ],
  176. // gap-20
  177. [
  178. /^gap-([\.\d]+)$/,
  179. ([_, num]) => ({
  180. gap: `${num}rpx`,
  181. }),
  182. ],
  183. ],
  184. transformers: [
  185. {
  186. name: 'remove-custom-classes',
  187. enforce: 'pre',
  188. transform(code, id) {
  189. // 只在相关文件中处理
  190. if (id.endsWith('.vue')) {
  191. // 移除特定的类名
  192. const modified = code.replace(/\bclass=["']([^"']*)u-popup__content—transition([^"']*)["']/g, (match, before, after) => {
  193. return `class="${before}${after}"`;
  194. });
  195. return {
  196. code: modified,
  197. map: null,
  198. };
  199. }
  200. return { code, map: null };
  201. },
  202. },
  203. ],
  204. theme: {
  205. colors: {
  206. /** 主题色,用法如: text-primary */
  207. primary: 'var(--wot-color-theme,#0957DE)',
  208. },
  209. fontSize: {
  210. /** 提供更小号的字体,用法如:text-2xs */
  211. '2xs': ['20rpx', '28rpx'],
  212. '3xs': ['18rpx', '26rpx'],
  213. },
  214. },
  215. });