mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-06 04:00:06 +08:00
refactor: theme color chose components
This commit is contained in:
parent
04f8642c33
commit
61f60316f3
106
src/components/check/ColorCheckBox.vue
Normal file
106
src/components/check/ColorCheckBox.vue
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<template>
|
||||||
|
<div class="theme-color" :style="{backgroundColor: color}" @click="toggle">
|
||||||
|
<a-icon v-if="sChecked" type="check" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import AIcon from 'ant-design-vue/es/icon/icon'
|
||||||
|
|
||||||
|
const Group = {
|
||||||
|
name: 'ColorCheckBoxGroup',
|
||||||
|
props: {
|
||||||
|
defaultValues: {
|
||||||
|
type: Array,
|
||||||
|
required: false,
|
||||||
|
default: () => []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
values: this.defaultValues
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide () {
|
||||||
|
return {
|
||||||
|
groupContext: this
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleChange (value) {
|
||||||
|
if (!value.checked) {
|
||||||
|
const values = this.values.filter(item => item.value !== value.value)
|
||||||
|
this.values = values
|
||||||
|
} else {
|
||||||
|
this.values.push(value)
|
||||||
|
}
|
||||||
|
this.$emit('change', this.values)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render (h) {
|
||||||
|
const clear = h('div', {attrs: {style: 'clear: both'}})
|
||||||
|
return h(
|
||||||
|
'div',
|
||||||
|
{},
|
||||||
|
[this.$slots.default, clear]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ColorCheckBox',
|
||||||
|
Group: Group,
|
||||||
|
components: {AIcon},
|
||||||
|
props: {
|
||||||
|
color: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
checked: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
sChecked: this.checked
|
||||||
|
}
|
||||||
|
},
|
||||||
|
inject: ['groupContext'],
|
||||||
|
watch: {
|
||||||
|
'sChecked': function (val) {
|
||||||
|
const value = {
|
||||||
|
value: this.value,
|
||||||
|
color: this.color,
|
||||||
|
checked: this.sChecked
|
||||||
|
}
|
||||||
|
this.$emit('change', value)
|
||||||
|
this.groupContext.handleChange(value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggle () {
|
||||||
|
this.sChecked = !this.sChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.theme-color{
|
||||||
|
float: left;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-right: 8px;
|
||||||
|
text-align: center;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
@ -3,7 +3,7 @@
|
|||||||
<div class="logo">
|
<div class="logo">
|
||||||
<router-link to="/dashboard/workplace">
|
<router-link to="/dashboard/workplace">
|
||||||
<img src="static/img/vue-antd-logo.png">
|
<img src="static/img/vue-antd-logo.png">
|
||||||
<h1>Vue Ant Pro</h1>
|
<h1>Vue Antd Admin</h1>
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<i-menu :collapsed="collapsed" :menuData="menuData" @select="onSelect"/>
|
<i-menu :collapsed="collapsed" :menuData="menuData" @select="onSelect"/>
|
||||||
|
@ -7,17 +7,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<setting-item title="主题色">
|
<setting-item title="主题色">
|
||||||
<div>
|
<color-check-box-group @change="onColorChange">
|
||||||
<theme-color color="rgb(245, 34, 45)" />
|
<color-check-box color="rgb(245, 34, 45)" value="1" />
|
||||||
<theme-color color="rgb(250, 84, 28)" />
|
<color-check-box color="rgb(250, 84, 28)" value="2" />
|
||||||
<theme-color color="rgb(250, 173, 20)" />
|
<color-check-box color="rgb(250, 173, 20)" value="3" />
|
||||||
<theme-color color="rgb(19, 194, 194)" />
|
<color-check-box color="rgb(19, 194, 194)" value="4" />
|
||||||
<theme-color color="rgb(82, 196, 26)" />
|
<color-check-box color="rgb(82, 196, 26)" value="5" />
|
||||||
<theme-color color="rgb(24, 144, 255)" />
|
<color-check-box color="rgb(24, 144, 255)" value="6" />
|
||||||
<theme-color color="rgb(47, 84, 235)" />
|
<color-check-box color="rgb(47, 84, 235)" value="7" />
|
||||||
<theme-color color="rgb(114, 46, 209)" :selected="true" />
|
<color-check-box color="rgb(114, 46, 209)" value="8" />
|
||||||
<div style="clear: both" />
|
</color-check-box-group>
|
||||||
</div>
|
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<a-divider/>
|
<a-divider/>
|
||||||
<setting-item title="导航设置">
|
<setting-item title="导航设置">
|
||||||
@ -75,12 +74,16 @@ import AListItem from 'ant-design-vue/es/list/Item'
|
|||||||
import AButton from 'ant-design-vue/es/button/button'
|
import AButton from 'ant-design-vue/es/button/button'
|
||||||
import ASwitch from 'ant-design-vue/es/switch/index'
|
import ASwitch from 'ant-design-vue/es/switch/index'
|
||||||
import ASelect from 'ant-design-vue/es/select/index'
|
import ASelect from 'ant-design-vue/es/select/index'
|
||||||
|
import ColorCheckBox from '../check/ColorCheckBox'
|
||||||
|
|
||||||
const ASelectOption = ASelect.Option
|
const ASelectOption = ASelect.Option
|
||||||
|
const ColorCheckBoxGroup = ColorCheckBox.Group
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Setting',
|
name: 'Setting',
|
||||||
components: {
|
components: {
|
||||||
|
ColorCheckBoxGroup,
|
||||||
|
ColorCheckBox,
|
||||||
ASelectOption,
|
ASelectOption,
|
||||||
ASelect,
|
ASelect,
|
||||||
ASwitch,
|
ASwitch,
|
||||||
@ -92,7 +95,12 @@ export default {
|
|||||||
StyleItem,
|
StyleItem,
|
||||||
SettingItem,
|
SettingItem,
|
||||||
AIcon,
|
AIcon,
|
||||||
ALayoutSider}
|
ALayoutSider},
|
||||||
|
methods: {
|
||||||
|
onColorChange (values) {
|
||||||
|
console.log(values)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user