app-scroll-container.vue 7.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<template>
    <div :class="curClassName" :style="curStyle">
        <div v-if="containerModel.NORTH" :style="containerModel.NORTH.style"
            class="no-style overflow-auto app-scroll-container__header">
            <div v-for="name of containerModel.NORTH.name" class="container-item__pos">
                <slot :name="name"></slot>
            </div>
        </div>
        <div class="app-scroll-container__middle" :style="middleContainerStyle">
            <div v-if="containerModel.WEST" :style="containerModel.WEST.style"
                class="no-style overflow-auto app-scroll-container__left">
12
                <div v-for="name of containerModel.WEST.name" class="container-item__pos" :style="getItemPosStyle(name)">
13 14 15 16 17 18 19 20 21 22 23
                    <slot :name="name"></slot>
                </div>
            </div>
            <div v-if="containerModel.CENTER" :style="containerModel.CENTER.style"
                class="no-style overflow-auto app-scroll-container__center">
                <div v-for="name of containerModel.CENTER.name" class="container-item__pos" :style="getItemPosStyle(name)">
                    <slot :name="name"></slot>
                </div>
            </div>
            <div v-if="containerModel.EAST" :style="containerModel.EAST.style"
                class="no-style overflow-auto app-scroll-container__right">
24
                <div v-for="name of containerModel.EAST.name" class="container-item__pos" :style="getItemPosStyle(name)">
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
                    <slot :name="name"></slot>
                </div>
            </div>
        </div>
        <div v-if="containerModel.SOUTH" :style="containerModel.SOUTH.style"
            class="no-style overflow-auto app-scroll-container__bottom">
            <div v-for="name of containerModel.SOUTH.name" class="container-item__pos">
                <slot :name="name"></slot>
            </div>
        </div>
    </div>
</template>

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

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

    /**
     * 下标
     *
     * @type {number}
     * @memberof AppScrollContainer
     */
58
    @Prop() public index?: number;
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

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

    /**
     * 布局模型详情变更
     * @param newVal 
     * @param oldVal 
     */
    @Watch('layoutModelDetails')
    onLayoutModelDetailsChange(newVal: any, oldVal: any) {
        this.initScrollContainer();
    }

    /**
     * 插槽对象
     *
     * @memberof AppScrollContainer
     */
    public containerModel: any = {};

    /**
     * 中间区域样式
     *
     * @memberof AppScrollContainer
     */
    public middleContainerStyle: any = {};

    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppScrollContainer
     */
    get itemName() {
99
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
100 101 102 103 104 105 106 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
    }

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

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

    /**
     * 初始化滚动容器
     *
     * @memberof AppScrollContainer
     */
    public initScrollContainer() {      
        let minusHeight = '';
        let minusWidth: string = '';
        this.containerModel = {};
        const curLayoutModel = this.layoutModelDetails[this.itemName];
        if (curLayoutModel && curLayoutModel.details && curLayoutModel.details.length > 0) {
            curLayoutModel.details.forEach((key: string) => {
                let childModelDetail: any;
135
                if (this.index || this.index === 0) {
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    childModelDetail = this.layoutModelDetails[`${key}_${this.index}`];
                } else {
                    childModelDetail = this.layoutModelDetails[key];
                }
                if (childModelDetail) {
                    const { name, layoutWidth, widthMode, layoutHeight, heightMode, layoutPos } = childModelDetail;
                    const style = {};
                    if (layoutWidth) {
                        if (layoutPos && (Object.is(layoutPos, 'WEST') || Object.is(layoutPos, 'EAST'))) {
                            Object.assign(style, { width: Util.getBoxSize('WIDTH', widthMode, layoutWidth).width });
                            minusWidth += ` - ${Util.getBoxSize('WIDTH', widthMode, layoutWidth).width}`;
                        }
                    }
                    if (layoutHeight) {
                        if (layoutPos && (Object.is(layoutPos, 'NORTH') || Object.is(layoutPos, 'SOUTH'))) {
                            Object.assign(style, { height: Util.getBoxSize('HEIGHT', heightMode, layoutHeight).height });
                            minusHeight += ` - ${Util.getBoxSize('HEIGHT', heightMode, layoutHeight).height}`;
                        }
                    }
                    if (this.containerModel.hasOwnProperty(layoutPos)) {
                        Object.assign(this.containerModel[layoutPos], { style });
                        this.containerModel[layoutPos].name.push(name);
                    } else {
                        this.containerModel[layoutPos] = { style, name: [name] };
                    }
                }
            });
        }
        this.middleContainerStyle.height = minusHeight ? `calc(100%${minusHeight})` : '100%';
        if (this.containerModel.CENTER) {
            this.containerModel.CENTER.style.width = minusWidth ? `calc(100%${minusWidth})` : '100%';
        }
    }

    /**
     *  获取项布局样式
     */
    public getItemPosStyle(name: string) {
174
        const itemName = (this.index || this.index === 0) ? `${name}_${this.index}` : name;
175 176
        let layoutModel = this.layoutModelDetails[itemName];
        if (layoutModel) {
177 178 179
            const childBoxSizeStyle: any = layoutModel.getBoxSizeStyle();
            const boxSizeStyle: any = {};
            if (!childBoxSizeStyle.width) {
180 181
                Object.assign(boxSizeStyle, { 'width': '100%' });
            }
182
            if (!childBoxSizeStyle.height) {
183
                Object.assign(boxSizeStyle, { 'height': '100%' });
184 185
            } else {
                Object.assign(boxSizeStyle, { 'display': 'contents' });
186 187 188 189 190 191 192 193 194 195 196 197
            }
            if (!layoutModel.visible) {
                Object.assign(boxSizeStyle, { display: 'none' })
            }
            return boxSizeStyle;
        }
    }
}
</script>
<style lang='less'>
@import 'app-scroll-container.less';
</style>