Blame view

src/components/alert/alert.vue 3.02 KB
9d69bab6   梁灏   add Alert component
1
2
  <template>
      <div v-if="!closed" :class="wrapClasses" transition="fade">
14768934   梁灏   fix Alert icon slot
3
4
          <span :class="iconClasses" v-if="showIcon">
              <slot name="icon">
9d69bab6   梁灏   add Alert component
5
                  <Icon :type="iconType"></Icon>
14768934   梁灏   fix Alert icon slot
6
7
              </slot>
          </span>
9d69bab6   梁灏   add Alert component
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
          <span :class="messageClasses"><slot></slot></span>
          <span :class="descClasses" v-el:desc><slot name="desc"></slot></span>
          <a :class="closeClasses" v-if="closable" @click="close">
              <slot name="close">
                  <Icon type="ios-close-empty"></Icon>
              </slot>
          </a>
      </div>
  </template>
  <script>
      import Icon from '../icon';
      import { oneOf } from '../../utils/assist';
  
      const prefixCls = 'ivu-alert';
  
      export default {
          components: { Icon },
          props: {
              type: {
                  validator (value) {
                      return oneOf(value, ['success', 'info', 'warning', 'error']);
                  },
                  default: 'info'
              },
              closable: {
                  type: Boolean,
                  default: false
              },
              showIcon: {
                  type: Boolean,
                  default: false
e49f7963   梁灏   Alert add banner ...
39
40
41
42
43
              },
              banner: {
                  type: Boolean,
                  default: false
              },
9d69bab6   梁灏   add Alert component
44
45
46
47
48
          },
          data () {
              return {
                  closed: false,
                  desc: false
b0893113   jingsam   :art: add eslint
49
              };
9d69bab6   梁灏   add Alert component
50
51
52
53
54
55
56
57
          },
          computed: {
              wrapClasses () {
                  return [
                      `${prefixCls}`,
                      `${prefixCls}-${this.type}`,
                      {
                          [`${prefixCls}-with-icon`]: this.showIcon,
e49f7963   梁灏   Alert add banner ...
58
59
                          [`${prefixCls}-with-desc`]: this.desc,
                          [`${prefixCls}-with-banner`]: this.banner
9d69bab6   梁灏   add Alert component
60
                      }
b0893113   jingsam   :art: add eslint
61
                  ];
9d69bab6   梁灏   add Alert component
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
              },
              messageClasses () {
                  return `${prefixCls}-message`;
              },
              descClasses () {
                  return `${prefixCls}-desc`;
              },
              closeClasses () {
                  return `${prefixCls}-close`;
              },
              iconClasses () {
                  return `${prefixCls}-icon`;
              },
              iconType () {
                  let type = '';
  
                  switch (this.type) {
                      case 'success':
                          type = 'checkmark-circled';
                          break;
                      case 'info':
                          type = 'information-circled';
                          break;
                      case 'warning':
                          type = 'android-alert';
                          break;
                      case 'error':
                          type = 'close-circled';
                          break;
                  }
  
                  return type;
              }
          },
          methods: {
              close (e) {
                  this.closed = true;
                  this.$emit('on-close', e);
              }
          },
          compiled () {
              this.desc = this.$els.desc.innerHTML != '';
          }
b0893113   jingsam   :art: add eslint
105
106
      };
  </script>