File tree Expand file tree Collapse file tree
packages/mpx-cube-ui/src/components/switch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 wx:class="{{ switchClass }}"
44 bindtap="toggleSwitch"
55 animation="{{ switchAnimationData }}"
6+ wx:style="{{ swithBGClass }}"
67 >
78 <view
89 class="cube-switch-handle"
Original file line number Diff line number Diff line change @@ -19,16 +19,18 @@ if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android') {
1919 lifetimes : {
2020 created ( ) {
2121 this . ANIMATION_PRESET = {
22- 'cube-switch-on ' : ( animationOptions ) => {
22+ 'cube-switch-BGC ' : ( animationOptions ) => {
2323 const animation = this . maskAnimation || ( this . maskAnimation = mpx . createAnimation ( { ...animationOptions } ) )
2424 if ( this . isOn ) {
25- animation . backgroundColor ( '#FF6435' ) . step ( )
25+ const onBGC = this . switchOnGBC || '#FF6435'
26+ animation . backgroundColor ( onBGC ) . step ( )
2627 } else {
27- animation . backgroundColor ( '#EAEAEA' ) . step ( )
28+ const defaultBGC = this . switchDefaultGBC || '#EAEAEA'
29+ animation . backgroundColor ( defaultBGC ) . step ( )
2830 }
2931 this . switchAnimationData = animation . export ( )
3032 } ,
31- 'cube-switch-handle-on ' : ( animationOptions ) => {
33+ 'cube-switch-left ' : ( animationOptions ) => {
3234 const animation = this . maskAnimation || ( this . maskAnimation = mpx . createAnimation ( { ...animationOptions } ) )
3335 if ( this . isOn ) {
3436 animation . left ( 18 ) . step ( )
Original file line number Diff line number Diff line change @@ -12,6 +12,14 @@ createComponent({
1212 type : Boolean ,
1313 value : false
1414 } ,
15+ switchDefaultGBC : {
16+ type : String ,
17+ value : ''
18+ } ,
19+ switchOnGBC : {
20+ type : String ,
21+ value : ''
22+ } ,
1523 /**
1624 * @description 是否禁用
1725 * @optional true/false
@@ -31,6 +39,22 @@ createComponent({
3139 'cube-switch-on' : this . isOn ,
3240 [ `cube-switch-${ this . themeType } ` ] : this . themeType
3341 }
42+ } ,
43+ swithBGClass ( ) {
44+ if ( __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' ) {
45+ return { }
46+ }
47+ if ( this . isOn && this . switchOnGBC ) {
48+ return {
49+ backgroundColor : this . switchOnGBC
50+ }
51+ } else if ( ! this . isOn && this . switchDefaultGBC ) {
52+ return {
53+ backgroundColor : this . switchDefaultGBC
54+ }
55+ } else {
56+ return { }
57+ }
3458 }
3559 } ,
3660 watch : {
You can’t perform that action at this time.
0 commit comments