Blame view

src/components/base/notification/index.js 1.11 KB
7c15ac9e   梁灏   add Message compo...
1
2
3
4
5
6
7
8
9
10
11
12
  import Notification from './notification.vue';
  import Vue from 'vue';
  import { camelcaseToHyphen } from '../../../utils/assist';
  
  Notification.newInstance = properties => {
      const _props = properties || {};
  
      let props = '';
      Object.keys(_props).forEach(prop => {
          props += ' :' + camelcaseToHyphen(prop) + '=' + prop;
      });
  
e8e1677b   Aresn   Message & Notice ...
13
      const Instance = new Vue({
7c15ac9e   梁灏   add Message compo...
14
          data: _props,
e8e1677b   Aresn   Message & Notice ...
15
16
17
18
19
20
21
22
23
24
          render (h) {
              return h(Notification, {
                  props: _props
              })
          }
      });
  
      const component = Instance.$mount();
      document.body.appendChild(component.$el);
      const notification = Instance.$children[0];
7c15ac9e   梁灏   add Message compo...
25
26
27
28
29
  
      return {
          notice (noticeProps) {
              notification.add(noticeProps);
          },
6cadeba4   梁灏   support Message
30
31
          remove (name) {
              notification.close(name);
47e58396   梁灏   message component...
32
          },
7c15ac9e   梁灏   add Message compo...
33
34
          component: notification,
          destroy () {
17628aab   Lawrence Lee   bugfix on message
35
36
37
38
              notification.closeAll();
              setTimeout(function() {
                  document.body.removeChild(document.getElementsByClassName('ivu-message')[0].parentElement);
              }, 500);
7c15ac9e   梁灏   add Message compo...
39
          }
b0893113   jingsam   :art: add eslint
40
      };
7c15ac9e   梁灏   add Message compo...
41
42
43
  };
  
  export default Notification;