@@ -11,10 +11,22 @@ createComponent({
1111 type : Boolean ,
1212 value : false
1313 } ,
14+ switchDefaultBGC : {
15+ type : String ,
16+ value : ''
17+ } ,
18+ switchOnBGC : {
19+ type : String ,
20+ value : ''
21+ } ,
22+ // @dosHide
23+ // props 命名错误,没人用就删掉
1424 switchDefaultGBC : {
1525 type : String ,
1626 value : ''
1727 } ,
28+ // @dosHide
29+ // props 命名错误,没人用就删掉
1830 switchOnGBC : {
1931 type : String ,
2032 value : ''
@@ -26,6 +38,14 @@ createComponent({
2638 disabled : {
2739 type : Boolean ,
2840 value : false
41+ } ,
42+ /**
43+ * @description 点击后是否需要更改 value
44+ * @optional true/false
45+ */
46+ changeOnClick : {
47+ type : Boolean ,
48+ value : true
2949 }
3050 } ,
3151 data : {
@@ -40,17 +60,17 @@ createComponent({
4060 } ;
4161 } ,
4262 swithBGClass ( ) {
43- if ( __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' ) {
63+ if ( __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' || __mpx_mode__ === 'harmony' ) {
4464 return { } ;
4565 }
46- if ( this . isOn && this . switchOnGBC ) {
66+ if ( this . isOn && ( this . switchOnBGC || this . switchOnGBC ) ) {
4767 return {
48- backgroundColor : this . switchOnGBC
68+ backgroundColor : this . switchOnBGC || this . switchOnGBC
4969 } ;
5070 }
51- else if ( ! this . isOn && this . switchDefaultGBC ) {
71+ else if ( ! this . isOn && ( this . switchDefaultBGC || this . switchDefaultGBC ) ) {
5272 return {
53- backgroundColor : this . switchDefaultGBC
73+ backgroundColor : this . switchDefaultBGC || this . switchDefaultGBC
5474 } ;
5575 }
5676 else {
@@ -68,10 +88,18 @@ createComponent({
6888 } ,
6989 methods : {
7090 toggleSwitch ( ) {
71- if ( this . disabled )
91+ if ( this . disabled ) {
92+ this . triggerEvent ( 'click' , { value : this . isOn } ) ;
7293 return ;
94+ }
95+ if ( ! this . changeOnClick ) {
96+ this . triggerEvent ( 'click' , { value : this . isOn } ) ;
97+ return ;
98+ }
7399 const newValue = ! this . isOn ;
74100 this . isOn = newValue ;
101+ // 当开关有点击时触发
102+ this . triggerEvent ( 'click' , { value : newValue } ) ;
75103 // 当开关状态变化时触发
76104 this . triggerEvent ( 'change' , { value : newValue } ) ;
77105 // 当开关状态变化时触发
0 commit comments