Commit fdafcd2cc519033af68dca396078cb1f1b00beb1
1 parent
0ff50807
Badge add text prop
Showing
4 changed files
with
28 additions
and
6 deletions
Show diff stats
examples/routers/badge.vue
... | ... | @@ -14,14 +14,17 @@ |
14 | 14 | </style> |
15 | 15 | <template> |
16 | 16 | <div> |
17 | - <Badge dot :count="count"> | |
17 | + <Badge :count="count"> | |
18 | 18 | <a href="#" class="demo-badge"></a> |
19 | 19 | </Badge> |
20 | 20 | <Badge :count="0" showZero> |
21 | 21 | <a href="#" class="demo-badge"></a> |
22 | 22 | </Badge> |
23 | 23 | <Button @click="setCount">set count</Button> |
24 | - | |
24 | + <br><br> | |
25 | + <Badge text="hot"> | |
26 | + <Button type="ghost">Hello</Button> | |
27 | + </Badge> | |
25 | 28 | </div> |
26 | 29 | </template> |
27 | 30 | <script> |
... | ... | @@ -29,7 +32,7 @@ |
29 | 32 | props: {}, |
30 | 33 | data () { |
31 | 34 | return { |
32 | - count: 50 | |
35 | + count: 5 | |
33 | 36 | }; |
34 | 37 | }, |
35 | 38 | methods: { | ... | ... |
examples/routers/cell.vue
... | ... | @@ -2,7 +2,9 @@ |
2 | 2 | <div style="margin: 100px;background: #f8f8f9;padding: 100px;"> |
3 | 3 | <Card title="选项" :padding="0" shadow style="width: 300px;"> |
4 | 4 | <CellGroup @on-click="handleClick"> |
5 | - <Cell title="标题一" name="a1" label="附属内容" to="/button"></Cell> | |
5 | + <Cell title="标题一" name="a1" label="附属内容" to="/button"> | |
6 | + <Badge count="10" slot="extra"></Badge> | |
7 | + </Cell> | |
6 | 8 | <Cell title="标题一" name="a2" label="附属内容" extra="详细信息"></Cell> |
7 | 9 | <Cell title="标题一" name="a3" label="附属内容" extra="详细信息" to="/button"></Cell> |
8 | 10 | <Cell title="标题一" name="a4" label="附属内容" selected></Cell> | ... | ... |
src/components/badge/badge.vue
... | ... | @@ -9,12 +9,13 @@ |
9 | 9 | </span> |
10 | 10 | </template> |
11 | 11 | <script> |
12 | + import { oneOf } from '../../utils/assist'; | |
12 | 13 | const prefixCls = 'ivu-badge'; |
13 | 14 | |
14 | 15 | export default { |
15 | 16 | name: 'Badge', |
16 | 17 | props: { |
17 | - count: [Number, String], | |
18 | + count: Number, | |
18 | 19 | dot: { |
19 | 20 | type: Boolean, |
20 | 21 | default: false |
... | ... | @@ -27,6 +28,18 @@ |
27 | 28 | showZero: { |
28 | 29 | type: Boolean, |
29 | 30 | default: false |
31 | + }, | |
32 | + text: { | |
33 | + type: String, | |
34 | + default: '' | |
35 | + }, | |
36 | + status: { | |
37 | + validator (value) { | |
38 | + return oneOf(value, ['success', 'processing', 'default', 'error', 'warning']); | |
39 | + } | |
40 | + }, | |
41 | + offset: { | |
42 | + type: Array | |
30 | 43 | } |
31 | 44 | }, |
32 | 45 | computed: { |
... | ... | @@ -46,6 +59,7 @@ |
46 | 59 | ]; |
47 | 60 | }, |
48 | 61 | finalCount () { |
62 | + if (this.text !== '') return this.text; | |
49 | 63 | return parseInt(this.count) >= parseInt(this.overflowCount) ? `${this.overflowCount}+` : this.count; |
50 | 64 | }, |
51 | 65 | badge () { |
... | ... | @@ -64,10 +78,12 @@ |
64 | 78 | } |
65 | 79 | } |
66 | 80 | |
81 | + if (this.text !== '') status = true; | |
82 | + | |
67 | 83 | return status || this.showZero; |
68 | 84 | }, |
69 | 85 | hasCount() { |
70 | - if(this.count) return true; | |
86 | + if(this.count || this.text !== '') return true; | |
71 | 87 | if(this.showZero && parseInt(this.count) === 0) return true; |
72 | 88 | else return false; |
73 | 89 | }, | ... | ... |