Blame view

src/components/modal/index.js 1.37 KB
be966e9f   梁灏   add Modal component
1
2
3
4
  import Modal from './confirm';
  
  let modalInstance;
  
3ef24d5f   Aresn   $Modal support re...
5
  function getModalInstance (render = undefined) {
be966e9f   梁灏   add Modal component
6
7
8
      modalInstance = modalInstance || Modal.newInstance({
          closable: false,
          maskClosable: false,
3ef24d5f   Aresn   $Modal support re...
9
10
          footerHide: true,
          render: render
be966e9f   梁灏   add Modal component
11
12
13
14
15
16
      });
  
      return modalInstance;
  }
  
  function confirm (options) {
3ef24d5f   Aresn   $Modal support re...
17
18
      const render = ('render' in options) ? options.render : undefined;
      let instance  = getModalInstance(render);
be966e9f   梁灏   add Modal component
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  
      options.onRemove = function () {
          modalInstance = null;
      };
  
      instance.show(options);
  }
  
  Modal.info = function (props = {}) {
      props.icon = 'info';
      props.showCancel = false;
      return confirm(props);
  };
  
  Modal.success = function (props = {}) {
      props.icon = 'success';
      props.showCancel = false;
      return confirm(props);
  };
  
  Modal.warning = function (props = {}) {
      props.icon = 'warning';
      props.showCancel = false;
      return confirm(props);
  };
  
  Modal.error = function (props = {}) {
      props.icon = 'error';
      props.showCancel = false;
      return confirm(props);
  };
  
  Modal.confirm = function (props = {}) {
      props.icon = 'confirm';
      props.showCancel = true;
      return confirm(props);
  };
  
  Modal.remove = function () {
      if (!modalInstance) {   // at loading status, remove after Cancel
          return false;
      }
  
      const instance = getModalInstance();
  
      instance.remove();
  };
  
  export default Modal;