mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-05 19:41:45 +08:00
feat(Switch): change loading color when background color change (#2067)
This commit is contained in:
parent
da30b612c4
commit
a65d97c2dd
@ -4,3 +4,4 @@ export const WHITE = '#fff';
|
|||||||
export const GREEN = '#07c160';
|
export const GREEN = '#07c160';
|
||||||
export const ORANGE = '#ff976a';
|
export const ORANGE = '#ff976a';
|
||||||
export const GRAY = '#323233';
|
export const GRAY = '#323233';
|
||||||
|
export const GRAY_DARK = '#969799';
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { BLUE, GRAY_DARK } from '../common/color';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
field: true,
|
field: true,
|
||||||
@ -27,15 +28,24 @@ VantComponent({
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
checked(value) {
|
checked(value) {
|
||||||
this.setData({ value });
|
const loadingColor = this.getLoadingColor(value);
|
||||||
|
this.setData({ value, loadingColor });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.setData({ value: this.data.checked });
|
const { checked: value } = this.data;
|
||||||
|
const loadingColor = this.getLoadingColor(value);
|
||||||
|
|
||||||
|
this.setData({ value, loadingColor });
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
getLoadingColor(checked) {
|
||||||
|
const { activeColor, inactiveColor } = this.data;
|
||||||
|
return checked ? activeColor || BLUE : inactiveColor || GRAY_DARK;
|
||||||
|
},
|
||||||
|
|
||||||
onClick() {
|
onClick() {
|
||||||
const { activeValue, inactiveValue } = this.data;
|
const { activeValue, inactiveValue } = this.data;
|
||||||
if (!this.data.disabled && !this.data.loading) {
|
if (!this.data.disabled && !this.data.loading) {
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
bind:tap="onClick"
|
bind:tap="onClick"
|
||||||
>
|
>
|
||||||
<view class="van-switch__node node-class">
|
<view class="van-switch__node node-class">
|
||||||
<van-loading wx:if="{{ loading }}" size="50%" custom-class="van-switch__loading" />
|
<van-loading wx:if="{{ loading }}" color="{{ loadingColor }}" size="50%" custom-class="van-switch__loading" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user