Blame view

src/components/poptip/poptip.vue 5.82 KB
9699c270   梁灏   add Poptip component
1
2
3
4
5
6
7
  <template>
      <div
          :class="classes"
          @mouseenter="handleMouseenter"
          @mouseleave="handleMouseleave"
          v-clickoutside="handleClose">
          <div
d6342fe1   jingsam   fixed ie bug
8
              :class="[prefixCls + '-rel']"
9699c270   梁灏   add Poptip component
9
10
11
12
13
14
              v-el:reference
              @click="handleClick"
              @mousedown="handleFocus"
              @mouseup="handleBlur">
              <slot></slot>
          </div>
d6342fe1   jingsam   fixed ie bug
15
16
17
18
19
          <div :class="[prefixCls + '-popper']" :style="styles" transition="fade" v-el:popper v-show="visible">
              <div :class="[prefixCls + '-content']">
                  <div :class="[prefixCls + '-arrow']"></div>
                  <div :class="[prefixCls + '-inner']" v-if="confirm">
                      <div :class="[prefixCls + '-body']">
9699c270   梁灏   add Poptip component
20
                          <i class="ivu-icon ivu-icon-help-circled"></i>
d6342fe1   jingsam   fixed ie bug
21
                          <div :class="[prefixCls + '-body-message']"><slot name="title">{{ title }}</slot></div>
9699c270   梁灏   add Poptip component
22
                      </div>
d6342fe1   jingsam   fixed ie bug
23
                      <div :class="[prefixCls + '-footer']">
66993732   梁灏   update Modal、Poptip
24
                          <i-button type="text" size="small" @click="cancel">{{ cancelText }}</i-button>
d6342fe1   jingsam   fixed ie bug
25
                          <i-button type="primary" size="small" @click="ok">{{ okText }}</i-button>
9699c270   梁灏   add Poptip component
26
27
                      </div>
                  </div>
d6342fe1   jingsam   fixed ie bug
28
                  <div :class="[prefixCls + '-inner']" v-if="!confirm">
3fa1c31e   梁灏   optimize Poptip s...
29
                      <div :class="[prefixCls + '-title']" v-if="showTitle" v-el:title><slot name="title"><div :class="[prefixCls + '-title-inner']">{{ title }}</div></slot></div>
d6342fe1   jingsam   fixed ie bug
30
                      <div :class="[prefixCls + '-body']">
3fa1c31e   梁灏   optimize Poptip s...
31
                          <div :class="[prefixCls + '-body-content']"><slot name="content"><div :class="[prefixCls + '-body-content-inner']">{{ content }}</div></slot></div>
613f5243   梁灏   update Poptip
32
                      </div>
9699c270   梁灏   add Poptip component
33
34
35
36
37
38
39
                  </div>
              </div>
          </div>
      </div>
  </template>
  <script>
      import Popper from '../base/popper';
4b7138b9   梁灏   fixed some bugs
40
      import iButton from '../button/button.vue';
9699c270   梁灏   add Poptip component
41
42
      import clickoutside from '../../directives/clickoutside';
      import { oneOf } from '../../utils/assist';
012cbf28   梁灏   update locale
43
      import { t } from '../../locale';
9699c270   梁灏   add Poptip component
44
45
46
47
48
49
  
      const prefixCls = 'ivu-poptip';
  
      export default {
          mixins: [Popper],
          directives: { clickoutside },
4b7138b9   梁灏   fixed some bugs
50
          components: { iButton },
9699c270   梁灏   add Poptip component
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
          props: {
              trigger: {
                  validator (value) {
                      return oneOf(value, ['click', 'focus', 'hover']);
                  },
                  default: 'click'
              },
              placement: {
                  validator (value) {
                      return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
                  },
                  default: 'top'
              },
              title: {
                  type: [String, Number]
              },
              content: {
                  type: [String, Number],
                  default: ''
              },
              width: {
                  type: [String, Number]
              },
              confirm: {
                  type: Boolean,
                  default: false
              },
              okText: {
                  type: String,
012cbf28   梁灏   update locale
80
81
82
                  default () {
                      return t('i.poptip.okText');
                  }
9699c270   梁灏   add Poptip component
83
84
85
              },
              cancelText: {
                  type: String,
012cbf28   梁灏   update locale
86
87
88
                  default () {
                      return t('i.poptip.cancelText');
                  }
9699c270   梁灏   add Poptip component
89
90
91
92
              }
          },
          data () {
              return {
88bb7c92   梁灏   fix bug of Poptip
93
94
                  prefixCls: prefixCls,
                  showTitle: true
b0893113   jingsam   :art: add eslint
95
              };
9699c270   梁灏   add Poptip component
96
97
98
99
          },
          computed: {
              classes () {
                  return [
4b7138b9   梁灏   fixed some bugs
100
                      `${prefixCls}`,
9699c270   梁灏   add Poptip component
101
                      {
4b7138b9   梁灏   fixed some bugs
102
                          [`${prefixCls}-confirm`]: this.confirm
9699c270   梁灏   add Poptip component
103
                      }
b0893113   jingsam   :art: add eslint
104
                  ];
9699c270   梁灏   add Poptip component
105
106
107
108
              },
              styles () {
                  let style = {};
  
b0893113   jingsam   :art: add eslint
109
                  if (this.width) {
4b7138b9   梁灏   fixed some bugs
110
                      style.width = `${this.width}px`;
9699c270   梁灏   add Poptip component
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                  }
                  return style;
              }
          },
          methods: {
              handleClick () {
                  if (this.confirm) {
                      this.visible = !this.visible;
                      return true;
                  }
                  if (this.trigger !== 'click') {
                      return false;
                  }
                  this.visible = !this.visible;
              },
              handleClose () {
                  if (this.confirm) {
                      this.visible = false;
                      return true;
                  }
                  if (this.trigger !== 'click') {
                      return false;
                  }
                  this.visible = false;
              },
              handleFocus () {
                  if (this.trigger !== 'focus' || this.confirm) {
                      return false;
                  }
                  this.visible = true;
              },
              handleBlur () {
                  if (this.trigger !== 'focus' || this.confirm) {
                      return false;
                  }
                  this.visible = false;
              },
              handleMouseenter () {
                  if (this.trigger !== 'hover' || this.confirm) {
                      return false;
                  }
                  this.visible = true;
              },
              handleMouseleave () {
                  if (this.trigger !== 'hover' || this.confirm) {
                      return false;
                  }
                  this.visible = false;
              },
              cancel () {
                  this.visible = false;
                  this.$emit('on-cancel');
              },
              ok () {
                  this.visible = false;
                  this.$emit('on-ok');
              }
88bb7c92   梁灏   fix bug of Poptip
168
169
170
          },
          ready () {
              if (!this.confirm) {
3fa1c31e   梁灏   optimize Poptip s...
171
                  this.showTitle = this.$els.title.innerHTML != `<div class="${prefixCls}-title-inner"></div>`;
88bb7c92   梁灏   fix bug of Poptip
172
              }
9699c270   梁灏   add Poptip component
173
          }
b0893113   jingsam   :art: add eslint
174
      };
d6342fe1   jingsam   fixed ie bug
175
  </script>