123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <template>
- <div :class="classes">
- <div class="rect-col">
- <div
- class="rect-col-item"
- ref="stdinfoContainer"
- :style="{ height: heights.stdinfo + 'px' }"
- >
- <slot name="stdinfo"></slot>
- </div>
- <div
- class="rect-col-item"
- ref="noticeContainer"
- :style="{ height: heights.notice + 'px' }"
- >
- <slot name="notice"></slot>
- </div>
- </div>
- <div class="rect-col">
- <div
- class="rect-col-item"
- ref="stdnoContainer"
- :style="{ height: heights.stdno + 'px' }"
- >
- <slot name="stdno"></slot>
- </div>
- <div
- :class="['rect-col-item', { 'rect-col-item-none': !$slots.dynamic }]"
- ref="dynamicContainer"
- :style="{ height: heights.dynamic + 'px' }"
- >
- <slot name="dynamic"></slot>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "card-head-body-auto-resize",
- data() {
- return {
- orgHeights: {
- stdinfo: 40,
- notice: 40,
- stdno: 40,
- dynamic: 40
- },
- heights: {
- stdinfo: 40,
- notice: 40,
- stdno: 40,
- dynamic: 40
- }
- };
- },
- computed: {
- classes() {
- return ["card-head-body-auto-resize", "col-item-auto-height"];
- }
- },
- mounted() {
- this.initStyles();
- },
- methods: {
- initStyles() {
- const containers = ["stdinfo", "notice", "stdno", "dynamic"];
- containers.forEach(container => {
- const dom =
- this.$refs[`${container}Container`] &&
- this.$refs[`${container}Container`].firstChild;
- this.orgHeights[container] = dom ? dom.offsetHeight : 0;
- });
- Object.keys(this.orgHeights).map(key => {
- this.heights[key] = this.orgHeights[key] + 2;
- });
- this.resizeRect();
- },
- resizeRect() {
- let col1 = this.orgHeights.stdinfo + this.orgHeights.notice;
- let col2 = this.orgHeights.stdno + this.orgHeights.dynamic;
- if (this.$slots.dynamic) {
- if (col1 > col2) {
- this.heights.stdno = col1 - col2 + this.orgHeights.stdno + 2;
- this.heights.dynamic = this.orgHeights.dynamic + 2;
- } else {
- const splitHeight = (col2 - col1) / 2;
- this.heights.stdinfo = splitHeight + this.orgHeights.stdinfo + 2;
- this.heights.notice = splitHeight + this.orgHeights.notice + 2;
- }
- } else {
- col1 += 14;
- col2 -= 2;
- if (col1 > col2) {
- this.heights.stdno = col1;
- } else {
- const splitHeight = (col2 - col1) / 2;
- this.heights.stdinfo = splitHeight + this.orgHeights.stdinfo + 2;
- this.heights.notice = splitHeight + this.orgHeights.notice + 2;
- }
- }
- }
- }
- };
- </script>
|