All files / src/components/u-modal.vue visibleModal.vue

38.46% Statements 5/13
16.66% Branches 1/6
0% Functions 0/3
41.66% Lines 5/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98      7x   7x     7x                   7x                                                                                                                                                              
<script>
import UModalReal from './index.vue';
import i18nMixin from '../../mixins/i18n';
 
const normalizeSlots = (slots, context) => Object.keys(slots)
    .reduce((arr, key) => {
        slots[key].forEach((vnode) => {
            if (!vnode.context) {
                slots[key].context = context;
            }
            if (!vnode.data) {
                vnode.data = {};
            }
            vnode.data.slot = key;
        });
        return arr.concat(slots[key]);
    }, []);
 
export default {
    name: 'u-visible-modal',
    // i18n: UModalReal.i18n,
    mixins: [i18nMixin('u-modal')],
    component: {
        UModalReal,
    },
    props: {
        placeholderInDesigner: String,
    },
    data() {
        return {
            currentVisible: false,
        };
    },
    watch: {
        currentVisible(currentVisible) {
            this.$refs.modal.currentVisible = currentVisible;
        },
    },
    methods: {
        // 双击打开弹出框
        designerDbControl() {
            this.$refs.modal.currentVisible = true;
        },
        closeHandler() {
            this.$refs.modal.currentVisible = false;
        },
        send(data) {
            const dataString = JSON.stringify(data);
            console.info('[vusion:designer] Send: ' + dataString); // (dataString.length > 100 ? dataString.slice(0, 100) + '...' : dataString));
            window.parent.postMessage({ protocol: 'vusion', sender: 'designer', data }, '*');
        },
        getStyle() {
            const { staticStyle = {}, style = {} } = this.$vnode.data;
            return { ...staticStyle, ...style };
        },
    },
    render(h) {
        const ctrlSlot = h('d-ctrl', {
            on: {
                close: this.closeHandler,
            },
        });
        const slots = normalizeSlots(this.$slots, this.$vnode.context) || [];
        const injectSlot = slots.find((item) => item.data.slot === 'inject');
        if (!injectSlot) {
            slots.push(h('template', {
                slot: 'inject',
            }, [ctrlSlot]));
        } else {
            console.error('搭建平台不允许使用此 slot');
        }
        return h('div', {
            style: {
                background: '#FAFAFA',
                border: '1px dashed #C3C3C3',
                height: '40px',
                alignItems: 'center',
                justifyContent: 'center',
                display: 'flex',
                cursor: 'pointer',
            },
        }, [
            h('u-modal-real', {
                class: this.class,
                style: this.getStyle(),
                attrs: this.$attrs,
                props: this.$props,
                on: this.$listeners,
                scopedSlots: this.$scopedSlots,
                ref: 'modal',
            }, slots),
            h('div', {}, [this.placeholderInDesigner]),
        ]);
    },
};
 
</script>