el-table表格的标头带斜线

<template>
    <div class="tableBox">
        <el-table
          :data="tableData"
          style="width: 100%"
          :header-cell-style="handleHeaderCell">
          <el-table-column prop="date"  fixed>
            <template slot="header">
              <div style="display: flex; justify-content: space-between">
                <span>日期</span> <span>统计</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="配送信息" >
            <el-table-column prop="name" label="姓名" > </el-table-column>
            <el-table-column label="地址" >
              <el-table-column prop="province" label="省份" > </el-table-column>
              <el-table-column prop="city" label="市区" > </el-table-column>
              <el-table-column prop="address" label="地址" > </el-table-column>
              <el-table-column prop="zip" label="邮编" > </el-table-column>
              <el-table-column prop="zip1" label="邮编" > </el-table-column>
               <el-table-column prop="zip2" label="邮编" > </el-table-column>
            </el-table-column>
          </el-table-column>

        </el-table>
        <div class="line" :style="{width:lineWhide+'px',transform:'rotate('+lineDeg+'deg)'}"></div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            //第一个单元格的类名
            firstCellClassName: "",
            //第一个单元格的宽度
            firstCellWidth: 0,
            //第一个单元格的高度
            firstCellHeight: 0,
            //对角线的宽度
            lineWhide:0,
            //对角线的角度
            lineDeg:0,
            //窗口宽度
            screenWidth:document.body.clientWidth,
            timer:null,
            //表格数据
            tableData:[],
        }
    },
     mounted() {
        //窗口或框架被调整大小时发生
        window.onresize=()=>{
            return (()=>{
                window.screenWidth =document.body.clientWidth
                this.screenWidth = window.screenWidth
            })
        }
    },
    methods:{
        handleHeaderCell({ row, column, rowIndex, columIndex }) {
            //如果使用的多级表头  就需要判断是第几个表头
            if (rowIndex == 0) {
                //获取第一个单元格的class类名
                this.firstCellClassName = row[0].id;
                //获取第一个单元格的宽度,这个方法直接返回了
                this.firstCellWidth = row[0].realWidth;
                //这个时候他是找不到元素的  所以在调用一次
                this.$nextTick(() => {
                this.getsElement();
                });
            }
            console.log(this.firstCellClassName, this.firstCellWidth, "查看类名");
        },
        getsElement() {
            //用原生获取第一个单元格的高度
            var a = document.getElementsByClassName(this.firstCellClassName)[0];
            this.firstCellHeight = a.offsetHeight;
            //获取对角线的长度 a²+b²=c²
            this.lineWhide = Math.sqrt((this.firstCellWidth*this.firstCellWidth)+(this.firstCellHeight*this.firstCellHeight))
            
            //获取对角线旋转的角度
            this.lineDeg = Math.atan(this.firstCellHeight/this.firstCellWidth)*180/Math.PI


            console.log(this.firstCellHeight,"查看高度")
            console.log(this.lineWhide,"对角线宽度")
            console.log(this.lineDeg,"角度")

        },
    },
    watch:{
        //监听窗口的变化 变了之后
        screenWidth(val){
            if(!this.timer){
                this.screenWidth =val
                this.timer =true
                // setTimeout(function(){
                this.getsElement()
                // })
            }
        }
    }
}
</script>
<style scoped lang="scss">
.tableBox {
    margin-top: 50px;
    position: relative;
    /* background-color: red; */
}
.line {
    position: absolute;
    /* position:fixed; */
    z-index: 9;
    top: 0;
    left: 0;
    height: 1px;
    width: 350px;
    background-color: black;
    transform-origin: left;
    transform: rotate(24.2deg);
}
</style>

我项目中改动后使用

