|
|
@@ -2,6 +2,7 @@
|
|
|
<div class="tablePaganations">
|
|
|
<a-config-provider :locale="locale">
|
|
|
<a-table
|
|
|
+ id="commonTable"
|
|
|
class="ant-table-striped"
|
|
|
bordered
|
|
|
size="small"
|
|
|
@@ -10,7 +11,7 @@
|
|
|
:data-source="dataSource"
|
|
|
:columns="columns"
|
|
|
:row-key="(record) => record.id"
|
|
|
- :scroll="scroll"
|
|
|
+ :scroll="{ y: yScroll }"
|
|
|
:pagination="havePage ? pagination : false"
|
|
|
:row-class-name="
|
|
|
(_record, index) => (index % 2 === 1 ? 'table-striped' : null)
|
|
|
@@ -48,36 +49,47 @@ import {
|
|
|
defineEmits,
|
|
|
defineExpose,
|
|
|
watch,
|
|
|
+ onMounted,
|
|
|
} from 'vue';
|
|
|
+import { getTableScroll } from '../common/tableScroll.js';
|
|
|
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN';
|
|
|
const locale = ref(zhCN);
|
|
|
+
|
|
|
const props = defineProps({
|
|
|
+ // 表格数据
|
|
|
dataSource: {
|
|
|
type: Object,
|
|
|
required: true,
|
|
|
},
|
|
|
+ // 表头数据
|
|
|
columns: {
|
|
|
type: Object,
|
|
|
required: true,
|
|
|
},
|
|
|
+ // 是否可选择
|
|
|
isSelect: {
|
|
|
type: Boolean,
|
|
|
},
|
|
|
+ // 表格loading
|
|
|
isLoading: {
|
|
|
type: Boolean,
|
|
|
},
|
|
|
+ // 数据总数
|
|
|
total: {
|
|
|
type: Number,
|
|
|
default: 0,
|
|
|
},
|
|
|
+ // 是否分页
|
|
|
havePage: {
|
|
|
type: Boolean,
|
|
|
default: true,
|
|
|
},
|
|
|
- scroll: {
|
|
|
- type: Object,
|
|
|
- default: () => ({ y: 400 }),
|
|
|
+ // 表格距底部高度
|
|
|
+ extraHeight: {
|
|
|
+ type: Number,
|
|
|
+ default: undefined,
|
|
|
},
|
|
|
+ // 选择的key值
|
|
|
selectedKeys: {
|
|
|
type: Array,
|
|
|
default: () => [],
|
|
|
@@ -100,6 +112,9 @@ const pagination = reactive({
|
|
|
total: props.total,
|
|
|
});
|
|
|
|
|
|
+const yScroll = ref(400); //默认滚动高度
|
|
|
+const extraHeight = ref(undefined); //表格距离底部值
|
|
|
+
|
|
|
// 最后一次排序信息
|
|
|
const lastSorter = reactive({ field: '', order: '' });
|
|
|
|
|
|
@@ -109,6 +124,26 @@ const state = reactive({
|
|
|
selectedRowKeys: [],
|
|
|
});
|
|
|
|
|
|
+onMounted(() => {
|
|
|
+ if (!props.havePage) {
|
|
|
+ extraHeight.value = 30;
|
|
|
+ } else {
|
|
|
+ extraHeight.value = props.extraHeight;
|
|
|
+ }
|
|
|
+ onResizeTable();
|
|
|
+ window.onresize = () => {
|
|
|
+ onResizeTable();
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+// 表格位置
|
|
|
+const onResizeTable = () => {
|
|
|
+ yScroll.value = getTableScroll({
|
|
|
+ extraHeight: extraHeight.value,
|
|
|
+ id: 'commonTable',
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
//点击页码事件
|
|
|
const changePage = (current, size) => {
|
|
|
pagination.current = current;
|
|
|
@@ -206,6 +241,7 @@ watch(
|
|
|
props,
|
|
|
newData => {
|
|
|
pagination.total = newData.total;
|
|
|
+ extraHeight.value = newData.extraHeight;
|
|
|
},
|
|
|
{ immediate: true, deep: true },
|
|
|
);
|