Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 crud 分页点击页面位置跳转问题 Close: #9667 #10643

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/amis-ui/scss/components/_cards.scss
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions packages/amis-ui/scss/components/_list.scss
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 4 additions & 0 deletions packages/amis-ui/scss/components/_table.scss
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
10 changes: 7 additions & 3 deletions packages/amis/src/renderers/CRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1435,9 +1435,13 @@ export default class CRUD extends React.Component<CRUDProps, any> {
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);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export default class Table extends React.Component<TableProps, object> {
resizable: true
};

dom = React.createRef<HTMLDivElement>();
table?: HTMLTableElement;
sortable?: Sortable;
dragTip?: HTMLElement;
Expand Down Expand Up @@ -989,6 +990,15 @@ export default class Table extends React.Component<TableProps, object> {
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;
Expand Down Expand Up @@ -2830,6 +2840,7 @@ export default class Table extends React.Component<TableProps, object> {

return (
<div
ref={this.dom}
className={cx('Table', {'is-mobile': mobileUI}, className, {
'Table--unsaved': !!store.modified || !!store.moved,
'Table--autoFillHeight': autoFillHeight
Expand Down
Loading