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",
|
"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
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -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 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
@ -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
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',
|
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);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -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
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 */
|
/* eslint-disable */
|
||||||
var REGEXP = getRegExp('^\d+(\.\d+)?$');
|
var REGEXP = getRegExp('^-?\d+(\.\d+)?$');
|
||||||
|
|
||||||
function addUnit(value) {
|
function addUnit(value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -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(':');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user