unocss.config.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. [/^w-([\.\d]+)%$/, ([_, num]) => ({ width: `${num}%` })],
  110. [
  111. /^wrapper-([\.\d]+)-([\.\d]+)$/,
  112. ([_, maxWidth, minWidth]) => ({
  113. 'max-width': `${maxWidth}rpx`,
  114. 'min-width': `${minWidth}rpx`,
  115. margin: '0 auto',
  116. padding: '0 20px',
  117. }),
  118. ],
  119. // 最大宽
  120. [/^max-w-([\.\d]+)$/, ([_, num]) => ({ 'max-width': `${num}rpx` })],
  121. // 最小宽
  122. [/^min-w-([\.\d]+)$/, ([_, num]) => ({ 'min-width': `${num}rpx` })],
  123. // 最大高
  124. [/^max-h-([\.\d]+)$/, ([_, num]) => ({ 'max-height': `${num}rpx` })],
  125. // 最小高
  126. [/^min-h-([\.\d]+)$/, ([_, num]) => ({ 'min-height': `${num}rpx` })],
  127. // 栅格 30份
  128. [/^hcol-([\.\d]+)$/, ([_, num]) => ({ width: `${(+num / 30) * 100}%` })],
  129. // border-radius-8
  130. [
  131. /^border-radius-([\.\d]+)$/,
  132. ([_, num]) => ({
  133. 'border-radius': `${num}rpx`,
  134. }),
  135. ],
  136. // border-w-4
  137. [
  138. /^border-w-([\.\d]+)$/,
  139. ([_, num]) => ({
  140. 'border-width': `${num}rpx`,
  141. }),
  142. ],
  143. // 旋转度数
  144. [
  145. /^rotate-([\-\.\d]+)$/,
  146. ([_, num]) => ({
  147. transform: `rotate(${num}deg)`,
  148. }),
  149. ],
  150. // gap-20
  151. [
  152. /^gap-([\.\d]+)$/,
  153. ([_, num]) => ({
  154. gap: `${num}rpx`,
  155. }),
  156. ],
  157. ],
  158. transformers: [
  159. {
  160. name: 'remove-custom-classes',
  161. enforce: 'pre',
  162. transform(code, id) {
  163. // 只在相关文件中处理
  164. if (id.endsWith('.vue')) {
  165. // 移除特定的类名
  166. const modified = code.replace(/\bclass=["']([^"']*)u-popup__content—transition([^"']*)["']/g, (match, before, after) => {
  167. return `class="${before}${after}"`;
  168. });
  169. return {
  170. code: modified,
  171. map: null,
  172. };
  173. }
  174. return { code, map: null };
  175. },
  176. },
  177. ],
  178. // theme: {
  179. // colors: {
  180. // /** 主题色,用法如: text-primary */
  181. // primary: 'var(--wot-color-theme,#0957DE)',
  182. // },
  183. // fontSize: {
  184. // /** 提供更小号的字体,用法如:text-2xs */
  185. // '2xs': ['20rpx', '28rpx'],
  186. // '3xs': ['18rpx', '26rpx'],
  187. // },
  188. // },
  189. });