mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-06 04:00:06 +08:00
feat: complete function for ColorCheckBox components
This commit is contained in:
parent
2dcc1279cc
commit
702a9dd832
@ -14,11 +14,28 @@ const Group = {
|
|||||||
type: Array,
|
type: Array,
|
||||||
required: false,
|
required: false,
|
||||||
default: () => []
|
default: () => []
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
values: this.defaultValues
|
values: [],
|
||||||
|
options: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
colors () {
|
||||||
|
let colors = []
|
||||||
|
this.options.forEach(item => {
|
||||||
|
if (item.sChecked) {
|
||||||
|
colors.push(item.color)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return colors
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
provide () {
|
provide () {
|
||||||
@ -26,15 +43,30 @@ const Group = {
|
|||||||
groupContext: this
|
groupContext: this
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
watch: {
|
||||||
handleChange (value) {
|
'values': function (newVal, oldVal) {
|
||||||
if (!value.checked) {
|
// 此条件是为解决单选时,触发两次chang事件问题
|
||||||
const values = this.values.filter(item => item.value !== value.value)
|
if (!(newVal.length === 1 && oldVal.length === 1 && newVal[0] === oldVal[0])) {
|
||||||
this.values = values
|
this.$emit('change', this.values, this.colors)
|
||||||
} else {
|
}
|
||||||
this.values.push(value)
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleChange (option) {
|
||||||
|
if (!option.checked) {
|
||||||
|
this.values = this.values.filter(item => item !== option.value)
|
||||||
|
} else {
|
||||||
|
if (!this.multiple) {
|
||||||
|
this.values = [option.value]
|
||||||
|
this.options.forEach(item => {
|
||||||
|
if (item.value !== option.value) {
|
||||||
|
item.sChecked = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.values.push(option.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.$emit('change', this.values)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render (h) {
|
render (h) {
|
||||||
@ -80,7 +112,17 @@ export default {
|
|||||||
checked: this.sChecked
|
checked: this.sChecked
|
||||||
}
|
}
|
||||||
this.$emit('change', value)
|
this.$emit('change', value)
|
||||||
this.groupContext.handleChange(value)
|
const groupContext = this.groupContext
|
||||||
|
if (groupContext) {
|
||||||
|
groupContext.handleChange(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
const groupContext = this.groupContext
|
||||||
|
if (groupContext) {
|
||||||
|
this.sChecked = groupContext.defaultValues.indexOf(this.value) >= 0
|
||||||
|
groupContext.options.push(this)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<setting-item title="主题色">
|
<setting-item title="主题色">
|
||||||
<color-check-box-group @change="onColorChange">
|
<color-check-box-group @change="onColorChange" :defaultValues="['1', '2', '3']" :multiple="false">
|
||||||
<color-check-box color="rgb(245, 34, 45)" value="1" />
|
<color-check-box ref="colorNode" color="rgb(245, 34, 45)" value="1" />
|
||||||
<color-check-box color="rgb(250, 84, 28)" value="2" />
|
<color-check-box color="rgb(250, 84, 28)" value="2" />
|
||||||
<color-check-box color="rgb(250, 173, 20)" value="3" />
|
<color-check-box color="rgb(250, 173, 20)" value="3" />
|
||||||
<color-check-box color="rgb(19, 194, 194)" value="4" />
|
<color-check-box color="rgb(19, 194, 194)" value="4" />
|
||||||
@ -97,8 +97,10 @@ export default {
|
|||||||
AIcon,
|
AIcon,
|
||||||
ALayoutSider},
|
ALayoutSider},
|
||||||
methods: {
|
methods: {
|
||||||
onColorChange (values) {
|
onColorChange (values, colors) {
|
||||||
console.log(values)
|
if (colors.length > 0) {
|
||||||
|
this.$message.info(`选择了主题色 ${colors}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user