<template>
    <div class="tableBox">
        <el-table :data="tableData" style="width: 100%" :header-cell-style="handleHeaderCell">
            
          <el-table-column prop="date" fixed>
              <el-table-column type="index" width="80" />
            <template slot="header">
              <div style="display: flex; justify-content: space-between">
                <span>L</span> <span>S</span>
              </div>
            </template>
            
          </el-table-column>
            <el-table-column label="1" ><template slot-scope="scope"><div class="tab-back-color" :style="{backgroundColor:backgroundColorFun(1)}">1级</div></template></el-table-column>
            <el-table-column label="2" ><template slot-scope="scope"><div class="tab-back-color" :style="{backgroundColor:backgroundColorFun(2)}">2级</div></template></el-table-column>
            <el-table-column label="3" ><template slot-scope="scope"><div class="tab-back-color" :style="{backgroundColor:backgroundColorFun(3)}">3级</div></template></el-table-column>
            <el-table-column label="4" ><template slot-scope="scope"><div class="tab-back-color" :style="{backgroundColor:backgroundColorFun(4)}">4级</div></template></el-table-column>
            <el-table-column label="5" ><template slot-scope="scope"><div class="tab-back-color" :style="{backgroundColor:backgroundColorFun(1)}">4级</div></template></el-table-column>
            

        </el-table>
        <div class="line" :style="{width:lineWhide+'px',transform:'rotate('+lineDeg+'deg)'}"></div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            //第一个单元格的类名
            firstCellClassName: "",
            //第一个单元格的宽度
            firstCellWidth: 0,
            //第一个单元格的高度
            firstCellHeight: 0,
            //对角线的宽度
            lineWhide:0,
            //对角线的角度
            lineDeg:0,
            //窗口宽度
            screenWidth:document.body.clientWidth,
            timer:null,
            //表格数据
            tableData:[{},{},{},{},{},],
        }
    },
    mounted() {
        //窗口或框架被调整大小时发生
        window.onresize=()=>{
            return (()=>{
                window.screenWidth =document.body.clientWidth
                this.screenWidth = window.screenWidth
            })
        }
    },
    computed:{
        backgroundColorFun(){
            return (num)=>{
                switch(num){
                    case 1:
                        return '#FF0000';
                    case 2:
                        return '#FF9900';
                    case 3:
                        return '#FFFF00';
                    case 4:
                        return '#3366FF';
                    
                }
            }
        }
    },
    methods:{
        handleHeaderCell({ row, column, rowIndex, columIndex }) {
            //如果使用的多级表头  就需要判断是第几个表头
            if (rowIndex == 0) {
                //获取第一个单元格的class类名
                this.firstCellClassName = row[0].id;
                //获取第一个单元格的宽度,这个方法直接返回了
                this.firstCellWidth = row[0].realWidth;
                //这个时候他是找不到元素的  所以在调用一次
                this.$nextTick(() => {
                this.getsElement();
                });
            }else if(rowIndex == 1){
                return {display: 'none'}
            }
            console.log(this.firstCellClassName, this.firstCellWidth, "查看类名");
        },
        getsElement() {
            //用原生获取第一个单元格的高度
            var a = document.getElementsByClassName(this.firstCellClassName)[0];
            this.firstCellHeight = a.offsetHeight;
            //获取对角线的长度 a²+b²=c²
            this.lineWhide = Math.sqrt((this.firstCellWidth*this.firstCellWidth)+(this.firstCellHeight*this.firstCellHeight))
            
            //获取对角线旋转的角度
            this.lineDeg = Math.atan(this.firstCellHeight/this.firstCellWidth)*180/Math.PI


            console.log(this.firstCellHeight,"查看高度")
            console.log(this.lineWhide,"对角线宽度")
            console.log(this.lineDeg,"角度")

        },
    },
    watch:{
        //监听窗口的变化 变了之后
        screenWidth(val){
            if(!this.timer){
                this.screenWidth =val
                this.timer =true
                // setTimeout(function(){
                this.getsElement()
                // })
            }
        }
    }
}
</script>
<style scoped lang="scss">
.tableBox {
    margin-top: 1rem;
    position: relative;
    /* background-color: red; */
    .tab-back-color{
        width: 4rem;
        height: 1.5rem;
        text-align: center;
        line-height: 1.5rem;
    }
}
.line {
    position: absolute;
    /* position:fixed; */
    z-index: 9;
    top: 0;
    left: 0;
    height: 1px;
    width: 350px;
    background-color: gainsboro;
    transform-origin: left;
    transform: rotate(24.2deg);
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用el-dialog组件时,可以通过在title属性里使用插槽的方式来设置多个不同样式的字符串。具体做法是在title属性的值前面加上`<template>`标签,并在内部使用`<span>`等标签来包裹需要设置不同样式的字符串。例如: ```html <el-dialog :title="`<template><span style='color: red;'>Hello</span> <span style='color: blue;'>World</span></template>`"> <!-- 对话框内容 --> </el-dialog> ``` 这样就可以在el-dialog的标题中设置两个不同样式的字符串,分别为"Hello"和"World",其中"Hello"的颜色为红色,"World"的颜色为蓝色。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [通过具名 slot (插槽) 来显示Dialog 的标题](https://blog.csdn.net/qyl_0316/article/details/107967547)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [elementui dialog弹框虚线拖拽](https://blog.csdn.net/m0_71818580/article/details/128260770)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [element ui 对话框el-dialog关闭事件详解](https://download.csdn.net/download/weixin_38660108/12763272)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值