zhang_12370
2025-07-23 ba07ace535232e5ea77cf0a89cd1c079895e1441
src/components/Table/ETable.vue
@@ -2,7 +2,7 @@
    v-loading="loading" 
    :data="tableData" 
    :border="border" 
    :show-selection="showSelection"
    :show-selection="showSelection"
    :max-height="maxHeight"
    :header-cell-style="{ background: '#EBEEF5', color: '#3D3D3D' }" 
    @selection-change="handleSelectionChange"
@@ -15,10 +15,10 @@
    :show-overflow-tooltip="showOverflowTooltip"
    ref="tableRef" 
    :row-key="rowKey"
    style="width: 100%"
    style="width: 100%;"
  >
    <el-table-column v-if="showSelection" type="selection" width="55" align="center" />
    <el-table-column v-if="showIndex" label="序号" width="60" align="center" fixed="left">
    <el-table-column v-if="showSelection" type="selection" width="55" align="center" :show-overflow-tooltip="false" />
    <el-table-column v-if="showIndex" label="序号" width="60" align="center" fixed="left" :show-overflow-tooltip="false">
      <template #default="scope">
        {{ getRowIndex(scope.$index) }}
      </template>
@@ -32,20 +32,31 @@
      </el-table-column>
    </template>
    <!-- 操作列 -->
    <el-table-column v-if="showOperations" :label="operationsLabel" :width="operationsWidth" fixed="right" align="center">
    <el-table-column v-if="showOperations" :label="operationsLabel" :width="operationsWidth" :show-overflow-tooltip="false" fixed="right" align="center">
      <template #default="scope">
        <slot name="operations" :row="scope.row">
          <!-- 自定义按钮 - 放在默认按钮之前 -->
          <el-button
            v-for="button in customButtons"
            :key="button.name"
            v-show="!button.show || button.show(scope.row)"
            :link="button.link !== false"
            :type="button.type || 'primary'"
            :size="button.size || 'small'"
            :icon="button.icon"
            :disabled="button.disabled && button.disabled(scope.row)"
            @click="handleCustomClick(button.name, scope.row)"
          >
            {{ button.label }}
          </el-button>
          <!-- 默认操作按钮 -->
          <el-button v-if="operations.includes('edit')" link type="primary" size="small"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button v-if="operations.includes('viewRow')" link type="primary" size="small"
            @click="handleView(scope.row)">查看</el-button>
          <el-button v-if="operations.includes('viewFile')" link type="primary" size="small"
            @click="handleView(scope.row)">查看附件</el-button>
          <!--            <el-button-->
          <!--              v-if="operations.includes('delete')"-->
          <!--              link-->
          <!--              type="danger"-->
          <!--              size="small"-->
          <!--              @click="handleDelete(scope.row)"-->
          <!--            >删除</el-button>-->
            @click="handleViewFile(scope.row)">查看附件</el-button>
        </slot>
      </template>
    </el-table-column>
@@ -131,7 +142,25 @@
  operations: {
    type: Array,
    default: () => ['edit', 'delete', 'export']
  },  // 删除确认信息
  },
  // 自定义按钮配置
  customButtons: {
    type: Array,
    default: () => []
    // 示例配置:
    // [
    //   {
    //     name: 'return',      // 按钮标识
    //     label: '归还',       // 按钮显示文本
    //     type: 'success',     // 按钮类型
    //     size: 'small',       // 按钮大小
    //     icon: '',            // 图标(可选)
    //     show: (row) => true, // 显示条件函数(可选)
    //     disabled: (row) => false, // 禁用条件函数(可选)
    //   }
    // ]
  },
  // 删除确认信息
  deleteConfirmText: {
    type: String,
    default: '确认删除该记录?'
@@ -168,7 +197,7 @@
};
// 处理选择变化、编辑、删除和导出操作
const emit = defineEmits(['selection-change', 'edit', 'delete', 'export'])
const emit = defineEmits(['selection-change', 'edit', 'delete', 'export', 'viewRow', 'viewFile', 'custom-click'])
const handleSelectionChange = (selection) => {
  emit('selection-change', selection)
}
@@ -176,8 +205,17 @@
  emit('edit', row)
}
const handleView = (row) => {
  emit('viewRow', row)
}
const handleViewFile = (row) => {
  emit('viewFile', row)
}
// 处理自定义按钮点击
const handleCustomClick = (buttonName, row) => {
  emit('custom-click', { buttonName, row })
}
const handleDelete = (row) => {
  ElMessageBox.confirm(
    props.deleteConfirmText,