| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import { defineConfig, presetUni } from 'uni-unocss';
- export default defineConfig({
- presets: [presetUni()],
- shortcuts: [
- {
- center: 'flex justify-center items-center',
- 'b-radius': 'radius-16',
- },
- ],
- rules: [
- [/^mg-([\.\d]+)$/, ([_, num]) => ({ margin: `${num}rpx` })],
- [/^pd-([\.\d]+)$/, ([_, num]) => ({ padding: `${num}rpx` })],
- [/^bg-([\w#-]+)$/, ([_, color]) => ({ 'background-color': color })],
- [/^c-([\w#-]+)$/, ([_, color]) => ({ color: color })],
- // bc-#fafafa
- [/^bc-([\w#-]+)$/, ([_, color]) => ({ 'border-color': color })],
- // 下边距
- [/^mb-([\.\d]+)$/, ([_, num]) => ({ 'margin-bottom': `${num}rpx` })],
- // 上边距
- [/^mt-([\.\d]+)$/, ([_, num]) => ({ 'margin-top': `${num}rpx` })],
- // 左边距
- [/^ml-([\.\d]+)$/, ([_, num]) => ({ 'margin-left': `${num}rpx` })],
- // 右边距
- [/^mr-([\.\d]+)$/, ([_, num]) => ({ 'margin-right': `${num}rpx` })],
- // 上padding
- [/^pt-([\.\d]+)$/, ([_, num]) => ({ 'padding-top': `${num}rpx` })],
- // 下padding
- [/^pb-([\.\d]+)$/, ([_, num]) => ({ 'padding-bottom': `${num}rpx` })],
- // pd3-40-0-20
- // padding
- [
- /^pd3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right, bottom]) => ({
- padding: `${top}rpx ${right}rpx ${bottom}rpx`,
- }),
- ],
- // pd2-40-20
- [
- /^pd2-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right]) => ({
- padding: `${top}rpx ${right}rpx`,
- }),
- ],
- // pd4-40-20-10-5
- [
- /^pd4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right, bottom, left]) => ({
- padding: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
- }),
- ],
- // mg2-40-20
- [
- /^mg2-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right]) => ({
- margin: `${top}rpx ${right}rpx`,
- }),
- ],
- // mg3-40-20-10
- [
- /^mg3-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right, bottom]) => ({
- margin: `${top}rpx ${right}rpx ${bottom}rpx`,
- }),
- ],
- // mg4-40-20-10-5
- [
- /^mg4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right, bottom, left]) => ({
- margin: `${top}rpx ${right}rpx ${bottom}rpx ${left}rpx`,
- }),
- ],
- // ab2-40-20
- [
- /^ab2-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right]) => ({
- position: 'absolute',
- top: `${top}rpx`,
- right: `${right}rpx`,
- }),
- ],
- // ab4-40-20-10-5
- [
- /^ab4-([\.\d]+)-([\.\d]+)-([\.\d]+)-([\.\d]+)$/,
- ([_, top, right, bottom, left]) => ({
- position: 'absolute',
- top: `${top}rpx`,
- right: `${right}rpx`,
- bottom: `${bottom}rpx`,
- left: `${left}rpx`,
- }),
- ],
- // 左padding
- [/^pl-([\.\d]+)$/, ([_, num]) => ({ 'padding-left': `${num}rpx` })],
- // 右padding
- [/^pr-([\.\d]+)$/, ([_, num]) => ({ 'padding-right': `${num}rpx` })],
- // 字体大小
- [/^f-s-([\.\d]+)$/, ([_, num]) => ({ 'font-size': `${num}rpx` })],
- // 字体加粗
- [/^f-w-([\.\d]+)$/, ([_, num]) => ({ 'font-weight': `${num > 100 ? num : num * 100}` })],
- // 宽
- [/^w-([\.\d]+)$/, ([_, num]) => ({ width: `${num}rpx` })],
- // 高
- [/^h-([\.\d]+)$/, ([_, num]) => ({ height: `${num}rpx` })],
- // 带透明度的可传入颜色计算rgba值加背景
- // 行高
- [/^lh-([\.\d]+)$/, ([_, num]) => ({ 'line-height': `${num}` })],
- // 黑色透明度
- [
- /^bg-black-([\.\d]+)$/,
- ([_, num]) => ({
- 'background-color': `rgba(0, 0, 0, ${num})`,
- }),
- ],
- [/^radius-([\.\d]+)$/, ([_, num]) => ({ 'border-radius': `${num}rpx` })],
- [/^radius-([\.\d]+)%$/, ([_, num]) => ({ 'border-radius': `${num}%` })],
- // 透明度
- [
- /^opacity-([\.\d]+)$/,
- ([_, num]) => ({
- opacity: `${num}`,
- }),
- ],
- // z-index
- [
- /^z-index-([\.\d]+)$/,
- ([_, num]) => ({
- 'z-index': `${num}`,
- }),
- ],
- // 百分比高度
- [/^h-([\.\d]+)%$/, ([_, num]) => ({ height: `${num}%` })],
- [/^w-([\.\d]+)%$/, ([_, num]) => ({ width: `${num}%` })],
- [
- /^wrapper-([\.\d]+)-([\.\d]+)$/,
- ([_, maxWidth, minWidth]) => ({
- 'max-width': `${maxWidth}rpx`,
- 'min-width': `${minWidth}rpx`,
- margin: '0 auto',
- padding: '0 20px',
- }),
- ],
- // 最大宽
- [/^max-w-([\.\d]+)$/, ([_, num]) => ({ 'max-width': `${num}rpx` })],
- // 最小宽
- [/^min-w-([\.\d]+)$/, ([_, num]) => ({ 'min-width': `${num}rpx` })],
- // 最大高
- [/^max-h-([\.\d]+)$/, ([_, num]) => ({ 'max-height': `${num}rpx` })],
- // 最小高
- [/^min-h-([\.\d]+)$/, ([_, num]) => ({ 'min-height': `${num}rpx` })],
- // 栅格 30份
- [/^hcol-([\.\d]+)$/, ([_, num]) => ({ width: `${(+num / 30) * 100}%` })],
- // border-w-4
- // gcol-10-10 后面的数字是gap宽度
- // 栅格30份加gap宽度
- [
- /^border-w-([\.\d]+)$/,
- ([_, num]) => ({
- 'border-width': `${num}rpx`,
- }),
- ],
- // 顶部边框
- [
- /^border-top-([\w#-]+)$/,
- ([_, color]) => ({
- 'border-top-color': color,
- 'border-top-style': 'solid',
- 'border-top-width': '1rpx',
- transform: 'rotate(360deg)',
- }),
- ],
- // 尾部边框
- [
- /^border-bottom-([\w#-]+)$/,
- ([_, color]) => ({
- 'border-bottom-color': color,
- 'border-bottom-style': 'solid',
- 'border-bottom-width': '1rpx',
- transform: 'rotate(360deg)',
- }),
- ],
- //边框
- [
- /^border-([\w#-]+)$/,
- ([_, color]) => ({
- 'border-color': color,
- 'border-style': 'solid',
- 'border-width': '1rpx',
- transform: 'rotate(360deg)',
- }),
- ],
- // 旋转度数
- [
- /^rotate-([\-\.\d]+)$/,
- ([_, num]) => ({
- transform: `rotate(${num}deg)`,
- }),
- ],
- // gap-20
- [
- /^gap-([\.\d]+)$/,
- ([_, num]) => ({
- gap: `${num}rpx`,
- }),
- ],
- // 黑色透明度颜色
- [
- /^bg-black-op-([\.\d]+)$/,
- ([_, num]) => ({
- 'background-color': `rgba(0, 0, 0, ${num})`,
- }),
- ],
- ],
- transformers: [
- {
- name: 'remove-custom-classes',
- enforce: 'pre',
- transform(code, id) {
- // 只在相关文件中处理
- if (id.endsWith('.vue')) {
- // 移除特定的类名
- const modified = code.replace(/\bclass=["']([^"']*)u-popup__content—transition([^"']*)["']/g, (match, before, after) => {
- return `class="${before}${after}"`;
- });
- return {
- code: modified,
- map: null,
- };
- }
- return { code, map: null };
- },
- },
- ],
- theme: {
- colors: {
- /** 主题色,用法如: text-primary */
- primary: 'var(--wot-color-theme,#0957DE)',
- },
- fontSize: {
- /** 提供更小号的字体,用法如:text-2xs */
- '2xs': ['20rpx', '28rpx'],
- '3xs': ['18rpx', '26rpx'],
- },
- },
- });
|