diff --git a/packages/amis-ui/scss/components/_cards.scss b/packages/amis-ui/scss/components/_cards.scss index 6ad5329de..99e312a2e 100644 --- a/packages/amis-ui/scss/components/_cards.scss +++ b/packages/amis-ui/scss/components/_cards.scss @@ -1,4 +1,8 @@ .#{$ns}Cards { + // 黑科技,让 scrollIntoView 能够跑正确的位置 + margin-top: calc(var(--affix-offset-top) * -1); + padding-top: var(--affix-offset-top); + &-toolbar { @include clearfix(); padding: var(--Cards-toolbar-marginY) var(--Cards-toolbar-marginX) diff --git a/packages/amis-ui/scss/components/_list.scss b/packages/amis-ui/scss/components/_list.scss index ac124bfb6..c20cf26fd 100644 --- a/packages/amis-ui/scss/components/_list.scss +++ b/packages/amis-ui/scss/components/_list.scss @@ -1,5 +1,8 @@ .#{$ns}List { position: relative; + // 黑科技,让 scrollIntoView 能够跑正确的位置 + margin-top: calc(var(--affix-offset-top) * -1); + padding-top: var(--affix-offset-top); &-items { border-radius: var(--List-borderRadius); diff --git a/packages/amis-ui/scss/components/_table.scss b/packages/amis-ui/scss/components/_table.scss index 5a2633215..0ce0bc9ba 100644 --- a/packages/amis-ui/scss/components/_table.scss +++ b/packages/amis-ui/scss/components/_table.scss @@ -1,6 +1,10 @@ .#{$ns}Table { position: relative; + // 黑科技,让 scrollIntoView 能够跑正确的位置 + margin-top: calc(var(--affix-offset-top) * -1); + padding-top: var(--affix-offset-top); + border-radius: var(--Table-borderRadius); margin-bottom: var(--gap-md); diff --git a/packages/amis/src/renderers/CRUD.tsx b/packages/amis/src/renderers/CRUD.tsx index ece4cdd7f..3a05d9a30 100644 --- a/packages/amis/src/renderers/CRUD.tsx +++ b/packages/amis/src/renderers/CRUD.tsx @@ -1435,9 +1435,13 @@ export default class CRUD extends React.Component { this.search(undefined, undefined, undefined); if (autoJumpToTopOnPagerChange && this.control) { - (findDOMNode(this.control) as HTMLElement).scrollIntoView(); - const scrolledY = window.scrollY; - scrolledY && window.scroll(0, scrolledY); + if (this.control.scrollToTop) { + this.control.scrollToTop(); + } else { + (findDOMNode(this.control) as HTMLElement).scrollIntoView(); + const scrolledY = window.scrollY; + scrolledY && window.scroll(0, scrolledY); + } } } diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index 480595534..499ac910a 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -548,6 +548,7 @@ export default class Table extends React.Component { resizable: true }; + dom = React.createRef(); table?: HTMLTableElement; sortable?: Sortable; dragTip?: HTMLElement; @@ -989,6 +990,15 @@ export default class Table extends React.Component { scoped.unRegisterComponent(this); } + scrollToTop() { + this.dom.current?.scrollIntoView(); + if (this.props.autoFillHeight) { + this.table?.scrollIntoView(); + } + const scrolledY = window.scrollY; + scrolledY && window.scroll(0, scrolledY); + } + rowPathPlusOffset(path: string, offset = 0) { const list = path.split('.').map((item: any) => parseInt(item, 10)); list[0] += offset; @@ -2830,6 +2840,7 @@ export default class Table extends React.Component { return (