123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <template>
- <div class="cus-table">
- <div class="cus-table-table">
- <el-table
- ref="ref_table"
- v-bind="$attrs"
- :data="data"
- :row-key="rowKey"
- @sort-change="handleSort"
- @filter-change="handleFilter"
- @selection-change="v => $emit('update:selected', v)"
- max-height="100%"
- >
- <el-table-column v-if="selected" type="selection" :width="selectWidth" align="center" :selectable="selectable"/>
- <el-table-column v-if="singled" :width="singledWidth" align="center" class-name="single-column" fixed="left">
- <template #default="scope">
- <div class="single-circle" :class="{active: scope.row[singledKey] === singled[singledKey]}" @click.stop="$emit('update:singled', scope.row)">
- <div class="single-circle-in"></div>
- </div>
- </template>
- </el-table-column>
- <el-table-column v-if="showIndex" type="index" label="序号" align="center" fixed="left" width="60"/>
- <!-- 一级-->
- <template v-for="(one, oneI) in tableHead" :key="oneI">
- <template v-if="one.children?.length > 0">
- <el-table-column :label="one.label" align="center">
- <!-- 二级-->
- <template v-for="(two, twoI) in one.children" :key="twoI">
- <template v-if="two.children?.length > 0">
- <el-table-column :label="two.label" align="center">
- <!-- 三级-->
- <template v-for="(three, threeI) in two.children" :key="threeI">
- <template v-if="three.children?.length > 0">
- <el-table-column :label="three.label" align="center">
- <!-- 四级-->
- <template v-for="(four, fourI) in three.children" :key="fourI">
- <template v-if="four.children?.length > 0">
- <el-table-column :label="four.label" align="center">
- <!-- 五级-->
- <template v-for="(five, fiveI) in four.children" :key="fiveI">
- <CusTableColumn :item="five">
- <template #[`${five.value}-column`]="{column}">
- <slot :name="`${five.value}-column`" :column="column">
- </slot>
- </template>
- <template #[`${five.value}-column-value`]="{scope}">
- <slot :name="`${five.value}-column-value`" :scope="scope">
- </slot>
- </template>
- <template #[`${five.value}-header-value`]="{scope}">
- <slot :name="`${five.value}-header-value`" :scope="scope">
- </slot>
- </template>
- </CusTableColumn>
- </template>
- </el-table-column>
- </template>
- <template v-else>
- <CusTableColumn :item="four">
- <template #[`${four.value}-column`]="{column}">
- <slot :name="`${four.value}-column`" :column="column">
- </slot>
- </template>
- <template #[`${four.value}-column-value`]="{scope}">
- <slot :name="`${four.value}-column-value`" :scope="scope">
- </slot>
- </template>
- <template #[`${four.value}-header-value`]="{scope}">
- <slot :name="`${four.value}-header-value`" :scope="scope">
- </slot>
- </template>
- </CusTableColumn>
- </template>
- </template>
- </el-table-column>
- </template>
- <template v-else>
- <CusTableColumn :item="three">
- <template #[`${three.value}-column`]="{column}">
- <slot :name="`${three.value}-column`" :column="column">
- </slot>
- </template>
- <template #[`${three.value}-column-value`]="{scope}">
- <slot :name="`${three.value}-column-value`" :scope="scope">
- </slot>
- </template>
- <template #[`${three.value}-header-value`]="{scope}">
- <slot :name="`${three.value}-header-value`" :scope="scope">
- </slot>
- </template>
- </CusTableColumn>
- </template>
- </template>
- </el-table-column>
- </template>
- <template v-else>
- <CusTableColumn :item="two">
- <template #[`${two.value}-column`]="{column}">
- <slot :name="`${two.value}-column`" :column="column">
- </slot>
- </template>
- <template #[`${two.value}-column-value`]="{scope}">
- <slot :name="`${two.value}-column-value`" :scope="scope">
- </slot>
- </template>
- <template #[`${two.value}-header-value`]="{scope}">
- <slot :name="`${two.value}-header-value`" :scope="scope">
- </slot>
- </template>
- </CusTableColumn>
- </template>
- </template>
- </el-table-column>
- </template>
- <template v-else>
- <CusTableColumn :item="one">
- <template #[`${one.value}-column`]="{column}">
- <slot :name="`${one.value}-column`" :column="column">
- </slot>
- </template>
- <template #[`${one.value}-column-value`]="{scope}">
- <slot :name="`${one.value}-column-value`" :scope="scope">
- </slot>
- </template>
- <template #[`${one.value}-header-value`]="{scope}">
- <slot :name="`${one.value}-header-value`" :scope="scope">
- </slot>
- </template>
- </CusTableColumn>
- </template>
- </template>
- </el-table>
- </div>
- <div class="cus-table-page" v-if="!noPage">
- <CusPage
- :page-num="pageNum"
- :page-size="pageSize"
- :total="total"
- @page="onPage"
- />
- </div>
- </div>
- </template>
- <script setup lang="ts">
- defineOptions({
- name: 'CusTable',
- });
- import {computed, getCurrentInstance, reactive, ref, watch} from "vue";
- const emit = defineEmits(['handleSort', 'handleFilter', 'handlePage', 'update:selected'])
- const {proxy} = getCurrentInstance()
- const props = defineProps({
- pageNum: {},
- pageSize: {},
- total: {},
- rowKey: {default: 'id'},
- data: {},
- selected: {default: null},
- selectWidth: {default: 50},
- singledWidth: {default: 50},
- singled: {default: null},
- singledKey: {default: 'id'},
- showIndex: {default: true},
- selectable: {},
- tableHead: {default: []},
- noPage: {default: false}
- })
- const state: any = reactive({})
- const ref_table = ref()
- const handleSort = ({ column, prop, order }: any) => {
- emit('handleSort', {
- key: prop,
- value: order
- })
- }
- const handleFilter = (val: any) => {
- const key = Object.keys(val)[0]
- const head = props.tableHead.filter(v => v.value === key)[0]
- let value = null
- if (val[key].length > 0) {
- if (head.filterMultiple) {
- value = val[key]
- } else {
- value = val[key][0]
- }
- }
- emit('handleFilter', {key, value})
- }
- const onPage = (pageNum, pageSize) => {
- emit('handlePage', pageNum, pageSize)
- }
- watch(() => props.selected, (n: any) => {
- if (n.length === 0) {
- ref_table.value.clearSelection()
- } else {
- setTimeout(() => {
- n.forEach(v => {
- ref_table.value.toggleRowSelection(v, true)
- })
- }, 100)
- }
- })
- </script>
- <style lang="scss" scoped>
- .cus-table {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- .cus-table-table {
- flex: 1;
- overflow: hidden;
- :deep(.el-table) {
- height: 100%;
- .el-table__header-wrapper, .el-table__fixed-right, .el-table__fixed {
- .el-table__header {
- border-bottom: 2px solid var(--cus-main-color);
- tr {
- >th {
- background-color: var(--cus-main-color-hex-2);
- height: 44px;
- padding: 0;
- .cell {
- font-weight: bold;
- font-size: 16px;
- color: var(--cus-text-color-1);
- }
- }
- }
- }
- }
- .el-table__body-wrapper {
- .el-scrollbar__wrap {
- max-height: 100% !important;
- .el-table__body {
- .el-table__row {
- >td {
- .cell {
- font-size: 14px;
- color: var(--cus-text-color-1);
- .el-link+.el-link, .cus-table-button+.cus-table-button {
- margin-left: 10px;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- .cus-table-page {
- margin-top: 10px;
- display: flex;
- justify-content: flex-end;
- }
- }
- </style>
|