app-standard-container.vue 3.9 KB
Newer Older
tony001's avatar
tony001 committed
1 2
<template>
    <div :class="curClassName" :style="curStyle">
tony001's avatar
tony001 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
        <template v-if="mutliData && mutliData.length > 0">
            <template v-for="data, index of mutliData">
                <template v-if="containerModel.length > 0">
                    <div v-for="name of containerModel" class="container-item__pos" :style="getItemPosStyle(name)">
                        <slot :name="name" :data="{ index }"></slot>
                    </div>
                </template>
            </template>
        </template>
        <template v-else>
            <template v-if="containerModel.length > 0">
                <div v-for="name of containerModel" class="container-item__pos" :style="getItemPosStyle(name)">
                    <slot :name="name"></slot>
                </div>
            </template>
tony001's avatar
tony001 committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
        </template>
    </div>
</template>

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

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

    /**
     * 下标
     *
     * @type {number}
     * @memberof AppStandardContainer
     */
tony001's avatar
tony001 committed
41
    @Prop() public index?: number;
tony001's avatar
tony001 committed
42 43 44 45 46 47 48 49 50

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

tony001's avatar
tony001 committed
51 52 53 54 55 56 57 58
    /**
     * 是否为多数据容器
     *
     * @type {boolean}
     * @memberof AppStandardContainer
     */
    @Prop() public isMultiContainer!:boolean;

tony001's avatar
tony001 committed
59 60 61 62 63 64 65
    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppStandardContainer
     */
    get itemName() {
tony001's avatar
tony001 committed
66
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
tony001's avatar
tony001 committed
67 68
    }

tony001's avatar
tony001 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82
    /**
     * 多数据容器值
     *
     * @type {*}
     * @memberof AppStandardContainer
     */
    get mutliData() {
        if (this.isMultiContainer && this.isMultiContainer === true) {
            if (this.layoutModelDetails[this.itemName]) {
                return this.layoutModelDetails[this.itemName].getData();
            }
        }
    }

tony001's avatar
tony001 committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    /**
     * 布局模型详情变更
     * @param newVal 
     * @param oldVal 
     */
    @Watch('layoutModelDetails')
    onLayoutModelDetailsChange(newVal: any, oldVal: any) {
        this.initStandardContainer();
    }

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

    /**
     * 初始化常规容器
     *
     * @memberof AppStandardContainer
     */
    public initStandardContainer() {
tony001's avatar
tony001 committed
106
        this.containerModel = [];
tony001's avatar
tony001 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        const curLayoutModel = this.layoutModelDetails[this.itemName];
        if (curLayoutModel && curLayoutModel.details && curLayoutModel.details.length > 0) {
            curLayoutModel.details.forEach((key: string) => {
                this.containerModel.push(key);
            })
        }
    }

    /**
    * 当前容器样式类
    */
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-standard-container ${this.itemName} ${layoutModel.sysCss}`;
        }
    }

    /**
     * 当前容器样式
     */
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
    }

    /**
     * 获取项布局样式
     */
    public getItemPosStyle(name: string) {
        let layoutModel: any;
tony001's avatar
tony001 committed
140
        if ((this.index || this.index === 0)) {
tony001's avatar
tony001 committed
141 142 143 144 145
            layoutModel = this.layoutModelDetails[`${name}_${this.index}`];
        } else {
            layoutModel = this.layoutModelDetails[name];
        }
        if (layoutModel) {
Shine-zwj's avatar
Shine-zwj committed
146
            return layoutModel.getBoxLayOutStyle();
tony001's avatar
tony001 committed
147 148 149 150
        }
    }
}
</script>
151 152
<style lang='scss'>
@import 'app-standard-container.scss';
tony001's avatar
tony001 committed
153
</style>