Compare commits

...

2 Commits

1 changed files with 33 additions and 49 deletions

View File

@ -1,16 +1,15 @@
<template> <template>
<div class="table-pro-content"> <div class="table-pro-content">
<div class="card padding" v-if="props.searchFormOptions"> <div class="card padding" v-if="props.searchFormOptions">
<FormProMax ref="searchFormRef" :form-item-options="props.searchFormOptions" v-model:value="searchParams" <FormProMax ref="searchFormRef" :form-item-options="props.searchFormOptions" v-model:value="searchParams" v-bind="props.searchFormProps">
v-bind="props.searchFormProps">
<template v-slot:formOperation> <template v-slot:formOperation>
<a-space class="margin-right flex-end"> <a-space class="margin-right flex-end">
<a-button type="primary" @click="search"> <a-button type="primary" @click="search">
<search-outlined/> <search-outlined />
搜索 搜索
</a-button> </a-button>
<a-button danger @click="resetFormAndTable"> <a-button danger @click="resetFormAndTable">
<rollback-outlined/> <rollback-outlined />
重置 重置
</a-button> </a-button>
</a-space> </a-space>
@ -27,7 +26,7 @@
<a-tooltip> <a-tooltip>
<template #title>刷新数据</template> <template #title>刷新数据</template>
<a-button shape="circle" @click="requestGetTableData"> <a-button shape="circle" @click="requestGetTableData">
<ReloadOutlined/> <ReloadOutlined />
</a-button> </a-button>
</a-tooltip> </a-tooltip>
</template> </template>
@ -35,34 +34,34 @@
<a-tooltip> <a-tooltip>
<template #title>打印数据</template> <template #title>打印数据</template>
<a-button shape="circle"> <a-button shape="circle">
<PrinterOutlined/> <PrinterOutlined />
</a-button> </a-button>
</a-tooltip> </a-tooltip>
</template> </template>
</a-space> </a-space>
</div> </div>
<a-table <a-table
class="margin-top" class="margin-top"
v-bind="props" v-bind="props"
:columns="tableColumns" :columns="tableColumns"
:row-selection="props.isSelection ? (props.selectionProps ? props.selectionProps : defaultSelectProps) : null" :row-selection="props.isSelection ? (props.selectionProps ? props.selectionProps : defaultSelectProps) : null"
:data-source="dataSource" :data-source="dataSource"
:loading="loading" :loading="loading"
:pagination="false" :pagination="false"
> >
<template v-for="(_, key) in slots" v-slot:[key]="scope"> <template v-for="(_, key) in slots" v-slot:[key]="scope">
<slot v-if="!includes(['tableHeader', 'tableHeaderRight'], String(key))" :name="key" v-bind="scope"></slot> <slot v-if="!includes(['tableHeader', 'tableHeaderRight'], String(key))" :name="key" v-bind="scope"></slot>
</template> </template>
</a-table> </a-table>
<a-pagination <a-pagination
v-if="props.isPagination" v-if="props.isPagination"
class="flex-end margin-top margin-right" class="flex-end margin-top margin-right"
v-model:current="pageParams.current" v-model:current="pageParams.current"
v-model:page-size="pageParams.size" v-model:page-size="pageParams.size"
:total="pageParams.total" :total="pageParams.total"
v-bind="props.paginationProps" v-bind="props.paginationProps"
@change="handleCurrentChange" @change="handleCurrentChange"
@showSizeChange="handleSizeChange" @showSizeChange="handleSizeChange"
/> />
</div> </div>
</div> </div>
@ -70,17 +69,12 @@
<script setup lang="ts" generic="T extends BaseTableRowRecord = {},P extends { [key: string]: any } ={}"> <script setup lang="ts" generic="T extends BaseTableRowRecord = {},P extends { [key: string]: any } ={}">
import FormProMax from '@/components/form/FormProMax.vue' import FormProMax from '@/components/form/FormProMax.vue'
import {PrinterOutlined, ReloadOutlined, RollbackOutlined, SearchOutlined} from '@ant-design/icons-vue' import { PrinterOutlined, ReloadOutlined, RollbackOutlined, SearchOutlined } from '@ant-design/icons-vue'
import {computed, onMounted, Ref, ref} from 'vue' import { computed, onMounted, Ref, ref } from 'vue'
import {FormInstance} from 'ant-design-vue' import { FormInstance } from 'ant-design-vue'
import useTableProMax from '@/hooks/useTableProMax.ts' import useTableProMax from '@/hooks/useTableProMax.ts'
import {includes, isEmpty} from 'lodash-es' import { includes, isEmpty } from 'lodash-es'
import { import { BaseTableRowRecord, TableProMaxProps, TableProMaxRowSelect, TableProMaxSlots } from '@/types/components/table/index.ts'
BaseTableRowRecord,
TableProMaxProps,
TableProMaxRowSelect,
TableProMaxSlots
} from '@/types/components/table/index.ts'
// //
const selectKeys = ref<string[]>([]) const selectKeys = ref<string[]>([])
@ -156,7 +150,7 @@ const tableColumns = computed(() => {
dataIndex: 'index', dataIndex: 'index',
width: 60, width: 60,
title: '序号', title: '序号',
customRender: ({index}) => index + 1, customRender: ({ index }) => index + 1,
}) })
} }
} }
@ -172,24 +166,14 @@ const searchFormRef = ref<FormInstance>() as Ref<FormInstance>
*/ */
const searchParams = ref<P | Record<string, any>>(props.defaultSearchParams || {}) as Ref<P> const searchParams = ref<P | Record<string, any>>(props.defaultSearchParams || {}) as Ref<P>
const { const { loading, dataSource, pageParams, search, requestGetTableData, handleSizeChange, handleCurrentChange, resetState } = useTableProMax(
loading, props.requestApi,
dataSource, searchFormRef,
pageParams, searchParams,
search, props.isPagination,
requestGetTableData, props.dataCallback,
handleSizeChange, props.requestError
handleCurrentChange,
resetState
} = useTableProMax(
props.requestApi,
searchFormRef,
searchParams,
props.isPagination,
props.dataCallback,
props.requestError
) )
// console.log('pageParams', pageParams)
onMounted(() => props.requestAuto && requestGetTableData(true)) onMounted(() => props.requestAuto && requestGetTableData(true))