Skip to content

Commit 75d5f98

Browse files
committed
修复自定义数值原子类与色值原子类生成问题
1 parent 7334070 commit 75d5f98

8 files changed

Lines changed: 12 additions & 30 deletions

File tree

loader.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,24 @@ module.exports = function(sSource) {
112112

113113
// 开始生成原子类
114114
aClassName.forEach(item => {
115-
let sKey;
116-
117-
let bColorFlag = oClassNameMap[item.split('-')[0]] && oClassNameMap[item.split('-')[0]].indexOf('#') != -1;
115+
let bColorFlag = oClassNameMap[item.split('-')[0]] && oClassNameMap[item.split('-')[0]].indexOf('$') == -1 && oClassNameMap[item.split('-')[0]].indexOf('#') != -1;
118116

119117
// 色值类
120118
if (bColorFlag) {
121-
sKey = item.match(/\.\w+/)[0];
119+
let sKey = item.match(/\.\w+/)[0];
120+
let nValue = '#' + item.split('-')[1];
121+
aStyleStr.push(`${item}{${oClassNameMap[sKey].replace(/\#/g, nValue)}}`);
122122
}
123123
// 数值类
124124
else if (/\d+/.test(item)) {
125-
sKey = item.match(/\.\w+/)[0];
125+
let sKey = item.match(/\.\w+/)[0];
126+
let nValue = +item.match(/\d+/)[0];
127+
aStyleStr.push(`${item}{${oClassNameMap[sKey].replace(/\$/g, nValue)}}`);
126128
// 通用类
127129
} else {
128-
sKey = item;
129-
}
130-
131-
let nValue;
132-
133-
// 百分比数值,字重,无需使用单位
134-
if (['.wp', '.hp', '.fw'].includes(sKey)) {
135-
nValue = item.match(/\d+/)[0];
136-
} else {
137-
if (bColorFlag) {
138-
nValue = '#' + item.split('-')[1]
139-
} else {
140-
/\d+/.test(item) && (nValue = +item.match(/\d+/)[0]);
141-
}
130+
let sKey = item;
131+
aStyleStr.push(`${item}{${oClassNameMap[sKey]}}`);
142132
}
143-
144-
aStyleStr.push(`${item}{${oClassNameMap[sKey].replace(/\$|\#/g, nValue)}}`);
145133
});
146134

147135
return `'' + '${aStyleStr.join('')}'`;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-atomcss-plugin",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"homepage": "https://github.com/wujr5/miniprogram-atomcss-plugin",
55
"repository": {
66
"type": "git",

test/atomcss.wxss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.h-90{height:90rpx}.lh-90{line-height:90rpx}.h-30{height:30rpx}.lh-30{line-height:30rpx}.w-30{width:30rpx}.bgc-00ff00{background-color: #00ff00}.backcolor-00ff00{background-color: #00ff00}.c-ff00ff{color: #ff00ff}.c-123a6d{color: #123a6d}
1+
.h-90{height:90rpx}.lh-90{line-height:90rpx}.bgc-00ff00{background-color: #00ff00}.backcolor-00ff00{background-color: #00ff00}.c-ff00ff{color: #ff00ff}.c-123a6d{color: #123a6d}.bgred{background: red}

test/pages/test/test.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<view class="h-90 lh-90 bgc-00ff00 backcolor-00ff00 c-ff00ff c-123a6d c-ssdfsdf">测试原子类</view>
1+
<view class="h-90 lh-90 bgc-00ff00 backcolor-00ff00 c-ff00ff c-123a6d bgred">测试原子类</view>

test/pages/test2/test2.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/pages/test2/test2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/pages/test2/test2.wxml

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/pages/test2/test2.wxss

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)