index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import modal from './modal';
  2. import {
  3. isArray,
  4. isFunction,
  5. isPlainObject,
  6. isString,
  7. forEach
  8. } from 'lodash-es';
  9. export default {
  10. install(G1o) {
  11. G1o.component('modal', modal);
  12. G1o.prototype.$Modal = ({
  13. ok = function() {},
  14. cancel = function() {},
  15. close = function() {},
  16. closeable = true,
  17. visible = false,
  18. transition = 'up',
  19. large,
  20. transparent,
  21. position = 'flex',
  22. flex = position === 'flex',
  23. styles,
  24. modalStyles,
  25. mask,
  26. opacity,
  27. store,
  28. router,
  29. data,
  30. children: cjk = [],
  31. target,
  32. single
  33. } = {}) => {
  34. let h4k = document.createElement('div');
  35. if (
  36. !target ||
  37. !Object.prototype.toString.call(target).indexOf('HTML') > -1 ||
  38. target.nodeType !== 1
  39. ) {
  40. target = document.body;
  41. }
  42. target.appendChild(h4k);
  43. const _ = new G1o({
  44. el: h4k,
  45. store,
  46. router,
  47. data,
  48. render: function(q7e) {
  49. return q7e(
  50. modal,
  51. {
  52. props: {
  53. global: true,
  54. styles,
  55. modalStyles,
  56. transition,
  57. large,
  58. transparent,
  59. position,
  60. flex,
  61. closeable,
  62. visible,
  63. mask,
  64. opacity,
  65. target,
  66. single
  67. },
  68. on: {
  69. ok,
  70. cancel,
  71. close
  72. },
  73. ref: 'modal'
  74. },
  75. b3h(q7e, cjk, this.$data)
  76. );
  77. },
  78. created() {
  79. this.target = target;
  80. },
  81. methods: {
  82. remove() {
  83. this.$destroy();
  84. },
  85. open(data) {
  86. this.$refs.modal.open(data);
  87. },
  88. close() {
  89. this.$refs.modal.close();
  90. },
  91. ok(data) {
  92. this.$refs.modal.ok(data);
  93. },
  94. cancel(data) {
  95. this.$refs.modal.cancel(data);
  96. }
  97. },
  98. destroyed() {
  99. this.target = null;
  100. h4k = null;
  101. }
  102. });
  103. // return $children[0];
  104. return _;
  105. };
  106. function b3h(g4r, n8y, v2t) {
  107. const a3e = [];
  108. if (!isArray(n8y)) {
  109. n8y = [n8y];
  110. }
  111. forEach(n8y, (p0i, key) => {
  112. const g4j = j98(g4r, p0i, v2t);
  113. !!g4j && a3e.push(g4j);
  114. });
  115. return a3e;
  116. }
  117. function j98(i8u, kk3, n37) {
  118. switch (true) {
  119. case isFunction(kk3):
  120. return kk3(i8u, n37);
  121. case isString(kk3):
  122. return kk3;
  123. case isPlainObject(kk3):
  124. if (kk3._scopeId) {
  125. return i8u(kk3, { props: Object.assign({}, n37) });
  126. } else if (kk3.component) {
  127. kk3.options = kk3.options || {};
  128. kk3.options.props = Object.assign(kk3.options.props || {}, n37);
  129. return i8u(kk3.component, kk3.options, b3h(i8u, kk3.children, n37));
  130. }
  131. return null;
  132. case isArray(kk3):
  133. kk3 = [].slice.apply(kk3);
  134. if (!kk3[1] || isPlainObject(kk3[1])) {
  135. kk3[1] = kk3[1] || {};
  136. kk3[1].props = Object.assign(kk3[1].props || {}, n37);
  137. }
  138. return i8u.apply(null, kk3);
  139. default:
  140. return null;
  141. }
  142. }
  143. }
  144. };