Blame view

components/base/notification/index.js 938 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);
          },
47e58396   梁灏   message component...
27
28
29
          remove (key) {
              notification.close(key);
          },
7c15ac9e   梁灏   add Message compo...
30
31
32
33
34
35
36
37
          component: notification,
          destroy () {
              document.body.removeChild(div);
          }
      }
  };
  
  export default Notification;