| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <template>
- <div class="page_table">
- <el-table
- class="el-table--border"
- ref="tableRef"
- :show-header="showHeader"
- :data="tableData"
- stripe
- v-loading="loading"
- element-loading-text="拼命加载中……"
- element-loading-spinner="el-icon-loading"
- element-loading-background="#ffffff"
- element-loading-custom-class="loading_icon"
- :row-class-name="tableRowClassName"
- @row-click="(row, column) => $emit('rowClick', row)"
- :span-method="spanMethod"
- >
- <template v-for="(item, index) in tableColumns">
- <el-table-column
- :key="item?.name"
- v-if="!item.hidden"
- :prop="item.name"
- :min-width="item.minWidth"
- :width="item.width"
- :label="item.label"
- :fixed="item.fixed ? item.fixed : false"
- :align="item.align"
- >
- <template v-if="item.customHeader" v-slot:header>
- <slot :name="'header-' + item.name"></slot>
- </template>
- <template v-if="item.custom" v-slot:default="row">
- <slot :name="item.name" :row="row.row" :currentIndex="(row.$index + 1)"></slot>
- </template>
- </el-table-column>
- </template>
- </el-table>
- <div class="page_pagination" v-if="!hidePagination">
- <el-pagination
- :hide-on-single-page="hidesinglePage"
- :current-page="currentPage"
- :page-size="pageSize"
- :page-sizes="[20, 50, 100]"
- background
- layout="prev, pager, next"
- :total="Number(totalNum)"
- @current-change="(val) => $emit('paginationChange', { type: 'currentPage', val })"
- @size-change="(val) => $emit('paginationChange', { type: 'pageSize', val })"
- />
- </div>
- </div>
- </template>
- <script>
- /*
- interface tableColumnItm {
- name:String,
- label:String,
- width?:String,
- fixed?:String,
- align?:String,
- minWidth?:String,
- custom:Boolean,
- customHeader?:Boolean,
- hidden:Boolean,
- }
- */
- export default {
- name: 'Table',
- props: {
- tableData: {
- type: Array,
- required: true
- },
- tableColumns: {
- type: Array, //类型为 tableColumnItm[]
- required: true
- },
- currentPage: {
- type: Number,
- default: 1
- },
- pageSize: {
- type: Number,
- default: 20
- },
- totalNum: {
- type: Number,
- default: 0
- },
- loading: {
- type: Boolean,
- default: false
- },
- hidesinglePage: {
- type: Boolean
- },
- hidePagination: {
- type: Boolean,
- default: false
- },
- spanMethod: {
- type: Function,
- required: false
- },
- tableRowClassName: {
- type: Function,
- required: false
- },
- showHeader: {
- type: Boolean,
- default: true
- }
- },
- data() {
- return {
- // Vue 2 中没有 defineModel,tableRef 仅作为内部状态或普通 ref
- // 父组件获取表格实例请使用 this.$refs.tableRef
- tableRef: null
- };
- },
- mounted(){
- }
- };
- </script>
- <style lang="scss" scoped>
- .page_table {
- overflow: auto;
- display: flex;
- flex-direction: column;
- justify-content: flex-start;
- ::v-deep .el-table {
- tr th.el-table__cell {
- font-size: 14px;
- }
- }
- .el-table {
- flex-grow: 1;
- ::v-deep .el-scrollbar__view {
- height: 100%;
- }
- }
- ::v-deep .el-table__body {
- tbody tr.even_row td {
- background-color: white;
- }
- tbody tr.odd_row td {
- background-color: rgb(250, 250, 250);
- }
- tbody tr.hover-row td {
- background-color: rgb(245, 247, 250) !important;
- }
- tbody tr td:last-child:not([rowspan="1"]) {
- border-left: solid rgba(235, 238, 245) 1px;
- }
- }
- }
- ::v-deep .loading_icon {
- .el-loading-spinner {
- .el-loading-text {
- color: #2e64fa;
- }
- }
- }
- </style>
|