Blame view

src/components/base/notification/index.js 1001 Bytes
7c15ac9e   梁灏   add Message compo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  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;
      });
  
      const div = document.createElement('div');
      div.innerHTML = `<notification${props}></notification>`;
      document.body.appendChild(div);
  
      const notification = new Vue({
          el: div,
          data: _props,
          components: { Notification }
      }).$children[0];
  
      return {
          notice (noticeProps) {
              notification.add(noticeProps);
          },
6cadeba4   梁灏   support Message
27
28
          remove (name) {
              notification.close(name);
47e58396   梁灏   message component...
29
          },
7c15ac9e   梁灏   add Message compo...
30
31
          component: notification,
          destroy () {
55b608a6   Lawrence Lee   bugfix on .destroy
32
              document.body.removeChild(document.getElementsByClassName('ivu-message')[0].parentElement);
7c15ac9e   梁灏   add Message compo...
33
          }
b0893113   jingsam   :art: add eslint
34
      };
7c15ac9e   梁灏   add Message compo...
35
36
37
  };
  
  export default Notification;