Commit c0fa72ca6df0de8a772b45d30084f608c4421528
1 parent
93a5f34f
update ColorPicker
Showing
3 changed files
with
19 additions
and
43 deletions
Show diff stats
examples/routers/color-picker.vue
1 | 1 | <template> |
2 | 2 | <div style="margin: 100px;"> |
3 | - {{ color.rgba }} | |
3 | + {{ color }} | |
4 | 4 | <!--<Input placeholder="请输入..." size="large" style="width: 50px;"></Input>--> |
5 | 5 | <!--<color-picker placement="bottom-start" size="large"></color-picker>--> |
6 | 6 | <!--<Date-picker type="date" placeholder="选择日期" size="large" style="width: 200px"></Date-picker>--> |
7 | 7 | <color-picker ref="xxx" v-model="color" alpha :recommend="true"></color-picker> |
8 | - <color-picker v-model="color" :alpha="false" :recommend="false"></color-picker> | |
8 | + <color-picker v-model="color2" :alpha="false" :recommend="false"></color-picker> | |
9 | 9 | <!--<Date-picker type="date" placeholder="选择日期" style="width: 200px"></Date-picker>--> |
10 | 10 | <!--<color-picker placement="bottom-start" size="small"></color-picker>--> |
11 | 11 | <!--<Date-picker type="date" placeholder="选择日期" size="small" style="width: 200px"></Date-picker>--> |
... | ... | @@ -17,7 +17,8 @@ |
17 | 17 | props: {}, |
18 | 18 | data () { |
19 | 19 | return { |
20 | - color: 'rgba(245,5,78,.8)' | |
20 | + color: 'rgba(124,24,24,.5)', | |
21 | + color2: '' | |
21 | 22 | }; |
22 | 23 | }, |
23 | 24 | computed: {}, | ... | ... |
src/components/color-picker/color-picker.vue
... | ... | @@ -4,7 +4,10 @@ |
4 | 4 | <i class="ivu-icon ivu-icon-arrow-down-b ivu-input-icon ivu-input-icon-normal"></i> |
5 | 5 | <div :class="inputClasses"> |
6 | 6 | <div :class="[prefixCls + '-color']"> |
7 | - <div :style="{backgroundColor: displayedColor}"></div> | |
7 | + <div :class="[prefixCls + '-color-empty']" v-if="value === '' && !visible"> | |
8 | + <Icon type="ios-close-empty"></Icon> | |
9 | + </div> | |
10 | + <div v-else :style="{backgroundColor: displayedColor}"></div> | |
8 | 11 | </div> |
9 | 12 | </div> |
10 | 13 | </div> |
... | ... | @@ -29,6 +32,7 @@ |
29 | 32 | <script> |
30 | 33 | import tinycolor from 'tinycolor2'; |
31 | 34 | |
35 | + import Icon from '../icon/icon.vue'; | |
32 | 36 | import Dropdown from '../dropdown/dropdown.vue'; |
33 | 37 | import DropdownMenu from '../dropdown/dropdown-menu.vue'; |
34 | 38 | import RecommendColors from './recommend-colors.vue'; |
... | ... | @@ -44,6 +48,7 @@ |
44 | 48 | const inputPrefixCls = 'ivu-input'; |
45 | 49 | |
46 | 50 | function _colorChange (data, oldHue) { |
51 | + data = data === '' ? '#ff0000' : data; | |
47 | 52 | const alpha = data && data.a; |
48 | 53 | let color; |
49 | 54 | |
... | ... | @@ -93,7 +98,7 @@ |
93 | 98 | |
94 | 99 | export default { |
95 | 100 | name: 'ColorPicker', |
96 | - components: { Dropdown, DropdownMenu, Confirm, RecommendColors, Saturation, Hue, Alpha }, | |
101 | + components: { Icon, Dropdown, DropdownMenu, Confirm, RecommendColors, Saturation, Hue, Alpha }, | |
97 | 102 | props: { |
98 | 103 | value: { |
99 | 104 | type: String |
... | ... | @@ -218,44 +223,6 @@ |
218 | 223 | } |
219 | 224 | }, |
220 | 225 | methods: { |
221 | - formatColor () { | |
222 | - const defaultColor = { | |
223 | - hex: '#ff0000', | |
224 | - hsl: { | |
225 | - h: 0, | |
226 | - s: 1, | |
227 | - l: 0.5, | |
228 | - a: 1 | |
229 | - }, | |
230 | - hsv: { | |
231 | - h: 0, | |
232 | - s: 1, | |
233 | - v: 1, | |
234 | - a: 1 | |
235 | - }, | |
236 | - rgba: { | |
237 | - r: 255, | |
238 | - g: 0, | |
239 | - b: 0, | |
240 | - a: 1 | |
241 | - }, | |
242 | - a: 1 | |
243 | - }; | |
244 | - if (this.value) { | |
245 | - const color = tinycolor(this.value); | |
246 | - const hex = color.toHex(); | |
247 | - const hsl = color.toHsl(); | |
248 | - const hsv = color.toHsv(); | |
249 | - const rgba = color.toRgb(); | |
250 | - | |
251 | - defaultColor.hex = hex; | |
252 | - defaultColor.hsl = hsl; | |
253 | - defaultColor.hsv = hsv; | |
254 | - defaultColor.rgba = rgba; | |
255 | - defaultColor.a = rgba.a; | |
256 | - } | |
257 | - return defaultColor; | |
258 | - }, | |
259 | 226 | childChange (data) { |
260 | 227 | this.colorChange(data); |
261 | 228 | }, | ... | ... |
src/styles/components/color-picker.less