-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8050cf4
commit d4810a0
Showing
8 changed files
with
1,084 additions
and
747 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div class="play-container" ref="playRef"> | ||
<div class="header"> | ||
<h4>## ant-vue table with Virtual Scrollbars</h4> | ||
<el-checkbox v-model="states.isVirtualScrollbar">表格虚拟滚动条</el-checkbox> | ||
</div> | ||
<a-table-pro ref="tableRef" :enable="states.isVirtualScrollbar" :columns="columns" :data-source="data" :pagination="{ pageSize: 50 }" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { reactive, onMounted, ref } from "vue"; | ||
import ATablePro from "./ant-vue-table/index.vue"; | ||
const playRef = ref(); | ||
const tableRef = ref(); | ||
onMounted(() => { | ||
console.log('playRef', playRef.value, tableRef.value) | ||
}) | ||
const states = reactive({ | ||
isVirtualScrollbar: false, | ||
}) | ||
const columns = [ | ||
{ title: 'Full Name', width: 100, dataIndex: 'name', key: 'name', fixed: 'left' }, | ||
{ title: 'Age', width: 100, dataIndex: 'age', key: 'age', fixed: 'left' }, | ||
{ title: 'Column 1', dataIndex: 'address', key: '1', width: 150 }, | ||
{ title: 'Column 2', dataIndex: 'address', key: '2', width: 150 }, | ||
{ title: 'Column 3', dataIndex: 'address', key: '3', width: 150 }, | ||
{ title: 'Column 4', dataIndex: 'address', key: '4', width: 150 }, | ||
{ title: 'Column 5', dataIndex: 'address', key: '5', width: 150 }, | ||
{ title: 'Column 6', dataIndex: 'address', key: '6', width: 150 }, | ||
{ title: 'Column 7', dataIndex: 'address', key: '7', width: 150 }, | ||
{ title: 'Column 8', dataIndex: 'address', key: '8' }, | ||
]; | ||
const data = []; | ||
for (let i = 0; i < 1000; i++) { | ||
data.push({ | ||
key: i, | ||
name: `Edrward ${i}`, | ||
age: 32, | ||
address: `London Park no. ${i}`, | ||
}); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<template> | ||
<a-table | ||
:class="[props.enable ? 'is-virtual-scrollbar' : '']" | ||
ref="tableRef" | ||
:scroll="scroll" | ||
v-bind="$attrs" | ||
> | ||
<slot /> | ||
</a-table> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { watch, ref, unref, computed } from "vue" | ||
import { useElementSize, until } from '@vueuse/core'; | ||
import { useScrollbar } from "@/hooks"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
enable: boolean | ||
}>(), | ||
{ | ||
enable: true | ||
} | ||
); | ||
const tableRef = ref(); | ||
const { width, height } = useElementSize(tableRef); | ||
const scroll = computed(() => ({ x: unref(width) + 160 /* ? */, y: unref(height) - 60 /* header height */ })) | ||
const barStates = useScrollbar(); | ||
watch(() => props.enable, async (enable) => { | ||
console.log('[info] 开启虚拟滚动条', enable) | ||
if (enable) { | ||
await until(tableRef.value).toMatch((x) => x?.$el?.parentElement); | ||
try { | ||
const $table = tableRef.value.$el; | ||
const $header = $table.querySelector(".ant-table-header"); | ||
const $bodyWrapper = $table.querySelector(".ant-table-body"); | ||
const $bodyContent = $table.querySelector(".ant-table-body > table"); | ||
console.log('barStates', barStates) | ||
barStates.setOffset({ y: { top: $header } }); | ||
barStates.init({ | ||
mount: tableRef, | ||
content: [$bodyContent], | ||
viewport: [$bodyWrapper] | ||
}); | ||
} catch (err) { | ||
console.error("[ERR] error when init virtual scrollbar", err, tableRef); | ||
} | ||
} else { | ||
barStates.destroy() | ||
} | ||
}, { | ||
immediate: true, | ||
}) | ||
</script> | ||
|
||
<style lang="less"> | ||
.is-virtual-scrollbar { | ||
&.ant-table-wrapper { | ||
box-sizing: border-box; | ||
border: solid 1px #333; | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
position: relative; | ||
td { | ||
white-space: nowrap; | ||
} | ||
.ant-table-body::-webkit-scrollbar { | ||
width: 0; | ||
height: 0; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.