Skip to content

Commit 104513f

Browse files
committed
fix(switch): props命名错误问题
1 parent 962688c commit 104513f

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

packages/mpx-cube-ui/src/components/switch/rn-mixin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android') {
2222
'cube-switch-BGC': (animationOptions) => {
2323
const animation = this.bgAnimation || (this.bgAnimation = mpx.createAnimation({ ...animationOptions }))
2424
if (this.isOn) {
25-
const onBGC = this.switchOnGBC || '#FF6435'
25+
const onBGC = this.switchOnBGC || this.switchOnGBC || '#FF6435'
2626
animation.backgroundColor(onBGC).step({ duration: animationOptions.duration })
2727
} else {
28-
const defaultBGC = this.switchDefaultGBC || '#EAEAEA'
28+
const defaultBGC = this.switchDefaultBGC || this.switchDefaultGBC || '#EAEAEA'
2929
animation.backgroundColor(defaultBGC).step({ duration: animationOptions.duration })
3030
}
3131
this.switchAnimationData = animation.export()

packages/mpx-cube-ui/src/components/switch/switch.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)