element封装一个表格

 
<template>
  <div>
    <el-table
       ref="multipleTable"
       v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(0, 0, 0, 0.5)"
      :header-cell-style="header_cell_style"
      :row-style="rowStyle"
      :cell-style="cellStyle"
      :data="tableData"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
    <el-table-column type="selection"   v-if="selection" width="55">
    </el-table-column>
      <el-table-column
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
         :show-overflow-tooltip="true"
        v-for="(item, index) in tableColumn"
        :key="index"
      >
        <template slot-scope="scope">
          <!-- 状态时候做判断 -->
          <div v-if="item?.status">
              <div v-for="(tag,tagi) in  item?.status" :key="tagi">
                <el-tag size="small" :style="tag?.style" v-if="tag.name === scope.row[item.prop]" >
                  <span  >{{ tag.desc || '...' }}</span>
                </el-tag>
              </div>
          </div>
         <div v-else>
          <!-- obj数据进行判断 -->
          <span :style="item?.style" v-if="item.type === 'Object'">{{
          scope.row[item.prop][item.ObjectField] || '...'
          }}</span>
          <span :style="item?.style" v-else>{{ scope.row[item.prop] || '...' }}</span>
         </div>
        </template>
      </el-table-column>
      <!-- 操作模块 -->
      <el-table-column
        :prop="operation.prop"
        :label="operation.label"
        :width="operation.width"
         fixed="right"
        v-if="operation?.isOperation"
      >
        <template slot-scope="scope">
          <el-button
            :style="item2?.style"
            type="text"
            v-for="(item2, index2) in operation.list"
            :key="index2"
            size="small"
            >
            <!-- 替换对象 -->
            <span  @click="operationClick(item2?.replace.event, scope.row)" v-if="item2?.replace && item2?.replace?.judge === scope.row[item2?.replace?.prop]">{{ item2?.replace?.name }}</span>
            <span  @click="operationClick(item2.event, scope.row)" v-else>{{ item2.name }}</span>
           </el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: {
    // 加载动画
    loading: {
      type: Boolean,
      default: false
    },
    // 选中的数据
    selectRows: {
      type: Array
    },
    // 表格数据
    tableData: {
      type: Array
    },
    // 行列表
    tableColumn: {
      type: Array
    },
    // 是否有选择按钮
    selection: {
      type: Boolean,
      default: false
    },
    // 操作对象
    operation: {
      type: Object
    },
    // 头部样式
    header_cell_style: {
      type: Object,
      default: function () {
        return {
          background: '#C2DBCE',
          'text-align': 'center',
          color: '#333333',
          'font-weight': 'bold'
        }
      }
    },
    // 行样式
    rowStyle: {
      type: Object,
      default: function () {
        return {
          'text-align': 'center'
        }
      }
    },
    // 列样式
    cellStyle: {
      type: Object,
      default: function () {
        return {
          'text-align': 'center'
        }
      }
    }
  },
  data() {
    return {
    }
  },
  methods: {
    // 操作点击事件
    operationClick(type, row) {
      const data = {
        type,
        item: row
      }
      this.$emit('click', data)
    },
    // 选择按钮事件
    handleSelectionChange(val) {
      this.$emit('handleSelectionChange', val)
    }

  }
}
</script>

<style>

</style>

使用方法:

 data() {
    return {
      // 对应列数据
      tableColumn: [
        {
          prop: 'taskNumber',
          label: '任务编号'
        },
        {
          prop: 'sampleArea',
          label: '区域'
        },
        {
          prop: 'sampleNumber',
          label: '采样点数量'
        },
        {
          prop: 'reportTime',
          label: '上报时间'

        },

        {
          prop: 'taskStatus',
          label: '任务状态',
          status: [
            {
              name: 'TO_LASSOED',
              style: {
                color: '#F82E2E'
              },
              desc: '待下发'
            },
            {
              name: 'IN_TASK',
              style: {
                color: '#FF0000'
              },
              desc: '实施中'
            },
            {
              name: 'REJECT',
              style: {
                color: '#F82E2E'
              },
              desc: '已拒绝'
            },
            {
              name: 'LASSOED',
              style: {
                color: '#67C23A'
              },
              desc: '下发中'
            },
            {
              name: 'REPORTING',
              style: {
                color: '#409EFF'
              },
              desc: '上报中'
            },
            {
              name: 'COMPLETED',
              style: {
                color: '#E4820E'
              },
              desc: '已完成'
            }
          ]
        },
        {
          prop: 'samplingRange',
          label: '采样范围(m)'
        },
        {
          prop: 'remark',
          label: '备注'
        }
      ],

      // 表单其他操作
      operation: {
        prop: 'operation',
        label: '操作',
        isOperation: true,
        list: [
          {
            name: '下发',
            event: 'Issued',
            replace: {
              prop: 'taskStatus',
              name: '撤回',
              event: 'withdraw',
              judge: 'LASSOED'
            }
          },
          {
            name: '删除',
            event: 'delete',
            style: {
              color: '#F82E2E'
            }
          }
        ]
      },
      // 请求参数
      paramsData: {
        enable: 'ENABLE',
        limit: 8,
        page: 1,
        samplingProjectId: '',
        sampleArea: ''
      },
      // 总数
      total: 0,
      // 表格传入数据
      tableData: [],
      // 多选选择的值
      multipleData: [],
      // 选中的数据
      selectRows: []
    }
  },

效果图:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue和Element可以一起使用来封装一个选人弹窗。首先,我们需要使用Vue框架来构建弹窗组件,然后使用Element UI库来实现弹窗的样式和组件。 在Vue中,我们可以使用组件的方式来封装选人弹窗。首先,我们需要创建一个组件文件,命名为"selectUserModal.vue"。然后,在该组件中,我们可以使用Element UI的Modal组件作为弹窗容器,使用Form组件和Table组件等来展示选择人员的界面。 在"selectUserModal.vue"中,我们可以定义一个data属性来存储选择的人员信息,以及一个visible属性来控制弹窗的显示和隐藏。我们还可以定义一些方法来处理用户的选择操作,如确定选择和取消选择等。 在弹窗的界面中,我们可以使用Form组件来展示与人员选择相关的输入框,如搜索框和筛选条件等。然后,在表格中展示人员列表,可以使用Table组件,并绑定数据源和列定义。 为了实现人员选择操作,我们可以提供一个确认按钮,当用户点击确认按钮时,我们可以触发一个自定义事件,并将选择的人员信息作为参数进行传递。其他的操作,如点击表格行即选中人员,我们也可以在相应的方法中进行处理。 当组件完成后,我们可以在其他Vue页面中引用该组件,并传递参数来控制弹窗的显示。通过监听自定义事件,我们可以在父组件中获取到选择的人员信息,并进行相应的操作。 总结起来,通过Vue和Element的配合,我们可以封装一个选人弹窗组件,使其能在Vue项目中方便地使用,并具有良好的交互和样式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的美,让我痴迷

你的好,我会永远记住你的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值