index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = exports.Modal = exports.modal = void 0;
  7. var _xeUtils = _interopRequireDefault(require("xe-utils"));
  8. var _modal = _interopRequireWildcard(require("./src/modal"));
  9. var _vXETable = _interopRequireDefault(require("../v-x-e-table"));
  10. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. /* eslint-disable @typescript-eslint/no-use-before-define */
  14. var ModalClass = null;
  15. function openModal(opts) {
  16. var options = Object.assign({}, opts, {
  17. transfer: true
  18. });
  19. return new Promise(function (resolve) {
  20. if (options && options.id && _modal.allActivedModals.some(function (comp) {
  21. return comp.id === options.id;
  22. })) {
  23. resolve('exist');
  24. } else {
  25. var events = options.events || {};
  26. options.events = Object.assign({}, events, {
  27. hide: function hide(params) {
  28. if (events.hide) {
  29. events.hide.call(this, params);
  30. }
  31. setTimeout(function () {
  32. return $modal.$destroy();
  33. }, $modal.isMsg ? 500 : 100);
  34. resolve(params.type);
  35. }
  36. });
  37. var $modal = new ModalClass({
  38. el: document.createElement('div'),
  39. propsData: options
  40. });
  41. setTimeout(function () {
  42. if ($modal.isDestroy) {
  43. $modal.close();
  44. } else {
  45. $modal.open();
  46. }
  47. });
  48. }
  49. });
  50. }
  51. /**
  52. * 全局关闭动态的活动窗口(只能用于关闭动态的创建的活动窗口)
  53. * 如果传 id 则关闭指定的窗口
  54. * 如果不传则关闭所有窗口
  55. */
  56. function closeModal(id) {
  57. var modals = arguments.length ? [getModal(id)] : _modal.allActivedModals;
  58. modals.forEach(function ($modal) {
  59. if ($modal) {
  60. $modal.isDestroy = true;
  61. $modal.close('close');
  62. }
  63. });
  64. return Promise.resolve();
  65. }
  66. function getModal(id) {
  67. return _xeUtils.default.find(_modal.allActivedModals, function ($modal) {
  68. return $modal.id === id;
  69. });
  70. }
  71. var ModalController = {
  72. get: getModal,
  73. close: closeModal,
  74. open: openModal
  75. };
  76. var modal = ModalController;
  77. exports.modal = modal;
  78. var shortcutTypes = ['alert', 'confirm', 'message'];
  79. shortcutTypes.forEach(function (type, index) {
  80. var defOpts = index === 2 ? {
  81. mask: false,
  82. lockView: false,
  83. showHeader: false
  84. } : {
  85. showFooter: true
  86. };
  87. defOpts.type = type;
  88. defOpts.dblclickZoom = false;
  89. if (index === 1) {
  90. defOpts.status = 'question';
  91. }
  92. ModalController[type] = function (message, title, options) {
  93. var opts;
  94. if (_xeUtils.default.isObject(message)) {
  95. opts = message;
  96. } else {
  97. if (title) {
  98. opts = index === 2 ? {
  99. status: title
  100. } : {
  101. title: title
  102. };
  103. }
  104. }
  105. return openModal(Object.assign({
  106. message: _xeUtils.default.toValueString(message),
  107. type: type
  108. }, defOpts, opts, options));
  109. };
  110. });
  111. var Modal = Object.assign(_modal.default, {
  112. install: function install(Vue) {
  113. _vXETable.default._modal = 1;
  114. Vue.component(_modal.default.name, _modal.default);
  115. ModalClass = Vue.extend(_modal.default);
  116. _vXETable.default.modal = ModalController;
  117. if (!Vue.prototype.$vxe) {
  118. Vue.prototype.$vxe = {
  119. modal: ModalController
  120. };
  121. } else {
  122. Vue.prototype.$vxe.modal = ModalController;
  123. }
  124. }
  125. });
  126. exports.Modal = Modal;
  127. var _default = Modal;
  128. exports.default = _default;