gaoluyang
6 天以前 37436ffec6f763d6d298d6f42d1ff946f27c71be
src/components/Table/ETable.vue
@@ -7,21 +7,20 @@
      :show-selection="showSelection"
      :max-height="maxHeight"
      @selection-change="handleSelectionChange"
<<<<<<< HEAD
=======
      @row-click="handleRowClick"
      @row-dblclick="handleRowDblClick"
      @cell-click="handleCellClick"
      :max-width="maxWidth"
      @export="handleExport"
>>>>>>> master
    >
      <el-table-column v-if="showSelection" type="selection" width="55" align="center" />
      <el-table-column v-if="showIndex" label="序号" type="index" width="60" align="center" />
      <el-table-column v-if="showIndex" label="序号" type="index" width="60" align="center"  />
      <template v-for="col in columns" :key="col.prop">
        <el-table-column
          v-bind="col"
          :show-overflow-tooltip="col.showOverflowTooltip !== false"
          :show-overflow-tooltip="shouldShowTooltip(col, tableData)"
          :formatter="(row, column, cellValue) => cellValue == null || cellValue === '' ? '--' : cellValue"
          align="center"
        >
          <template v-if="col.slot" #default>
            <slot></slot>
@@ -29,7 +28,7 @@
        </el-table-column>
      </template>
      <!-- 操作列 -->
      <el-table-column v-if="showOperations" :label="operationsLabel" :width="operationsWidth" fixed="right">
      <el-table-column v-if="showOperations" :label="operationsLabel" :width="operationsWidth" fixed="right" align="center">
        <template #default="scope">
          <slot name="operations" :row="scope.row">
            <el-button
@@ -39,13 +38,13 @@
              size="small"
              @click="handleEdit(scope.row)"
            >编辑</el-button>
            <el-button
              v-if="operations.includes('delete')"
              link
              type="danger"
              size="small"
              @click="handleDelete(scope.row)"
            >删除</el-button>
<!--            <el-button-->
<!--              v-if="operations.includes('delete')"-->
<!--              link-->
<!--              type="danger"-->
<!--              size="small"-->
<!--              @click="handleDelete(scope.row)"-->
<!--            >删除</el-button>-->
          </slot>
        </template>
      </el-table-column>
@@ -55,10 +54,7 @@
  <script setup>
  import { defineEmits } from 'vue'
  import { ElMessage, ElMessageBox } from 'element-plus'
  const props = defineProps({
<<<<<<< HEAD
=======
    // 最大宽度
    maxWidth: {
      type: [String, Number],
@@ -80,7 +76,6 @@
      type: Function,
      default: () => {}
    },
>>>>>>> master
    // 高度
    maxHeight: {
      type: [String, Number],
@@ -129,7 +124,7 @@
    // 操作列宽度
    operationsWidth: {
      type: [String, Number],
      default: 160
      default: 100
    },
    // 显示哪些操作按钮
    operations: {
@@ -142,6 +137,14 @@
      default: '确认删除该记录?'
    }
  })
  // 检查列是否需要显示tooltip
  const shouldShowTooltip = (col, data) => {
  // 如果没有prop,直接返回false
  if (!col.prop) return false;
  // 检查该列在所有数据中是否有非空值
  return data.some(row => row[col.prop] != null && row[col.prop] !== '');
};
// 处理选择变化、编辑、删除和导出操作
  const emit = defineEmits(['selection-change', 'edit', 'delete', 'export'])
  const handleSelectionChange = (selection) => {
    emit('selection-change', selection)