Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zxkws committed Nov 18, 2024
1 parent f70b0c1 commit be0915f
Show file tree
Hide file tree
Showing 32 changed files with 1,223 additions and 3,974 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ desktop.ini # Windows
logs/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn-error.log*
myenv
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@

```shell
pnpm add @packages/test-work --workspace -w
```

```sh
python3 -m venv myenv
source myenv/bin/activate
pip install DrissionPage
deactivate
```
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,33 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@types/node": "^22.5.5",
"@types/react": "^18.1.3",
"@types/react-dom": "^18.1.3",
"@vitejs/plugin-react": "^4.3.1",
"css-loader": "^7.1.2",
"eslint": "^7.32.0",
"html-webpack-plugin": "^5.6.0",
"sass-loader": "^16.0.2",
"style-loader": "^4.0.0",
"stylelint": "^13.13.1",
"ts-loader": "^9.5.1",
"typescript": "^5.6.3",
"vite": "^5.4.6",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4",
"@rollup/plugin-commonjs": "^26.0.1",
"@vitejs/plugin-react": "^4.3.1",
"css-loader": "^7.1.2",
"sass-loader": "^16.0.2",
"style-loader": "^4.0.0",
"typescript": "^4.4.3",
"webpack-dev-server": "^5.1.0"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@packages/utils": "workspace:*",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"axios": "^1.7.7",
"less": "^4.2.0",
"path-to-regexp": "^8.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.4.5",
"url-parse": "^1.5.10"
}
Expand Down
9 changes: 4 additions & 5 deletions packages/v-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
"serve": "vite preview"
},
"dependencies": {
"@ice/stark-app": "^1.4.1",
"@icon-park/vue-next": "^1.4.2",
"@packages/test-work": "workspace:*",
"@surely-vue/table": "^4.3.13",
"@tailwindcss/forms": "^0.5.9",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"cssnano": "^7.0.6",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"sass": "^1.77.8",
"vue": "^3.2.16",
"vue": "^3.5.12",
"vue-router": "^4.0.11"
},
"devDependencies": {
Expand All @@ -27,7 +26,7 @@
"tailwindcss": "^3.4.5",
"unplugin-auto-import": "^0.18.0",
"vite-plugin-index-html": "^2.0.0",
"vue-tsc": "^2.1.6"
"vue-tsc": "^2.1.10"
},
"license": "MIT"
}
11 changes: 11 additions & 0 deletions packages/v-app/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module "vue" {
export interface GlobalComponents {
STable: typeof import("@surely-vue/table")["STable"];
STableColumn: typeof import("@surely-vue/table")["STableColumn"];
STableColumnGroup: typeof import("@surely-vue/table")["STableColumnGroup"];
STableSummary: typeof import("@surely-vue/table")["STableSummary"];
STableSummaryRow: typeof import("@surely-vue/table")["STableSummaryRow"];
STableSummaryCell: typeof import("@surely-vue/table")["STableSummaryCell"];
}
}
export {};
86 changes: 85 additions & 1 deletion packages/v-app/src/components/Detail.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
<!-- src/components/DynamicHeightList.vue -->
<template>
<h1>Detail Page</h1>
<div
ref="containerRef"
class="flex-1 overflow-y-auto box-border relative"
@scroll="handleScroll"
>
<div :style="{ height: totalHeight + 'px' }"></div>
<ul
class="absolute top-0 left-0"
:style="{
transform: `translateY(${offsetY}px)`,
}"
>
<li
v-for="item in visibleItems"
:key="item.id"
class="text-gray-700 bg-gray-50 border-y-[1px]"
:style="{ height: item.height + 'px' }"
>
{{ item.text }}
</li>
</ul>
</div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from "vue";

const total = ref(100);
const containerRef = ref(null);
const items = ref([]);
const startIndex = ref(0);
const offsetY = ref(0);

function generateDynamicHeightData(count) {
return Array.from({ length: count }, (_, i) => ({
id: i,
text: `Item ${i + 1}`,
height: 50 + Math.floor(Math.random() * 100), // 动态高度在 50 到 150px 之间
}));
}

const totalHeight = computed(() => {
return items.value.reduce((sum, item) => sum + item.height, 0);
});

const visibleItems = computed(() => {
return items.value.slice(startIndex.value, startIndex.value + 20);
});

