perf(col): use wxs (#3886)

This commit is contained in:
rex 2020-12-22 20:23:34 +08:00 committed by GitHub
parent 7f7de48e4a
commit 2f7d66a14f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 48 deletions

View File

@ -48,12 +48,6 @@
"simulatorType": "wechat", "simulatorType": "wechat",
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},
"condition": { "condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"plugin": { "plugin": {
"list": [] "list": []
}, },
@ -391,6 +385,17 @@
"pathName": "pages/share-sheet/index", "pathName": "pages/share-sheet/index",
"query": "", "query": "",
"scene": null "scene": null
},
{
"name": "col",
"pathName": "pages/col/index",
"query": "",
"scene": null
},
{
"name": "divider",
"pathName": "pages/divider/index",
"scene": null
} }
] ]
} }

View File

@ -11,21 +11,4 @@ VantComponent({
span: Number, span: Number,
offset: Number, offset: Number,
}, },
data: {
viewStyle: '',
},
methods: {
setGutter(gutter: number) {
const padding = `${gutter / 2}px`;
const viewStyle = gutter
? `padding-left: ${padding}; padding-right: ${padding};`
: '';
if (viewStyle !== this.data.viewStyle) {
this.setData({ viewStyle });
}
},
},
}); });

View File

@ -1,8 +1,9 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<view <view
class="custom-class {{ utils.bem('col', [span]) }} {{ offset ? 'van-col--offset-' + offset : '' }}" class="custom-class {{ utils.bem('col', [span]) }} {{ offset ? 'van-col--offset-' + offset : '' }}"
style="{{ viewStyle }}" style="{{ computed.rootStyle({ gutter }) }}"
> >
<slot /> <slot />
</view> </view>

18
packages/col/index.wxs Normal file
View File

@ -0,0 +1,18 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
if (!data.gutter) {
return '';
}
return style({
'padding-right': addUnit(data.gutter / 2),
'padding-left': addUnit(data.gutter / 2),
});
}
module.exports = {
rootStyle: rootStyle,
};

View File

@ -6,8 +6,10 @@ VantComponent({
type: 'descendant', type: 'descendant',
current: 'row', current: 'row',
linked(target) { linked(target) {
if (this.data.gutter) { const { gutter } = this.data;
target.setGutter(this.data.gutter);
if (gutter) {
target.setData({ gutter });
} }
}, },
}, },
@ -19,27 +21,10 @@ VantComponent({
}, },
}, },
data: {
viewStyle: '',
},
mounted() {
if (this.data.gutter) {
this.setGutter();
}
},
methods: { methods: {
setGutter() { setGutter() {
const { gutter } = this.data;
const margin = `-${Number(gutter) / 2}px`;
const viewStyle = gutter
? `margin-right: ${margin}; margin-left: ${margin};`
: '';
this.setData({ viewStyle });
this.getRelationNodes('../col/index').forEach((col) => { this.getRelationNodes('../col/index').forEach((col) => {
col.setGutter(this.data.gutter); col.setData(this.data.gutter);
}); });
}, },
}, },

View File

@ -1,3 +1,5 @@
<view class="custom-class van-row" style="{{ viewStyle }}"> <wxs src="./index.wxs" module="computed" />
<view class="van-row custom-class" style="{{ computed.rootStyle({ gutter }) }}">
<slot /> <slot />
</view> </view>

18
packages/row/index.wxs Normal file
View File

@ -0,0 +1,18 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
if (!data.gutter) {
return '';
}
return style({
'margin-right': addUnit(-data.gutter / 2),
'margin-left': addUnit(-data.gutter / 2),
});
}
module.exports = {
rootStyle: rootStyle,
};

View File

@ -1,5 +1,5 @@
/* eslint-disable */ /* eslint-disable */
var REGEXP = getRegExp('^\d+(\.\d+)?$'); var REGEXP = getRegExp('^-?\d+(\.\d+)?$');
function addUnit(value) { function addUnit(value) {
if (value == null) { if (value == null) {

View File

@ -6,7 +6,7 @@ function style(styles) {
if (array.isArray(styles)) { if (array.isArray(styles)) {
return styles return styles
.filter(function (item) { .filter(function (item) {
return item != null; return item != null && item !== '';
}) })
.map(function (item) { .map(function (item) {
return style(item); return style(item);
@ -18,7 +18,7 @@ function style(styles) {
return object return object
.keys(styles) .keys(styles)
.filter(function (key) { .filter(function (key) {
return styles[key] != null; return styles[key] != null && styles[key] !== '';
}) })
.map(function (key) { .map(function (key) {
return [key, [styles[key]]].join(':'); return [key, [styles[key]]].join(':');