app-tab-panel.vue 2.7 KB
<template>
    <Tabs v-model="activeName" @on-click="handleClick" :name="name" :class="curClassName">
        <template v-if="containerModel.length > 0">
            <template v-for="name of containerModel">
                <slot :name="name"></slot>
            </template>
        </template>
    </Tabs>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({})
export default class AppTabPanel extends Vue {
    /**
    * 名称
    *
    * @type {string}
    * @memberof AppTabPanel
    */
    @Prop() public name!: string;

    /**
     * 布局模型详情
     *
     * @type {*}
     * @memberof AppTabPanel
     */
    @Prop() public layoutModelDetails: any;

    /**
     * 当前布局模型
     *
     * @type {*}
     * @memberof AppTabPanel
     */
    public currentLayoutModel: any;

    /**
     * 插槽对象
     *
     * @memberof AppTabPanel
     */
    public containerModel: any[] = [];

    /**
     * 当前激活项
     *
     * @memberof AppTabPanel
     */
    public activeName: string = '';

    /**
     * 组件初始化
     *
     * @memberof AppTabPanel
     */
    public created() {
        this.initTabPage();
    }

    /**
     * 初始化分页
     *
     * @memberof AppTabPanel
     */
    public initTabPage() {
        this.currentLayoutModel = this.layoutModelDetails[this.name];
        if (this.currentLayoutModel && this.currentLayoutModel.details && this.currentLayoutModel.details.length > 0) {
            this.currentLayoutModel.details.forEach((key: string) => {
                this.containerModel.push(key);
            })
        }
        this.activeName = this.containerModel && this.containerModel.length > 0 ? this.containerModel[0] : '';
        this.layoutModelDetails[this.name].clickPage(this.activeName);
    }

    /**
     * 处理分页点击
     *
     * @memberof AppTabPanel
     */
    public handleClick(tab: any) {
        this.layoutModelDetails[this.name].clickPage(tab);
    }

    /**
     * 当前容器类名
     *
     * @memberof AppTabPanel
     */
    get curClassName() {
        return {
            'app-tab-panel': true,
            [this.name]: true,
            [this.currentLayoutModel.sysCss]: this.currentLayoutModel.sysCss ? true : false
        }
    }

    /**
     * 当前容器样式
     *
     * @memberof AppTabPanel
     */
    get curStyle() {
        if (this.currentLayoutModel) {
            return this.currentLayoutModel.getElementStyle();
        }
        return '';
    }
}
</script>
<style lang='less'>
@import './app-tab-panel.less';
</style>