Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
598ce5a1
Unverified
提交
598ce5a1
authored
12月 28, 2021
作者:
George Tan
提交者:
GitHub
12月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(table component): add 'scrollTo' table action (#1538)
上级
8c607b38
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
63 行增加
和
0 行删除
+63
-0
BasicTable.vue
src/components/Table/src/BasicTable.vue
+4
-0
useScrollTo.ts
src/components/Table/src/hooks/useScrollTo.ts
+55
-0
useTable.ts
src/components/Table/src/hooks/useTable.ts
+3
-0
table.ts
src/components/Table/src/types/table.ts
+1
-0
没有找到文件。
src/components/Table/src/BasicTable.vue
浏览文件 @
598ce5a1
...
...
@@ -52,6 +52,7 @@
import
{
useLoading
}
from
'./hooks/useLoading'
;
import
{
useRowSelection
}
from
'./hooks/useRowSelection'
;
import
{
useTableScroll
}
from
'./hooks/useTableScroll'
;
import
{
useTableScrollTo
}
from
'./hooks/useTableScrollTo'
;
import
{
useCustomRow
}
from
'./hooks/useCustomRow'
;
import
{
useTableStyle
}
from
'./hooks/useTableStyle'
;
import
{
useTableHeader
}
from
'./hooks/useTableHeader'
;
...
...
@@ -186,6 +187,8 @@
getDataSourceRef
,
);
const
{
scrollTo
}
=
useTableScrollTo
(
tableElRef
,
getDataSourceRef
);
const
{
customRow
}
=
useCustomRow
(
getProps
,
{
setSelectedRowKeys
,
getSelectRowKeys
,
...
...
@@ -298,6 +301,7 @@
setCacheColumnsByField
,
expandAll
,
collapseAll
,
scrollTo
,
getSize
:
()
=>
{
return
unref
(
getBindValues
).
size
as
SizeType
;
},
...
...
src/components/Table/src/hooks/useScrollTo.ts
0 → 100644
浏览文件 @
598ce5a1
import
type
{
ComputedRef
,
Ref
}
from
'vue'
;
import
{
nextTick
,
unref
}
from
'vue'
;
import
{
warn
}
from
'/@/utils/log'
;
export
function
useTableScrollTo
(
tableElRef
:
Ref
<
ComponentRef
>
,
getDataSourceRef
:
ComputedRef
<
Recordable
[]
>
,
)
{
let
bodyEl
:
HTMLElement
|
null
;
async
function
findTargetRowToScroll
(
targetRowData
:
Recordable
)
{
const
{
id
}
=
targetRowData
;
const
targetRowEl
:
HTMLElement
|
null
|
undefined
=
bodyEl
?.
querySelector
(
`[data-row-key="
${
id
}
"]`
,
);
//Add a delay to get new dataSource
await
nextTick
();
bodyEl
?.
scrollTo
({
top
:
targetRowEl
?.
offsetTop
??
0
,
behavior
:
'smooth'
,
});
}
function
scrollTo
(
pos
:
string
):
void
{
const
table
=
unref
(
tableElRef
);
if
(
!
table
)
return
;
const
tableEl
:
Element
=
table
.
$el
;
if
(
!
tableEl
)
return
;
if
(
!
bodyEl
)
{
bodyEl
=
tableEl
.
querySelector
(
'.ant-table-body'
);
if
(
!
bodyEl
)
return
;
}
const
dataSource
=
unref
(
getDataSourceRef
);
if
(
!
dataSource
)
return
;
// judge pos type
if
(
pos
===
'top'
)
{
findTargetRowToScroll
(
dataSource
[
0
]);
}
else
if
(
pos
===
'bottom'
)
{
findTargetRowToScroll
(
dataSource
[
dataSource
.
length
-
1
]);
}
else
{
const
targetRowData
=
dataSource
.
find
((
data
)
=>
data
.
id
===
pos
);
if
(
targetRowData
)
{
findTargetRowToScroll
(
targetRowData
);
}
else
{
warn
(
`id:
${
pos
}
doesn't exist`
);
}
}
}
return
{
scrollTo
};
}
src/components/Table/src/hooks/useTable.ts
浏览文件 @
598ce5a1
...
...
@@ -155,6 +155,9 @@ export function useTable(tableProps?: Props): [
collapseAll
:
()
=>
{
getTableInstance
().
collapseAll
();
},
scrollTo
:
(
pos
:
string
)
=>
{
getTableInstance
().
scrollTo
(
pos
);
},
};
return
[
register
,
methods
];
...
...
src/components/Table/src/types/table.ts
浏览文件 @
598ce5a1
...
...
@@ -88,6 +88,7 @@ export interface TableActionType {
clearSelectedRowKeys
:
()
=>
void
;
expandAll
:
()
=>
void
;
collapseAll
:
()
=>
void
;
scrollTo
:
(
pos
:
string
)
=>
void
;
// pos: id | "top" | "bottom"
getSelectRowKeys
:
()
=>
string
[];
deleteSelectRowByKey
:
(
key
:
string
)
=>
void
;
setPagination
:
(
info
:
Partial
<
PaginationProps
>
)
=>
void
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论