Blame view

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