function updateVisibleItems() {
if (!containerRef.value) return;

const scrollTop = containerRef.value.scrollTop;

let currentHeight = 0;
let start = 0;

for (let i = 0; i < items.value.length; i++) {
if (currentHeight >= scrollTop && start === 0) {
start = i;
}
currentHeight += items.value[i].height;
}

startIndex.value = Math.max(0, start - 5); // 预加载5个项

offsetY.value = items.value
.slice(0, startIndex.value)
.reduce((sum, item) => sum + item.height, 0);
}

function handleScroll() {
updateVisibleItems();
}

onMounted(() => {
items.value = generateDynamicHeightData(total.value);
updateVisibleItems();
window.addEventListener("resize", updateVisibleItems);
});

onUnmounted(() => {
window.removeEventListener("resize", updateVisibleItems);
});
</script>
79 changes: 78 additions & 1 deletion packages/v-app/src/components/List.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
<template>
<h1>List Page</h1>
<div
ref="containerRef"
class="flex-1 overflow-y-auto box-border relative"
@scroll="handleScroll"
>
<div :style="{ height: totalHeight + 'px' }"></div>
<ul
class="absolute top-0 left-0"
:style="{
transform: `translateY(${offsetY}px)`, // 设置偏移量
}"
>
<li
v-for="item in visibleItems"
:key="item.id"
class="border-y-[1px] text-gray-700 h-[50px]"
>
{{ item.text }}
</li>
</ul>
</div>
</template>

<script setup>
import { ref, onMounted, computed } from "vue";
const items = ref([]);
const total = ref(200); // 总条目数,调大测试是否能正常渲染到底部
const itemHeight = 50; // 每个条目的高度
const containerRef = ref();
const containerHeight = computed(() => containerRef.value?.clientHeight || 0); // 容器固定高度
const visibleCount = computed(() =>
Math.ceil(containerHeight.value / itemHeight)
); // 可见条目数量
// 总内容高度,确保滚动的区域正确覆盖所有内容
const totalHeight = computed(() => total.value * itemHeight);
// 记录起始索引和偏移量
const startIndex = ref(0);
const offsetY = ref(0); // 实际偏移量,用于控制 translateY
// 增加缓冲区,确保上下滚动有足够的渲染项
const bufferSize = 10;
const visibleItems = computed(() => {
if (!visibleCount.value) return [];
const start = Math.max(0, startIndex.value - bufferSize);
const end = Math.min(
startIndex.value + visibleCount.value + bufferSize,
total.value
);
return items.value.slice(start, end);
});
function handleScroll(event) {
// 获取真实的 scrollTop 值
const scrollTop = event.target.scrollTop;
// 根据 scrollTop 计算起始索引
startIndex.value = Math.floor(scrollTop / itemHeight);
// 计算偏移量 offsetY,用于 translateY
offsetY.value = startIndex.value * itemHeight;
}
function generateFixedHeightData(count) {
return Array.from({ length: count }, (_, i) => ({
id: i,
text: `Item ${i + 1}`,
}));
}
onMounted(() => {
items.value = generateFixedHeightData(total.value);
});
</script>
<style scoped></style>
5 changes: 5 additions & 0 deletions packages/v-app/src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const menus = [
value: "siteProxy",
name: "siteProxy",
},
{
label: "table",
value: "table",
name: "table",
},
];
</script>
<template>
Expand Down
7 changes: 7 additions & 0 deletions packages/v-app/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createApp } from "vue";
import type { App as Root } from "vue";
import "@surely-vue/table/dist/index.less";
import STable, { setLicenseKey } from "@surely-vue/table";

import isInIcestark from "./utils/isInIcestark";

Expand All @@ -15,6 +17,11 @@ let vue: Root<Element> | null = null;

const runApp = (container: Element | string) => {
vue = createApp(App);
setLicenseKey(
"0b50c5c2999298c91d183c696087eb90T1JERVI6MDAwMDEsRVhQSVJZPTQxMDIzNTg0MDAwMDAsRE9NQUlOPV8sS0VZVkVSU0lPTj0xLFVMVElNQVRFPTE="
);

vue.use(STable);
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
vue.use(pinia);
Expand Down
4 changes: 4 additions & 0 deletions packages/v-app/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const routes = [
path: "/siteProxy",
component: () => import("../views/SiteProxy/index.vue"),
},
{
path: "/table",
component: () => import("../views/table/index.vue"),
},
],
},
{
Expand Down
Loading

0 comments on commit be0915f

Please sign in to comment.