vue2.0、elment-ui-table 行,自定义鼠标右键弹出内容

<template>  
   <div>
     <el-table :data="manageData.tableData"  height="100%" size="mini"
                @row-contextmenu="handleRow">
                <el-table-column prop="sensorCode" header-align="center" align="center" 
                label="探测器编号"></el-table-column>
     </el-table>

    <!-- 自定义 tooltip 弹出框 -->
     <div :style="tooltipStyle" v-if="tooltipVisible" class="custom-tooltip" 
      @click="ignoreAlarm"> 忽略报警
     </div>

  </div>
</template>
<script>
export default {
  data(){
     return{
        currentRowData: null, // 保存当前行的数据
        tooltipVisible: false,
        tooltipStyle: {
        position: 'absolute',
        left: '0px',
        top: '0px',
        zIndex: 9999,
      },
         }

    },
  mounted() {
   document.addEventListener('click', this.handleDocumentClick);  // 添加全局点击事件监听器
  },
  beforeDestroy() {
    document.removeEventListener('click', this.handleDocumentClick);
  },
  methods: {

    // 点击鼠标左键空白区域就关闭提示
    handleDocumentClick(event) {
      if (this.tooltipVisible && (!this.$refs.tooltip || 
          !this.$refs.tooltip.contains(event.target))) {
          this.tooltipVisible = false;  // 如果点击的不是 tooltip 或其子元素,关闭 tooltip
      }
    },

    // 自定义鼠标右键事件
    handleRow(row, event) {
      this.currentRowData = row
      event.preventDefault();
      const tooltipWidth = 70; // 定义 Tooltip 宽度
      const tooltipHeight = 20; // 定义 Tooltip 高度
      let x = event.clientX;
      let y = event.clientY;

      // 确保 Tooltip 不超出屏幕右边界
      if (x + tooltipWidth > window.innerWidth) {
        x -= tooltipWidth;
      }

      // 确保 Tooltip 不超出屏幕底部边界
      if (y + tooltipHeight > window.innerHeight) {
        y -= tooltipHeight;
      }

      this.tooltipStyle = {
        position: 'fixed', // 使用 fixed 以便相对于视窗定位
        left: `${x}px`,
        top: `${y}px`,
        zIndex: 9999,
        width: `${tooltipWidth}px`,
        height: `${tooltipHeight}px`,
        backgroundColor: '#152841',
        border: '1px solid #ccc',
        padding: '5px',
        borderRadius: '4px',
      };
      this.tooltipVisible = true;

    },
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值