7fa943eb
梁灏
init
|
1
|
<template>
|
15368be1
梁灏
Support Badge
|
2
|
<span v-if="dot" :class="classes" ref="badge">
|
7fa943eb
梁灏
init
|
3
4
5
|
<slot></slot>
<sup :class="dotClasses" v-show="badge"></sup>
</span>
|
15368be1
梁灏
Support Badge
|
6
|
<span v-else :class="classes" ref="badge">
|
7fa943eb
梁灏
init
|
7
|
<slot></slot>
|
d3905b35
xiaofengsha
Badge 组件增加 showZe...
|
8
|
<sup v-if="hasCount" :class="countClasses" v-show="badge">{{ finalCount }}</sup>
|
7fa943eb
梁灏
init
|
9
10
11
|
</span>
</template>
<script>
|
fdafcd2c
梁灏
Badge add text prop
|
12
|
import { oneOf } from '../../utils/assist';
|
7fa943eb
梁灏
init
|
13
14
15
|
const prefixCls = 'ivu-badge';
export default {
|
34ee7b4a
梁灏
support Tree & ad...
|
16
|
name: 'Badge',
|
7fa943eb
梁灏
init
|
17
|
props: {
|
fdafcd2c
梁灏
Badge add text prop
|
18
|
count: Number,
|
7fa943eb
梁灏
init
|
19
20
21
22
23
24
25
26
|
dot: {
type: Boolean,
default: false
},
overflowCount: {
type: [Number, String],
default: 99
},
|
d3905b35
xiaofengsha
Badge 组件增加 showZe...
|
27
28
29
30
|
className: String,
showZero: {
type: Boolean,
default: false
|
fdafcd2c
梁灏
Badge add text prop
|
31
32
33
34
35
36
37
38
39
40
41
42
|
},
text: {
type: String,
default: ''
},
status: {
validator (value) {
return oneOf(value, ['success', 'processing', 'default', 'error', 'warning']);
}
},
offset: {
type: Array
|
d3905b35
xiaofengsha
Badge 组件增加 showZe...
|
43
|
}
|
7fa943eb
梁灏
init
|
44
45
46
47
48
49
50
51
52
53
54
55
|
},
computed: {
classes () {
return `${prefixCls}`;
},
dotClasses () {
return `${prefixCls}-dot`;
},
countClasses () {
return [
`${prefixCls}-count`,
{
|
15368be1
梁灏
Support Badge
|
56
|
[`${this.className}`]: !!this.className,
|
7fa943eb
梁灏
init
|
57
58
|
[`${prefixCls}-count-alone`]: this.alone
}
|
b0893113
jingsam
add eslint
|
59
|
];
|
7fa943eb
梁灏
init
|
60
61
|
},
finalCount () {
|
fdafcd2c
梁灏
Badge add text prop
|
62
|
if (this.text !== '') return this.text;
|
7fa943eb
梁灏
init
|
63
64
65
66
67
68
69
70
71
72
73
|
return parseInt(this.count) >= parseInt(this.overflowCount) ? `${this.overflowCount}+` : this.count;
},
badge () {
let status = false;
if (this.count) {
status = !(parseInt(this.count) === 0);
}
if (this.dot) {
status = true;
|
f575eca7
Lison
update badge.vue
|
74
|
if (this.count !== null) {
|
7fa943eb
梁灏
init
|
75
76
77
78
79
80
|
if (parseInt(this.count) === 0) {
status = false;
}
}
}
|
fdafcd2c
梁灏
Badge add text prop
|
81
82
|
if (this.text !== '') status = true;
|
d3905b35
xiaofengsha
Badge 组件增加 showZe...
|
83
84
85
|
return status || this.showZero;
},
hasCount() {
|
fdafcd2c
梁灏
Badge add text prop
|
86
|
if(this.count || this.text !== '') return true;
|
d3905b35
xiaofengsha
Badge 组件增加 showZe...
|
87
88
|
if(this.showZero && parseInt(this.count) === 0) return true;
else return false;
|
75c32564
Aresn
fixed #646
|
89
90
91
|
},
alone () {
return this.$slots.default === undefined;
|
7fa943eb
梁灏
init
|
92
93
|
}
}
|
b0893113
jingsam
add eslint
|
94
95
|
};
</script>
|