Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivManage
Commits
c065213b
Commit
c065213b
authored
Oct 28, 2020
by
张烨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: auto fix on save
parent
35381dc1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
69 deletions
+81
-69
setting.json
.vscode/setting.json
+6
-0
index.js
src/components/BaseTable/SearchBar/index.js
+0
-1
index.jsx
src/components/BaseTable/index.jsx
+75
-68
No files found.
.vscode/setting.json
0 → 100644
View file @
c065213b
{
"editor.codeActionsOnSave"
:
{
"source.fixAll"
:
true
}
}
\ No newline at end of file
src/components/BaseTable/SearchBar/index.js
View file @
c065213b
// eslint-disable-next-line button-has-type
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
BaseForm
from
'../../BaseForm'
;
...
...
src/components/BaseTable/index.jsx
View file @
c065213b
...
...
@@ -2,10 +2,8 @@ import React, { useEffect, useState } from 'react';
// import OperationBar from './OperationBar'
import
{
Table
}
from
'antd'
;
import
{
Resizable
}
from
'react-resizable'
;
import
SearchBar
from
'./SearchBar'
import
SearchBar
from
'./SearchBar'
;
import
styles
from
'./baseTable.less'
;
const
ResizableTitle
=
props
=>
{
const
{
onResize
,
width
,
...
restProps
}
=
props
;
...
...
@@ -34,17 +32,17 @@ const ResizableTitle = props => {
};
// 表格头变形的hook
const
useResizableClumns
=
(
clumns
)
=>
{
const
useResizableClumns
=
clumns
=>
{
const
[
clmns
,
setClmns
]
=
useState
(
clumns
);
if
(
!
clumns
)
return
null
;
const
[
clmns
,
setClmns
]
=
useState
(
clumns
)
const
handleResize
=
(
index
)
=>
(
e
,
{
size
})
=>
{
const
nextClmns
=
[...
clmns
]
const
handleResize
=
index
=>
(
e
,
{
size
})
=>
{
const
nextClmns
=
[...
clmns
];
nextClmns
[
index
]
=
{
...
nextClmns
[
index
],
width
:
size
.
width
}
setClmns
(
nextClmns
)
}
width
:
size
.
width
,
}
;
setClmns
(
nextClmns
)
;
}
;
return
clmns
.
map
((
col
,
index
)
=>
({
...
col
,
onHeaderCell
:
column
=>
({
...
...
@@ -52,84 +50,94 @@ const useResizableClumns = (clumns) => {
onResize
:
handleResize
(
index
),
}),
}));
}
}
;
// 渲染列表组件
const
renderComponents
=
(
componentOption
=
{})
=>
{
const
defaultComponents
=
{
header
:
{
cell
:
ResizableTitle
,
}
}
}
,
}
;
return
{
...
defaultComponents
,
...
componentOption
,
}
}
}
;
}
;
// 过滤列表数据
const
filterData
=
(
datas
,
searches
,
searchVal
)
=>
{
return
datas
.
filter
(
data
=>
{
return
searches
.
some
(
s
=>
s
.
filter
(
data
[
s
.
dataIndex
],
searchVal
[
s
.
dataIndex
]))
})
}
const
filterData
=
(
datas
,
searches
,
searchVal
)
=>
datas
.
filter
(
data
=>
searches
.
some
(
s
=>
s
.
filter
(
data
[
s
.
dataIndex
],
searchVal
[
s
.
dataIndex
])),
);
const
BaseTable
=
(
props
)
=>
{
const
{
searchBar
,
// 筛选栏属性{list: [{filter: () => boolean, key, dataIndex, label, type, initialValue?, options?}]}
operation
,
// 操作栏属性,可选
dataSource
,
// 数据源,可选
columns
,
// 列,必填
resizable
,
// 列宽是否可调整,可选
components
,
// 自定义table渲染,同antd/table, 可选
onRequest
,
// 请求数据接口,非必须,需返回Promise<{data, pagenation}>,可选,与dataSource冲突,优先onRequest
onSearchCommit
,
// 筛选回调, 可选
const
BaseTable
=
props
=>
{
const
{
searchBar
,
// 筛选栏属性{list: [{filter: () => boolean, key, dataIndex, label, type, initialValue?, options?}]}
operation
,
// 操作栏属性,可选
dataSource
,
// 数据源,可选
columns
,
// 列,必填
resizable
,
// 列宽是否可调整,可选
components
,
// 自定义table渲染,同antd/table, 可选
onRequest
,
// 请求数据接口,非必须,需返回Promise<{data, pagenation}>,可选,与dataSource冲突,优先onRequest
onSearchCommit
,
// 筛选回调, 可选
// onPageChange, // 翻页时回调
...
restProps
}
=
props
const
resizableClumns
=
resizable
?
useResizableClumns
(
columns
)
:
columns
const
[
dataList
,
setDataList
]
=
useState
(
dataSource
||
[])
const
[
pagenation
,
setPageNation
]
=
useState
({})
const
[
loading
,
setLoading
]
=
useState
(
false
)
const
[
seachVal
,
setSearchVal
]
=
useState
({})
...
restProps
}
=
props
;
let
resizableClumns
=
useResizableClumns
(
columns
);
resizableClumns
=
resizable
?
resizableClumns
:
columns
;
const
[
dataList
,
setDataList
]
=
useState
(
dataSource
||
[]);
const
[
pagenation
,
setPageNation
]
=
useState
({});
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
seachVal
,
setSearchVal
]
=
useState
({});
const
fetch
=
(
page
,
search
)
=>
{
search
=
search
||
seachVal
search
=
search
||
seachVal
;
if
(
onRequest
)
{
setLoading
(
true
)
setLoading
(
true
)
;
onRequest
(
page
||
pagenation
,
search
).
then
(
res
=>
{
console
.
log
(
res
)
setDataList
(
searchBar
?
filterData
(
res
.
data
,
searchBar
.
list
,
search
)
:
res
.
data
)
setPageNation
(
res
.
pagenation
)
setLoading
(
false
)
})
console
.
log
(
res
);
setDataList
(
searchBar
?
filterData
(
res
.
data
,
searchBar
.
list
,
search
)
:
res
.
data
,
);
setPageNation
(
res
.
pagenation
);
setLoading
(
false
);
});
}
else
{
setDataList
(
searchBar
?
filterData
(
dataSource
,
searchBar
.
list
,
search
)
:
dataSource
)
setPageNation
(
page
)
setDataList
(
searchBar
?
filterData
(
dataSource
,
searchBar
.
list
,
search
)
:
dataSource
,
);
setPageNation
(
page
);
}
}
}
;
const
handleChange
=
(
page
)
=>
{
fetch
(
page
)
}
const
handleChange
=
page
=>
{
fetch
(
page
)
;
}
;
const
handleSearchCommit
=
(
value
)
=>
{
console
.
log
(
value
)
}
const
handleSearchCommit
=
value
=>
{
console
.
log
(
value
)
;
}
;
useEffect
(()
=>
{
fetch
(
pagenation
)
},
[
dataSource
])
fetch
(
pagenation
)
;
},
[
dataSource
])
;
return
(
<
div
className=
{
styles
.
BaseTable
}
>
{
searchBar
?.
list
?.
length
>
0
&&
(
<
SearchBar
{
...
searchBar
}
onCommit=
{
handleSearchCommit
}
/>
)
}
<
Table
dataSource=
{
dataList
}
loading=
{
loading
}
components=
{
renderComponents
(
components
)
}
columns=
{
resizableClumns
}
onChange=
{
handleChange
}
{
...
restProps
}
/>
</
div
>
);
};
return
<
div
className=
{
styles
.
BaseTable
}
>
{
searchBar
?.
list
?.
length
>
0
&&
<
SearchBar
{
...
searchBar
}
onCommit=
{
handleSearchCommit
}
/>
}
<
Table
dataSource=
{
dataList
}
loading=
{
loading
}
components=
{
renderComponents
(
components
)
}
columns=
{
resizableClumns
}
onChange=
{
handleChange
}
{
...
restProps
}
/>
</
div
>
}
export
default
BaseTable
\ No newline at end of file
export
default
BaseTable
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment