mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
perf(col): use wxs (#3886)
This commit is contained in:
parent
7f7de48e4a
commit
2f7d66a14f
@ -48,12 +48,6 @@
|
||||
"simulatorType": "wechat",
|
||||
"simulatorPluginLibVersion": {},
|
||||
"condition": {
|
||||
"search": {
|
||||
"list": []
|
||||
},
|
||||
"conversation": {
|
||||
"list": []
|
||||
},
|
||||
"plugin": {
|
||||
"list": []
|
||||
},
|
||||
@ -391,6 +385,17 @@
|
||||
"pathName": "pages/share-sheet/index",
|
||||
"query": "",
|
||||
"scene": null
|
||||
},
|
||||
{
|
||||
"name": "col",
|
||||
"pathName": "pages/col/index",
|
||||
"query": "",
|
||||
"scene": null
|
||||
},
|
||||
{
|
||||
"name": "divider",
|
||||
"pathName": "pages/divider/index",
|
||||
"scene": null
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -11,21 +11,4 @@ VantComponent({
|
||||
span: 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 });
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -1,8 +1,9 @@
|
||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||
<wxs src="./index.wxs" module="computed" />
|
||||
|
||||
<view
|
||||
class="custom-class {{ utils.bem('col', [span]) }} {{ offset ? 'van-col--offset-' + offset : '' }}"
|
||||
style="{{ viewStyle }}"
|
||||
style="{{ computed.rootStyle({ gutter }) }}"
|
||||
>
|
||||
<slot />
|
||||
</view>
|
||||
|
18
packages/col/index.wxs
Normal file
18
packages/col/index.wxs
Normal 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,
|
||||
};
|
@ -6,8 +6,10 @@ VantComponent({
|
||||
type: 'descendant',
|
||||
current: 'row',
|
||||
linked(target) {
|
||||
if (this.data.gutter) {
|
||||
target.setGutter(this.data.gutter);
|
||||
const { gutter } = this.data;
|
||||
|
||||
if (gutter) {
|
||||
target.setData({ gutter });
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -19,27 +21,10 @@ VantComponent({
|
||||
},
|
||||
},
|
||||
|
||||
data: {
|
||||
viewStyle: '',
|
||||
},
|
||||
|
||||
mounted() {
|
||||
if (this.data.gutter) {
|
||||
this.setGutter();
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
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) => {
|
||||
col.setGutter(this.data.gutter);
|
||||
col.setData(this.data.gutter);
|
||||
});
|
||||
},
|
||||
},
|
||||
|
@ -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 />
|
||||
</view>
|
||||
|
18
packages/row/index.wxs
Normal file
18
packages/row/index.wxs
Normal 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,
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/* eslint-disable */
|
||||
var REGEXP = getRegExp('^\d+(\.\d+)?$');
|
||||
var REGEXP = getRegExp('^-?\d+(\.\d+)?$');
|
||||
|
||||
function addUnit(value) {
|
||||
if (value == null) {
|
||||
|
@ -6,7 +6,7 @@ function style(styles) {
|
||||
if (array.isArray(styles)) {
|
||||
return styles
|
||||
.filter(function (item) {
|
||||
return item != null;
|
||||
return item != null && item !== '';
|
||||
})
|
||||
.map(function (item) {
|
||||
return style(item);
|
||||
@ -18,7 +18,7 @@ function style(styles) {
|
||||
return object
|
||||
.keys(styles)
|
||||
.filter(function (key) {
|
||||
return styles[key] != null;
|
||||
return styles[key] != null && styles[key] !== '';
|
||||
})
|
||||
.map(function (key) {
|
||||
return [key, [styles[key]]].join(':');
|
||||
|
Loading…
x
Reference in New Issue
Block a user