diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 05b12040b77f82bfd61e4ee78a03bc2fdca1f713..21ebb4ef2e340af971fa7a00c38ecee3da7360c8 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -268,8 +268,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; } @@ -376,6 +394,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() { @@ -395,11 +470,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) { @@ -415,23 +494,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 }) @@ -448,40 +539,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 - // ); - // - // // this.vTableController.unmergeCells(this.mergeCellParams[0], this.mergeCellParams[1], - // // this.mergeCellParams[2], this.mergeCellParams[3]) - // }) + // .borderRadius(0) + // .backgroundColor('#70949292') + // .fontColor(Color.Black) + // .onClick(() => { + // this.vTableController.unmergeCells( + // 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]) + // ); + // }) 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]) + ) }) Button('取消自定义渲染') .borderRadius(0) diff --git a/library/src/main/ets/interface/ScrollEventData.ets b/library/src/main/ets/interface/ScrollEventData.ets index 5cd5c8b044da7a0a6a4671429252fb6c3d9453f8..3b108aa266296c82ea08612f7ed64483eee3bf7b 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 5dd990352cb37ecba7005143aa96d8ed604cb811..ccf9ee79d186526deac9c120b7321f6d4edd1c34 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 5666a440b6b7aad064e7a2f68240647474d4c29a..2890052e6816b5f69944c6bd493a1e4cc659ae60 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; } } @@ -228,7 +249,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 bf03bfe30dae4fa5f91b1eb217866fad2c4e50db..835cd54c74036b939cdea1a9dc6fafa16ea16d95 100644 --- a/library/src/main/resources/rawfile/index.html +++ b/library/src/main/resources/rawfile/index.html @@ -2,7 +2,7 @@ - + Tabulator Test