123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <template>
- <div class="mt-20">
- <el-table
- :data="items"
- :style="`width: 100%; min-height:${minHeight};`"
- v-bind="$attrs"
- @selection-change="handleSelectionChange"
- >
- <slot name="table">
- <template v-for="column in columns">
- <el-table-column
- v-if="column.key === 'selection'"
- :key="column.key"
- :type="column.key"
- :min-width="column.minWidth"
- :width="column.width || 50"
- :align="column.align || 'center'"
- />
- <el-table-column
- v-else
- :key="column.key"
- :prop="column.key"
- :label="column.name"
- :min-width="column.minWidth"
- :width="column.width"
- :align="column.align"
- :fixed="column.fixed"
- :show-overflow-tooltip="column['show-overflow-tooltip']"
- >
- <template slot-scope="scope">
- <ex-slot
- v-if="column.render"
- :render="column.render"
- :row="scope.row"
- :index="scope.$index"
- :column="column"
- />
- <span v-else-if="column.type === 'tag'">
- <el-tag
- size="medium"
- :type="column.fetchTagType(scope.row[column.key]) || ''"
- >{{
- typeof column.tagName === 'function'
- ? column.tagName(scope.row)
- : scope.row[column.key]
- }}</el-tag
- >
- </span>
- <span v-else>{{ scope.row[column.key] || '-' }}</span>
- </template>
- </el-table-column>
- </template>
- </slot>
- </el-table>
- <div class="page-select">
- <div class="btn-box">
- <slot :selected="multipleSelection" name="btn-box" />
- </div>
- <el-pagination
- v-if="showPage"
- background
- layout="prev, pager, next"
- :current-page="pagination.page"
- :page-size="pagination.pageSize"
- :total="pagination.total"
- @current-change="num => pageChange(num)"
- />
- </div>
- </div>
- </template>
- <script>
- // 自定义内容的组件
- var exSlot = {
- functional: true,
- props: {
- row: Object,
- render: Function,
- index: Number,
- column: {
- type: Object,
- default: null
- }
- },
- render: (h, data) => {
- const params = {
- row: data.props.row,
- index: data.props.index
- };
- if (data.props.column) params.column = data.props.column;
- return data.props.render(h, params);
- }
- };
- export default {
- name: 'TableWithPage',
- components: {
- 'ex-slot': exSlot
- },
- props: {
- columns: {
- type: Array,
- default: () => []
- },
- items: {
- type: Array,
- default: () => []
- },
- pagination: {
- type: Object,
- default: () => ({})
- },
- pageChange: {
- type: Function,
- default: () => {}
- },
- minHeight: {
- type: String,
- default: '600px'
- },
- showPage: {
- type: Boolean,
- default: true
- }
- },
- data() {
- return {
- multipleSelection: []
- };
- },
- watch: {
- items: {
- handler(val) {
- this.multipleSelection = [];
- },
- immedaite: true
- }
- },
- methods: {
- handleSelectionChange(params) {
- this.multipleSelection = params;
- }
- }
- };
- </script>
- <style scoped>
- .page-select {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 6px 20px 0 20px;
- }
- .btn-box .el-button {
- margin: 2px 10px;
- }
- </style>
|