<template>
    <div style="height: 100%;width: 100%;">
        <comment :is="currentVueComp"/>
    </div>
</template>

<script>
// 批量导入组件

const allComponents = require.context('@/views/generator', false, /\.vue$/)
const generatorVueComp = {}
allComponents.keys().forEach(fileName => {
    const comp = allComponents(fileName)
    generatorVueComp[fileName.replace(/^\.\/(.*)\.\w+$/, '$1')] = comp.default
})
export default {
    name: 'GeneratorPage',
    components: generatorVueComp,
    data() {
        return {
            currentVueComp: '',
        }
    },
    created() {
        this.getComp()
    },
    methods: {
        getComp() {
            let hrefs = window.location.href.split("?");
            if (hrefs.length != 2) {
                return;
            }
            let params = hrefs[1].split("&");

            if (params.length < 1) {
                return;
            }
            for (let i = 0; i < params.length; i++) {
                if (params[i].startsWith("comp=")) {
                    this.currentVueComp = params[i].substring("comp=".length, params[i].length)
                    return;
                }
            }
        }
    }

}
</script>

<style scoped>
</style>
