From 59166a5af8383e2a391379395ba59242316b8260 Mon Sep 17 00:00:00 2001 From: Miosas Date: Sun, 4 Jan 2026 14:56:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=B6=E4=BB=96=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=A0=B7=E5=BC=8F=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 131 +++++++++++++++--- .../main/ets/interface/ScrollEventData.ets | 6 +- .../src/main/ets/interface/callbackEvents.ets | 8 +- .../src/main/ets/util/VTableController.ets | 34 ++++- library/src/main/resources/rawfile/index.html | 2 +- .../src/main/resources/rawfile/vtable_util.js | 126 ++++++++--------- 6 files changed, 201 insertions(+), 106 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index ebaa02d..4e9e948 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -261,8 +261,26 @@ struct Index { }, 1000) as number; } + onUpdated(): void { + if (this.floatingWindowType !== 0) { + return; + } + // 清除之前的定时器 + if (this.timerId !== -1) { + clearTimeout(this.timerId); + } + + this.isShow = true; + this.texts = ['更新完成', '']; + + // 设置新的定时器 + this.timerId = setTimeout(() => { + this.isShow = false; + this.timerId = -1; + }, 1000) as number; + } + onClickCell(event: CellClickData) { - console.log(`===== onClickCell =====`) if (this.floatingWindowType !== 1) { return; } @@ -369,6 +387,63 @@ struct Index { }, 1000) as number; } + onSelectedClear() { + if (this.floatingWindowType !== 6) { + return; + } + + if (this.timerId !== -1) { + clearTimeout(this.timerId); + } + + this.isShow = true; + this.texts = ['点击空白取消了选中', '']; + + // 设置新的定时器,并保存ID + this.timerId = setTimeout(() => { + this.isShow = false; + this.timerId = -1; // 重置ID + }, 1000) as number; + } + + onScrollHorizontalEnd(event: ScrollEventData) { + if (this.floatingWindowType !== 7) { + return; + } + + if (this.timerId !== -1) { + clearTimeout(this.timerId); + } + + this.isShow = true; + this.texts = ['横向滚动到底部', JSON.stringify(event)]; + + // 设置新的定时器,并保存ID + this.timerId = setTimeout(() => { + this.isShow = false; + this.timerId = -1; // 重置ID + }, 1000) as number; + } + + onScrollVerticalEnd(event: ScrollEventData) { + if (this.floatingWindowType !== 7) { + return; + } + + if (this.timerId !== -1) { + clearTimeout(this.timerId); + } + + this.isShow = true; + this.texts = ['纵向滚动到底部', JSON.stringify(event)]; + + // 设置新的定时器,并保存ID + this.timerId = setTimeout(() => { + this.isShow = false; + this.timerId = -1; // 重置ID + }, 1000) as number; + } + build() { Column() { Scroll() { @@ -388,11 +463,15 @@ struct Index { option: this.option, onEvent: { onInitialized: (): void => this.onInitialized(), + onUpdated: (): void => this.onUpdated(), onClickCell: (event: CellClickData): void => this.onClickCell(event), onDBClickCell: (event: CellClickData): void => this.onDBClickCell(event), onSelectedCell: (event: CellSelectionData): void => this.onSelectedCell(event), onScroll: (event: ScrollEventData): void => this.onScroll(event), - onChangeCellValue: (event: CellChangeEvent): void => this.onChangeCellValue(event) + onChangeCellValue: (event: CellChangeEvent): void => this.onChangeCellValue(event), + onSelectedClear: (): void => this.onSelectedClear(), + onScrollHorizontalEnd: (event: ScrollEventData): void => this.onScrollHorizontalEnd(event), + onScrollVerticalEnd: (event: ScrollEventData): void => this.onScrollVerticalEnd(event) } }) if (this.isShow) { @@ -408,23 +487,35 @@ struct Index { .borderColor(Color.Black) .borderWidth(2) } + Slider({ + value: 1, + min: 1, + max: 1.5, + step: 0.1, + style: SliderStyle.InSet, + direction: Axis.Vertical, + reverse: true + }) + .height("20%") } .layoutWeight(1) Scroll() { Row() { Select([ - { value: '初始化浮窗' }, + { value: '初始化/更新浮窗' }, { value: '点击浮窗' }, { value: '双击浮窗' }, { value: '选中单元格' }, { value: '滚动表格' }, { value: '修改单元格值' }, + { value: '点击空白取消选中' }, + { value: '滚动到底部' } ]) .borderRadius(0) .backgroundColor('#70949292') .fontColor(Color.Black) - .value('初始化浮窗') + .value('初始化/更新浮窗') .onSelect((event) => { this.floatingWindowType = event }) @@ -441,40 +532,36 @@ struct Index { .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { - - this.vTableController.mergeCell( - Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), // startRow - Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), // startCol - Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), // endRow - Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) // endCol + Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), + Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) ); - - // this.vTableController.mergeCell(this.mergeCellParams[0], this.mergeCellParams[1], - // this.mergeCellParams[2], this.mergeCellParams[3]) }) Button('取消合并') .borderRadius(0) .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { - this.vTableController.unmergeCells( - Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), // startRow - Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), // startCol - Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), // endRow - Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) // endCol + Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), + Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) ); - - // this.vTableController.unmergeCells(this.mergeCellParams[0], this.mergeCellParams[1], - // this.mergeCellParams[2], this.mergeCellParams[3]) }) Button('自定义渲染') .borderRadius(0) .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { - this.vTableController.customRender(this.mergeCellParams[0], this.mergeCellParams[1],this.mergeCellParams[2], this.mergeCellParams[3]) + this.vTableController.customRender( + Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), + Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) + ) }) } diff --git a/library/src/main/ets/interface/ScrollEventData.ets b/library/src/main/ets/interface/ScrollEventData.ets index 5cd5c8b..3b108aa 100644 --- a/library/src/main/ets/interface/ScrollEventData.ets +++ b/library/src/main/ets/interface/ScrollEventData.ets @@ -10,8 +10,8 @@ export interface ScrollEventData { scrollWidth: number; viewHeight: number; viewWidth: number; - scrollDirection: string; - scrollRatioY: number; - dy: number; + scrollDirection?: string; + scrollRatioY?: number; + dy?: number; event?: Trusted; } \ No newline at end of file diff --git a/library/src/main/ets/interface/callbackEvents.ets b/library/src/main/ets/interface/callbackEvents.ets index 5dd9903..ccf9ee7 100644 --- a/library/src/main/ets/interface/callbackEvents.ets +++ b/library/src/main/ets/interface/callbackEvents.ets @@ -2,13 +2,13 @@ import { CellChangeEvent, CellClickData, CellSelectionData, ScrollEventData } fr export interface VTableOnEvent { onInitialized?: () => void - // onUpdated?: () => void + onUpdated?: () => void onClickCell?: (event: CellClickData) => void onDBClickCell?: (event: CellClickData) => void onSelectedCell?: (event: CellSelectionData) => void - // onSelectedClear?: () => void + onSelectedClear?: () => void onScroll?: (event: ScrollEventData) => void - // onScrollHorizontalEnd?: (event: ScrollOptions) => void - // onScrollVerticalEnd?: (options: ScrollOptions) => void + onScrollHorizontalEnd?: (event: ScrollEventData) => void + onScrollVerticalEnd?: (options: ScrollEventData) => void onChangeCellValue?: (event: CellChangeEvent) => void } \ No newline at end of file diff --git a/library/src/main/ets/util/VTableController.ets b/library/src/main/ets/util/VTableController.ets index 9a50518..d9a3429 100644 --- a/library/src/main/ets/util/VTableController.ets +++ b/library/src/main/ets/util/VTableController.ets @@ -5,6 +5,8 @@ export class VTableController { private controller?: webview.WebviewController; tableOnEvent: VTableOnEvent = {} private isInitialized = false; + private zoom = 0; + constructor(controller?: webview.WebviewController) { this.controller = controller; } @@ -29,10 +31,12 @@ export class VTableController { let event = JSON.parse(JSON.parse(msg!)) as Record; switch (event["type"]) { case "INITIALIZED": - // this.tableOnEvent.onInitialized?.(); this.tableOnEvent.onInitialized?.(); this.isInitialized = true; break; + case "UPDATED": + this.isInitialized && this.tableOnEvent.onUpdated?.(); + break; case "CLICK_CELL": if (this.isInitialized) { const data = JSON.parse(event["data"] as string) as CellClickData; @@ -63,6 +67,23 @@ export class VTableController { this.tableOnEvent.onChangeCellValue?.(data); } break; + case "SELECTED_CLEAR": + if (this.isInitialized) { + this.tableOnEvent.onSelectedClear?.(); + } + break; + case "SCROLL_VERTICAL_END": + if (this.isInitialized) { + const data = JSON.parse(event["data"] as string) as ScrollEventData; + this.tableOnEvent.onScrollVerticalEnd?.(data); + } + break; + case "SCROLL_HORIZONTAL_END": + if (this.isInitialized) { + const data = JSON.parse(event["data"] as string) as ScrollEventData; + this.tableOnEvent.onScrollHorizontalEnd?.(data); + } + break; } } @@ -123,13 +144,14 @@ export class VTableController { } // 自定义渲染 - customRender(startCol: number, startRow: number, endCol: number, endRow: number,id?:string,style?:Record){ + customRender(startCol: number, startRow: number, endCol: number, endRow: number, id?: string, + style?: Record) { if (!this.checkInitialized()) { return; } - const Style:Record = { - "borderColor":"red", - "borderLineWidth":4, + const Style: Record = { + "borderColor": "red", + "borderLineWidth": 4, } const styleStr = JSON.stringify(Style) this.controller!.runJavaScript(`customRender(${startCol},${startRow},${endCol},${endRow},"diagonal",${styleStr})`) @@ -215,7 +237,7 @@ export class VTableController { }) } - updateOption(option: Record>){ + updateOption(option: Record>) { if (!this.checkInitialized()) { return; } diff --git a/library/src/main/resources/rawfile/index.html b/library/src/main/resources/rawfile/index.html index bf03bfe..835cd54 100644 --- a/library/src/main/resources/rawfile/index.html +++ b/library/src/main/resources/rawfile/index.html @@ -2,7 +2,7 @@ - + Tabulator Test