123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <script>
- /*
- * @Author: yolo
- * @Date: 2020-05-13 10:36:04
- * @Last Modified by: Yolo
- * @Last Modified time: 2020-12-24 15:18:03
- * 应用于表格视图
- */
- export default {
- name: 'TableView',
- data () {
- return {
- tableViewBodyDom: null,
- interval: null,
- bodyHeight: 100,
- isShowHeader: false
- }
- },
- computed: {
- isShow () {
- return this.$slots.header
- }
- },
- methods: {
- setHeight () {
- if (this.tableViewBodyDom) {
- setTimeout(() => {
- const height =
- document.body.clientHeight -
- (this.$refs.header ? this.$refs.header.offsetHeight : 0) -
- this.getTopHeight() -
- (this.$refs.footer ? this.$refs.footer.offsetHeight : 0)
- height && this.bodyHeight !== height && this.bodyHeightChange(height)
- }, 300)
- }
- },
- /**
- 兼容页面多个头不能动态计算的问题
- */
- getTopHeight () {
- let height =
- (document.getElementsByClassName('navBar').length > 0
- ? document.getElementsByClassName('navBar')[0].offsetHeight
- : 0) +
- (document.getElementsByClassName('title-line-height').length > 0
- ? document.getElementsByClassName('title-line-height')[0].offsetHeight
- : 0) + 40
- return height
- },
- bodyHeightChange (newHeight) {
- this.bodyHeight = newHeight
- this.$emit('body-height-change', newHeight)
- },
- /**
- * 安装 table body height 监视器
- */
- installBodyHeightMonitor () {
- // console.info(this.$el)
- this.bodyHeight = 90
- this.beforeDestroyed()
- this.interval = setTimeout(() => {
- this.setHeight()
- this.installBodyHeightMonitor()
- }, 800)
- },
- /**
- * 安装 table body height 监视器
- */
- uninstallBodyHeightMonitor () {
- clearTimeout(this.interval)
- },
- beforeDestroyed () {
- this.uninstallBodyHeightMonitor()
- }
- },
- mounted () {
- this.tableViewBodyDom = this.$refs.tableViewBody
- this.setHeight()
- this.installBodyHeightMonitor()
- },
- destroyed () {
- this.beforeDestroyed()
- }
- }
- </script>
- <template>
- <section ref="tableView"
- class="table-view">
- <header ref="header">
- <slot name="header"></slot>
- </header>
- <div class="table-view__body"
- ref="tableViewBody">
- <slot v-if="bodyHeight"
- name="body"></slot>
- <footer ref="footer">
- <slot name="footer"></slot>
- </footer>
- </div>
- <slot></slot>
- </section>
- </template>
- <style lang="scss" scope>
- .table-view {
- // display: flex;
- flex-direction: column;
- height: 100%;
- min-height: 150px;
- // margin-top: 1px;
- max-height: 100%;
- header {
- }
- &__body {
- flex: 1;
- overflow-y: auto;
- padding: 10px;
- background: #fff;
- overflow-x: hidden;
- }
- // footer {
- // padding-top: 8px;
- // }
- .pagination-container {
- margin-top: 0 !important;
- padding: 5px;
- }
- .el-pagination {
- margin-bottom: 0 !important;
- }
- .maintenance-overview {
- padding: 0 !important;
- }
- }
- </style>
|