app-scroll-container.vue 7.0 KB
Newer Older
tony001's avatar
tony001 committed
1
<template>
tony001's avatar
tony001 committed
2
    <div :class="curClassName" :style="curStyle">
tony001's avatar
tony001 committed
3 4
        <div v-if="containerModel.NORTH" :style="containerModel.NORTH.style"
            class="no-style overflow-auto app-scroll-container__header">
tony001's avatar
tony001 committed
5
            <div v-for="name of containerModel.NORTH.name" class="container-item__pos">
tony001's avatar
tony001 committed
6
                <slot :name="name"></slot>
tony001's avatar
tony001 committed
7
            </div>
tony001's avatar
tony001 committed
8 9
        </div>
        <div class="app-scroll-container__middle" :style="middleContainerStyle">
tony001's avatar
tony001 committed
10 11
            <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)">
tony001's avatar
tony001 committed
13
                    <slot :name="name"></slot>
tony001's avatar
tony001 committed
14
                </div>
tony001's avatar
tony001 committed
15
            </div>
tony001's avatar
tony001 committed
16 17
            <div v-if="containerModel.CENTER" :style="containerModel.CENTER.style"
                class="no-style overflow-auto app-scroll-container__center">
tony001's avatar
tony001 committed
18
                <div v-for="name of containerModel.CENTER.name" class="container-item__pos" :style="getItemPosStyle(name)">
tony001's avatar
tony001 committed
19
                    <slot :name="name"></slot>
tony001's avatar
tony001 committed
20
                </div>
tony001's avatar
tony001 committed
21
            </div>
tony001's avatar
tony001 committed
22 23
            <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)">
tony001's avatar
tony001 committed
25
                    <slot :name="name"></slot>
tony001's avatar
tony001 committed
26
                </div>
tony001's avatar
tony001 committed
27 28
            </div>
        </div>
tony001's avatar
tony001 committed
29 30
        <div v-if="containerModel.SOUTH" :style="containerModel.SOUTH.style"
            class="no-style overflow-auto app-scroll-container__bottom">
tony001's avatar
tony001 committed
31
            <div v-for="name of containerModel.SOUTH.name" class="container-item__pos">
tony001's avatar
tony001 committed
32
                <slot :name="name"></slot>
tony001's avatar
tony001 committed
33
            </div>
tony001's avatar
tony001 committed
34 35 36 37 38
        </div>
    </div>
</template>

<script lang="ts">
tony001's avatar
tony001 committed
39
import { Util } from '@/utils';
tony001's avatar
tony001 committed
40
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
tony001's avatar
tony001 committed
41 42 43 44 45 46 47 48 49 50 51

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

tony001's avatar
tony001 committed
52 53 54 55 56 57
    /**
     * 下标
     *
     * @type {number}
     * @memberof AppScrollContainer
     */
tony001's avatar
tony001 committed
58
    @Prop() public index?: number;
tony001's avatar
tony001 committed
59

tony001's avatar
tony001 committed
60 61 62 63 64 65 66 67
    /**
     * 布局模型详情
     *
     * @type {string}
     * @memberof AppScrollContainer
     */
    @Prop() public layoutModelDetails: any;

tony001's avatar
tony001 committed
68 69 70 71 72 73 74 75 76 77
    /**
     * 布局模型详情变更
     * @param newVal 
     * @param oldVal 
     */
    @Watch('layoutModelDetails')
    onLayoutModelDetailsChange(newVal: any, oldVal: any) {
        this.initScrollContainer();
    }

tony001's avatar
tony001 committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
    /**
     * 插槽对象
     *
     * @memberof AppScrollContainer
     */
    public containerModel: any = {};

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

tony001's avatar
tony001 committed
92
    /**
tony001's avatar
tony001 committed
93 94 95 96
     * 项名称
     *
     * @type {*}
     * @memberof AppScrollContainer
tony001's avatar
tony001 committed
97
     */
tony001's avatar
tony001 committed
98
    get itemName() {
tony001's avatar
tony001 committed
99
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
tony001's avatar
tony001 committed
100 101 102
    }

    /**
tony001's avatar
tony001 committed
103
     * 当前容器样式类
tony001's avatar
tony001 committed
104
     */
tony001's avatar
tony001 committed
105 106 107 108 109
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-scroll-container ${this.itemName} ${layoutModel.sysCss}`;
        }
tony001's avatar
tony001 committed
110 111 112
    }

    /**
tony001's avatar
tony001 committed
113
     * 当前容器样式
tony001's avatar
tony001 committed
114
     */
tony001's avatar
tony001 committed
115 116
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
tony001's avatar
tony001 committed
117
        if (layoutModel) {
tony001's avatar
tony001 committed
118 119
            return layoutModel.getElementStyle();
        }
tony001's avatar
tony001 committed
120 121
    }

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

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