Blame view

src/components/badge/badge.vue 3.81 KB
7fa943eb   梁灏   init
1
  <template>
15368be1   梁灏   Support Badge
2
      <span v-if="dot" :class="classes" ref="badge">
7fa943eb   梁灏   init
3
          <slot></slot>
457fe087   梁灏   update Badge style
4
          <sup :class="dotClasses" :style="styles" v-show="badge"></sup>
7fa943eb   梁灏   init
5
      </span>
0823f88b   梁灏   Badge add status
6
7
8
9
      <span v-else-if="status" :class="classes" class="ivu-badge-status" ref="badge">
          <span :class="statusClasses"></span>
          <span class="ivu-badge-status-text">{{ text }}</span>
      </span>
15368be1   梁灏   Support Badge
10
      <span v-else :class="classes" ref="badge">
7fa943eb   梁灏   init
11
          <slot></slot>
457fe087   梁灏   update Badge style
12
          <sup v-if="hasCount" :style="styles" :class="countClasses" v-show="badge">{{ finalCount }}</sup>
7fa943eb   梁灏   init
13
14
15
      </span>
  </template>
  <script>
fdafcd2c   梁灏   Badge add text prop
16
      import { oneOf } from '../../utils/assist';
7fa943eb   梁灏   init
17
18
19
      const prefixCls = 'ivu-badge';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
20
          name: 'Badge',
7fa943eb   梁灏   init
21
          props: {
fdafcd2c   梁灏   Badge add text prop
22
              count: Number,
7fa943eb   梁灏   init
23
24
25
26
27
28
29
30
              dot: {
                  type: Boolean,
                  default: false
              },
              overflowCount: {
                  type: [Number, String],
                  default: 99
              },
d3905b35   xiaofengsha   Badge 组件增加 showZe...
31
32
33
34
              className: String,
              showZero: {
                  type: Boolean,
                  default: false
fdafcd2c   梁灏   Badge add text prop
35
36
37
38
39
40
41
42
43
44
              },
              text: {
                  type: String,
                  default: ''
              },
              status: {
                  validator (value) {
                      return oneOf(value, ['success', 'processing', 'default', 'error', 'warning']);
                  }
              },
cc27c42a   梁灏   Badge add type pr...
45
46
47
48
49
              type: {
                  validator (value) {
                      return oneOf(value, ['success', 'primary', 'normal', 'error', 'warning', 'info']);
                  }
              },
fdafcd2c   梁灏   Badge add text prop
50
51
              offset: {
                  type: Array
d3905b35   xiaofengsha   Badge 组件增加 showZe...
52
              }
7fa943eb   梁灏   init
53
54
55
56
57
58
59
60
61
62
63
64
          },
          computed: {
              classes () {
                  return `${prefixCls}`;
              },
              dotClasses () {
                  return `${prefixCls}-dot`;
              },
              countClasses () {
                  return [
                      `${prefixCls}-count`,
                      {
15368be1   梁灏   Support Badge
65
                          [`${this.className}`]: !!this.className,
cc27c42a   梁灏   Badge add type pr...
66
67
                          [`${prefixCls}-count-alone`]: this.alone,
                          [`${prefixCls}-count-${this.type}`]: !!this.type
7fa943eb   梁灏   init
68
                      }
b0893113   jingsam   :art: add eslint
69
                  ];
7fa943eb   梁灏   init
70
              },
0823f88b   梁灏   Badge add status
71
72
73
74
75
76
77
78
              statusClasses () {
                  return [
                      `${prefixCls}-status-dot`,
                      {
                          [`${prefixCls}-status-${this.status}`]: !!this.status
                      }
                  ];
              },
457fe087   梁灏   update Badge style
79
80
81
82
83
84
85
86
              styles () {
                  const style = {};
                  if (this.offset && this.offset.length === 2) {
                      style['margin-top'] = `${this.offset[0]}px`;
                      style['margin-right'] = `${this.offset[1]}px`;
                  }
                  return style;
              },
7fa943eb   梁灏   init
87
              finalCount () {
fdafcd2c   梁灏   Badge add text prop
88
                  if (this.text !== '') return this.text;
7fa943eb   梁灏   init
89
90
91
92
93
94
95
96
97
98
99
                  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
100
                      if (this.count !== null) {
7fa943eb   梁灏   init
101
102
103
104
105
106
                          if (parseInt(this.count) === 0) {
                              status = false;
                          }
                      }
                  }
  
fdafcd2c   梁灏   Badge add text prop
107
108
                  if (this.text !== '') status = true;
  
d3905b35   xiaofengsha   Badge 组件增加 showZe...
109
110
111
                  return status || this.showZero;
              },
              hasCount() {
fdafcd2c   梁灏   Badge add text prop
112
                  if(this.count || this.text !== '') return true;
d3905b35   xiaofengsha   Badge 组件增加 showZe...
113
114
                  if(this.showZero && parseInt(this.count) === 0) return true;
                  else return false;
75c32564   Aresn   fixed #646
115
116
117
              },
              alone () {
                  return this.$slots.default === undefined;
7fa943eb   梁灏   init
118
119
              }
          }
b0893113   jingsam   :art: add eslint
120
121
      };
  </script>