123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import modal from './modal';
- import {
- isArray,
- isFunction,
- isPlainObject,
- isString,
- forEach
- } from 'lodash-es';
- export default {
- install(G1o) {
- G1o.component('modal', modal);
- G1o.prototype.$Modal = ({
- ok = function() {},
- cancel = function() {},
- close = function() {},
- closeable = true,
- visible = false,
- transition = 'up',
- large,
- transparent,
- position = 'flex',
- flex = position === 'flex',
- styles,
- modalStyles,
- mask,
- opacity,
- store,
- router,
- data,
- children: cjk = [],
- target,
- single
- } = {}) => {
- let h4k = document.createElement('div');
- if (
- !target ||
- !Object.prototype.toString.call(target).indexOf('HTML') > -1 ||
- target.nodeType !== 1
- ) {
- target = document.body;
- }
- target.appendChild(h4k);
- const _ = new G1o({
- el: h4k,
- store,
- router,
- data,
- render: function(q7e) {
- return q7e(
- modal,
- {
- props: {
- global: true,
- styles,
- modalStyles,
- transition,
- large,
- transparent,
- position,
- flex,
- closeable,
- visible,
- mask,
- opacity,
- target,
- single
- },
- on: {
- ok,
- cancel,
- close
- },
- ref: 'modal'
- },
- b3h(q7e, cjk, this.$data)
- );
- },
- created() {
- this.target = target;
- },
- methods: {
- remove() {
- this.$destroy();
- },
- open(data) {
- this.$refs.modal.open(data);
- },
- close() {
- this.$refs.modal.close();
- },
- ok(data) {
- this.$refs.modal.ok(data);
- },
- cancel(data) {
- this.$refs.modal.cancel(data);
- }
- },
- destroyed() {
- this.target = null;
- h4k = null;
- }
- });
- // return $children[0];
- return _;
- };
- function b3h(g4r, n8y, v2t) {
- const a3e = [];
- if (!isArray(n8y)) {
- n8y = [n8y];
- }
- forEach(n8y, (p0i, key) => {
- const g4j = j98(g4r, p0i, v2t);
- !!g4j && a3e.push(g4j);
- });
- return a3e;
- }
- function j98(i8u, kk3, n37) {
- switch (true) {
- case isFunction(kk3):
- return kk3(i8u, n37);
- case isString(kk3):
- return kk3;
- case isPlainObject(kk3):
- if (kk3._scopeId) {
- return i8u(kk3, { props: Object.assign({}, n37) });
- } else if (kk3.component) {
- kk3.options = kk3.options || {};
- kk3.options.props = Object.assign(kk3.options.props || {}, n37);
- return i8u(kk3.component, kk3.options, b3h(i8u, kk3.children, n37));
- }
- return null;
- case isArray(kk3):
- kk3 = [].slice.apply(kk3);
- if (!kk3[1] || isPlainObject(kk3[1])) {
- kk3[1] = kk3[1] || {};
- kk3[1].props = Object.assign(kk3[1].props || {}, n37);
- }
- return i8u.apply(null, kk3);
- default:
- return null;
- }
- }
- }
- };
|