Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
bkunyun
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
Administrator
bkunyun
Commits
82e2d8ba
Commit
82e2d8ba
authored
Oct 25, 2022
by
chenshouchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 卡片列表适配调整
parent
ad209280
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
3 deletions
+42
-3
index.module.css
src/components/CommonComponents/CardTable/index.module.css
+1
-0
index.tsx
src/components/CommonComponents/CardTable/index.tsx
+36
-2
index.tsx
...ourceCenter/UserResources/UserResourcesTemplate/index.tsx
+5
-1
No files found.
src/components/CommonComponents/CardTable/index.module.css
View file @
82e2d8ba
...
@@ -4,4 +4,5 @@
...
@@ -4,4 +4,5 @@
flex-wrap
:
wrap
;
flex-wrap
:
wrap
;
}
}
.itemBox
{
.itemBox
{
/* flex: 1; */
}
}
src/components/CommonComponents/CardTable/index.tsx
View file @
82e2d8ba
import
{
useCallback
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
import
style
from
"./index.module.css"
;
import
style
from
"./index.module.css"
;
interface
ICardTableProps
{
interface
ICardTableProps
{
data
:
Array
<
any
>
;
// 列表数据
data
:
Array
<
any
>
;
// 列表数据
renderItem
:
any
;
// 单个卡片的渲染函数
renderItem
:
any
;
// 单个卡片的渲染函数
itemMinWidth
?:
number
;
// 单个卡片的最小宽度,有这个参数时numberOfColumns参数失效,效果为根据屏幕大小和单个卡片的最小宽度来适配每行渲染个数
tableKey
?:
string
;
// 表格数据的key
tableKey
?:
string
;
// 表格数据的key
numberOfColumns
?:
number
;
// 列数 每行渲染几个
numberOfColumns
?:
number
;
// 列数 每行渲染几个
horizontalSpacing
?:
number
;
// 水平方向的间隔
horizontalSpacing
?:
number
;
// 水平方向的间隔
...
@@ -14,10 +16,41 @@ const CardTable = (props: ICardTableProps) => {
...
@@ -14,10 +16,41 @@ const CardTable = (props: ICardTableProps) => {
data
,
data
,
renderItem
,
renderItem
,
tableKey
=
"id"
,
tableKey
=
"id"
,
numberOfColumns
=
3
,
numberOfColumns
:
propsNumberOfColumns
=
3
,
horizontalSpacing
=
20
,
horizontalSpacing
=
20
,
verticalSpacing
=
20
,
verticalSpacing
=
20
,
itemMinWidth
,
}
=
props
;
}
=
props
;
const
[
numberOfColumns
,
setNumberOfColumns
]
=
useState
(
3
);
const
getNumberOfColumns
=
useCallback
(()
=>
{
if
(
itemMinWidth
)
{
const
boxWidth
=
tableBoxRef
?.
current
?.
offsetWidth
;
if
(
boxWidth
)
{
setNumberOfColumns
(
Math
.
floor
(
boxWidth
/
itemMinWidth
));
}
else
{
setNumberOfColumns
(
propsNumberOfColumns
);
}
}
else
{
setNumberOfColumns
(
propsNumberOfColumns
);
}
},
[
itemMinWidth
,
propsNumberOfColumns
]);
useEffect
(()
=>
{
getNumberOfColumns
();
},
[
getNumberOfColumns
]);
const
tableBoxRef
:
any
=
useRef
(
null
);
const
boxWidth
=
useMemo
(()
=>
{
return
`
${
100
/
numberOfColumns
}
%`
;
},
[
numberOfColumns
]);
window
.
onresize
=
()
=>
{
getNumberOfColumns
();
};
return
(
return
(
<
div
<
div
className=
{
style
.
tableBox
}
className=
{
style
.
tableBox
}
...
@@ -25,6 +58,7 @@ const CardTable = (props: ICardTableProps) => {
...
@@ -25,6 +58,7 @@ const CardTable = (props: ICardTableProps) => {
marginLeft
:
`-${horizontalSpacing / 2}px`
,
marginLeft
:
`-${horizontalSpacing / 2}px`
,
marginRight
:
`-${horizontalSpacing / 2}px`
,
marginRight
:
`-${horizontalSpacing / 2}px`
,
}
}
}
}
ref=
{
tableBoxRef
}
>
>
{
data
.
map
((
item
,
index
)
=>
{
{
data
.
map
((
item
,
index
)
=>
{
return
(
return
(
...
@@ -32,7 +66,7 @@ const CardTable = (props: ICardTableProps) => {
...
@@ -32,7 +66,7 @@ const CardTable = (props: ICardTableProps) => {
className=
{
style
.
itemBox
}
className=
{
style
.
itemBox
}
key=
{
item
[
tableKey
]
?
item
[
tableKey
]
:
index
}
key=
{
item
[
tableKey
]
?
item
[
tableKey
]
:
index
}
style=
{
{
style=
{
{
width
:
`${100 / numberOfColumns}%`
,
width
:
boxWidth
,
paddingLeft
:
`${horizontalSpacing / 2}px`
,
paddingLeft
:
`${horizontalSpacing / 2}px`
,
paddingRight
:
`${horizontalSpacing / 2}px`
,
paddingRight
:
`${horizontalSpacing / 2}px`
,
paddingBottom
:
`${verticalSpacing}px`
,
paddingBottom
:
`${verticalSpacing}px`
,
...
...
src/views/ResourceCenter/UserResources/UserResourcesTemplate/index.tsx
View file @
82e2d8ba
...
@@ -162,7 +162,11 @@ const UserResourcesTemplate = observer(() => {
...
@@ -162,7 +162,11 @@ const UserResourcesTemplate = observer(() => {
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className=
{
style
.
tableBox
}
>
<
div
className=
{
style
.
tableBox
}
>
<
CardTable
data=
{
list
}
renderItem=
{
renderItem
}
></
CardTable
>
<
CardTable
data=
{
list
}
renderItem=
{
renderItem
}
minWidth=
{
377
}
></
CardTable
>
</
div
>
</
div
>
{
showAddTemplate
&&
(
{
showAddTemplate
&&
(
<
WorkFlowEdit
<
WorkFlowEdit
...
...
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