mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
perf(button): use wxs instead of setData (#3839)
This commit is contained in:
parent
ca08409488
commit
979dc506bf
@ -50,32 +50,7 @@ VantComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
value: '20px',
|
value: '20px',
|
||||||
},
|
},
|
||||||
color: {
|
color: String,
|
||||||
type: String,
|
|
||||||
observer(color: string) {
|
|
||||||
let style = '';
|
|
||||||
|
|
||||||
if (color) {
|
|
||||||
style += `color: ${this.data.plain ? color : 'white'};`;
|
|
||||||
|
|
||||||
if (!this.data.plain) {
|
|
||||||
// Use background instead of backgroundColor to make linear-gradient work
|
|
||||||
style += `background: ${color};`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// hide border when color is linear-gradient
|
|
||||||
if (color.indexOf('gradient') !== -1) {
|
|
||||||
style += 'border: 0;';
|
|
||||||
} else {
|
|
||||||
style += `border-color: ${color};`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (style !== this.data.baseStyle) {
|
|
||||||
this.setData({ baseStyle: style });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
|
||||||
<button
|
<button
|
||||||
id="{{ id }}"
|
id="{{ id }}"
|
||||||
@ -7,7 +8,7 @@
|
|||||||
hover-class="van-button--active hover-class"
|
hover-class="van-button--active hover-class"
|
||||||
lang="{{ lang }}"
|
lang="{{ lang }}"
|
||||||
form-type="{{ formType }}"
|
form-type="{{ formType }}"
|
||||||
style="{{ baseStyle }} {{ customStyle }}"
|
style="{{ computed.rootStyle({ plain, color }) }} {{ customStyle }}"
|
||||||
open-type="{{ disabled ? '' : openType }}"
|
open-type="{{ disabled ? '' : openType }}"
|
||||||
business-id="{{ businessId }}"
|
business-id="{{ businessId }}"
|
||||||
session-from="{{ sessionFrom }}"
|
session-from="{{ sessionFrom }}"
|
||||||
@ -30,7 +31,7 @@
|
|||||||
custom-class="loading-class"
|
custom-class="loading-class"
|
||||||
size="{{ loadingSize }}"
|
size="{{ loadingSize }}"
|
||||||
type="{{ loadingType }}"
|
type="{{ loadingType }}"
|
||||||
color="{{ loadingColor(type,color,plain) }}"
|
color="{{ computed.loadingColor({ type, color, plain }) }}"
|
||||||
/>
|
/>
|
||||||
<view wx:if="{{ loadingText }}" class="van-button__loading-text">
|
<view wx:if="{{ loadingText }}" class="van-button__loading-text">
|
||||||
{{ loadingText }}
|
{{ loadingText }}
|
||||||
@ -50,19 +51,3 @@
|
|||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
<wxs module="loadingColor">
|
|
||||||
function get(type, color,plain) {
|
|
||||||
if(plain) {
|
|
||||||
return color ? color: '#c9c9c9';
|
|
||||||
}
|
|
||||||
|
|
||||||
if(type === 'default') {
|
|
||||||
return '#c9c9c9';
|
|
||||||
}
|
|
||||||
return 'white';
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = get;
|
|
||||||
</wxs>
|
|
||||||
|
39
packages/button/index.wxs
Normal file
39
packages/button/index.wxs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var style = require('../wxs/style.wxs');
|
||||||
|
|
||||||
|
function rootStyle(data) {
|
||||||
|
if (!data.color) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = {
|
||||||
|
color: data.plain ? data.color : '#fff',
|
||||||
|
background: data.plain ? null : data.color,
|
||||||
|
};
|
||||||
|
|
||||||
|
// hide border when color is linear-gradient
|
||||||
|
if (data.color.indexOf('gradient') !== -1) {
|
||||||
|
properties.border = 0;
|
||||||
|
} else {
|
||||||
|
properties['border-color'] = data.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadingColor(data) {
|
||||||
|
if (data.plain) {
|
||||||
|
return data.color ? data.color : '#c9c9c9';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.type === 'default') {
|
||||||
|
return '#c9c9c9';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '#fff';
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
rootStyle: rootStyle,
|
||||||
|
loadingColor: loadingColor,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user