@@ -12,10 +12,22 @@ createComponent({
1212 type : Boolean ,
1313 value : false
1414 } ,
15+ switchDefaultBGC : {
16+ type : String ,
17+ value : ''
18+ } ,
19+ switchOnBGC : {
20+ type : String ,
21+ value : ''
22+ } ,
23+ // @dosHide
24+ // props 命名错误,没人用就删掉
1525 switchDefaultGBC : {
1626 type : String ,
1727 value : ''
1828 } ,
29+ // @dosHide
30+ // props 命名错误,没人用就删掉
1931 switchOnGBC : {
2032 type : String ,
2133 value : ''
@@ -27,6 +39,14 @@ createComponent({
2739 disabled : {
2840 type : Boolean ,
2941 value : false
42+ } ,
43+ /**
44+ * @description 点击后是否需要更改 value
45+ * @optional true/false
46+ */
47+ changeOnClick : {
48+ type : Boolean ,
49+ value : true
3050 }
3151 } ,
3252 data : {
@@ -41,16 +61,16 @@ createComponent({
4161 }
4262 } ,
4363 swithBGClass ( ) {
44- if ( __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' ) {
64+ if ( __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' || __mpx_mode__ === 'harmony' ) {
4565 return { }
4666 }
47- if ( this . isOn && this . switchOnGBC ) {
67+ if ( this . isOn && ( this . switchOnBGC || this . switchOnGBC ) ) {
4868 return {
49- backgroundColor : this . switchOnGBC
69+ backgroundColor : this . switchOnBGC || this . switchOnGBC
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 } else {
5676 return { }
@@ -67,9 +87,20 @@ createComponent({
6787 } ,
6888 methods : {
6989 toggleSwitch ( ) {
70- if ( this . disabled ) return
90+ if ( this . disabled ) {
91+ this . triggerEvent ( 'click' , { value : this . isOn } )
92+ return
93+ }
94+
95+ if ( ! this . changeOnClick ) {
96+ this . triggerEvent ( 'click' , { value : this . isOn } )
97+ return
98+ }
99+
71100 const newValue = ! this . isOn
72101 this . isOn = newValue
102+ // 当开关有点击时触发
103+ this . triggerEvent ( 'click' , { value : newValue } )
73104 // 当开关状态变化时触发
74105 this . triggerEvent ( 'change' , { value : newValue } )
75106 // 当开关状态变化时触发
0 commit comments