All files / src/components/m-modal.vue index.vue

32.14% Statements 9/28
12.5% Branches 1/8
0% Functions 0/7
34.61% Lines 9/26

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      7x     7x         7x                                                                  
<template>
<u-modal :visible.sync="visible">Modal Mixin</u-modal>
</template>
 
<script>
export default {
    name: 'm-modal',
    /**
     * 设置弹窗是否需要 reset
     */
    resetModal: true,
    data() {
        return {
            visible: false,
        };
    },
    watch: {
        visible(visible) {
            if (this.$options.resetModal && !visible)
                this.reset();
        },
    },
    methods: {
        open(data) {
            Object.assign(this, data);
            this.visible = true;
            this.$emit('open', data);
        },
        close(data) {
            Object.assign(this, data);
            this.visible = false;
            this.$emit('close', data);
        },
        reset() {
            const staticData = Array.from(this.$options.staticData || []);
            const resetData = this.$options.data.apply(this);
            staticData.push('visible');
            for (const name of staticData)
                delete resetData[name];
            Object.assign(this.$data, resetData);
        },
    },
};
</script>