Skip to content

Commit

Permalink
test: 更新 ant-vue-table 的示例
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionad-Morotar committed Aug 19, 2023
1 parent 8050cf4 commit d4810a0
Show file tree
Hide file tree
Showing 8 changed files with 1,084 additions and 747 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Assuming a 400px height div, you can easily get a div with beautiful virtual scr

## ⚒️ Feature

- [x] **Powerful API**, have ability to deal with complex components[^1], such as vxe-table
- [x] **Powerful API**, have ability to deal with complex components[^1], such as vxe-table、ant-vue-table
- [x] **Customisable**, so that you can create your own scrollbar style, animation and user interaction
- [x] **Theme**, integrated with these style configurations: ElementPlus, Steam, CSS-Tricks ...
- [x] **Full Typed**, with the power of typescript
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"@vitejs/plugin-vue": "^2.3.4",
"ant-design-vue": "^4.0.0",
"cross-env": "^7.0.3",
"dayjs": "^1.11.7",
"element-plus": "^2.2.32",
Expand All @@ -59,8 +60,8 @@
"vue-eslint-parser": "^9.1.0",
"vue-tsc": "1.0.9",
"vue3": "npm:vue@^3.2.47",
"vxe-table": "^4.3.9",
"xe-utils": "^3.5.7"
"vxe-table": "^4.3.9",
"xe-utils": "^3.5.7"
},
"peerDependencies": {
"vue": "^3"
Expand All @@ -71,7 +72,7 @@
"svelte"
]
}
},
},
"lint-staged": {
"*.{js,ts,tsx,vue}": [
"eslint --fix"
Expand Down
3 changes: 3 additions & 0 deletions play/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { createApp } from "vue"
import ElementPlus from 'element-plus'
import {Table } from 'ant-design-vue'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// import 'ant-design-vue/dist/antd.css'
import 'element-plus/dist/index.css'

// main
Expand All @@ -20,6 +22,7 @@ import 'element-plus/dist/index.css'

app.use(VXETable)
app.use(ElementPlus)
app.use(Table)

app.mount('#play')
})()
12 changes: 8 additions & 4 deletions play/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<template>
<div class="play-container">
<h1># use-scrollbar</h1>
<p align="center">
<img width="555" alt="use-scrollbar" src="../../docs/assets/logo.png">
</p>
<p class="intro">
`use-scrollbar` enables a component based on a native scrollbar to replace its native scrollbar with a virtual scrollbar, NOT virtual scroll.
`Use-Scrollbar` enables a component relies on a native scrollbar to replace its native scrollbar with a virtual scrollbar instead, NOT virtual scroll.
</p>
<h2>## examples</h2>
<ol>
<li><a href="./compare-styles?type=normal">Simply Usage</a></li>
<li><a href="./vxe-table">VXETable + 虚拟滚动条</a></li>
<li><a href="./vxe-table-multy">多表格 + 虚拟滚动条</a></li>
<li><a href="./gantt">GanttElastic + 虚拟滚动条</a></li>
<li><a href="./ant-vue-table">ant-design-vue table + use-scrollbars</a></li>
<li><a href="./vxe-table">VXETable + use-scrollbars</a></li>
<li><a href="./vxe-table-multy">VXETable 多表格 + use-scrollbars</a></li>
<li><a href="./gantt">GanttElastic + use-scrollbars</a></li>
</ol>
<h2>## styles</h2>
<ol>
Expand Down
48 changes: 48 additions & 0 deletions play/src/ant-vue-table.vue
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>
79 changes: 79 additions & 0 deletions play/src/ant-vue-table/index.vue
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>
2 changes: 2 additions & 0 deletions play/src/vxe-table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ watch(() => props.enable, async (enable) => {
const $bodyXSpace = $table.querySelector(".vxe-body--x-space");
const $bodyYSpace = $table.querySelector(".vxe-body--y-space");
console.log('barStates', barStates)
barStates.setOffset({ y: { top: $header } });
barStates.init({
mount: tableRef,
Expand Down
Loading

0 comments on commit d4810a0

Please sign in to comment.