Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
factory_front
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinjianhui
factory_front
Commits
7bbd818e
Commit
7bbd818e
authored
Apr 10, 2024
by
qinjianhui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 表格支持动态宽度
parent
bc2d1dc3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
src/utils/hooks/useElTableColumnWidth.ts
+23
-4
No files found.
src/utils/hooks/useElTableColumnWidth.ts
View file @
7bbd818e
...
@@ -6,15 +6,33 @@ export default function useElTableColumnWidth(
...
@@ -6,15 +6,33 @@ export default function useElTableColumnWidth(
selector
:
string
,
selector
:
string
,
):
[
Ref
<
HTMLElement
|
null
>
,
Ref
<
number
>
]
{
):
[
Ref
<
HTMLElement
|
null
>
,
Ref
<
number
>
]
{
const
tableWrapperRef
=
ref
<
HTMLDivElement
|
null
>
(
null
)
const
tableWrapperRef
=
ref
<
HTMLDivElement
|
null
>
(
null
)
let
cleanupResizeEventListener
:
(()
=>
void
)
|
undefined
const
width
=
ref
(
0
)
const
width
=
ref
(
0
)
const
onThOrderDetailResize
=
debounce
(()
=>
{
let
cleanupResizeEventListener
:
(()
=>
void
)
|
undefined
let
cleanupThResizeEventListener
:
(()
=>
void
)
|
undefined
let
currentTh
:
HTMLElement
|
null
=
null
const
onThResize
=
()
=>
{
if
(
currentTh
)
width
.
value
=
currentTh
.
offsetWidth
}
const
watchThSizeChange
=
(
th
:
HTMLElement
)
=>
{
if
(
currentTh
===
th
)
return
currentTh
=
th
cleanupThResizeEventListener
?.()
addResizeListener
(
th
,
onThResize
)
cleanupThResizeEventListener
=
()
=>
{
removeResizeListener
(
th
,
onThResize
)
currentTh
=
null
}
}
const
onTableWrapperResize
=
debounce
(()
=>
{
const
el
=
tableWrapperRef
.
value
const
el
=
tableWrapperRef
.
value
if
(
!
el
)
return
if
(
!
el
)
return
const
th
=
el
.
querySelector
(
selector
)
as
HTMLElement
|
null
const
th
=
el
.
querySelector
(
selector
)
as
HTMLElement
|
null
if
(
th
)
{
if
(
th
)
{
width
.
value
=
th
.
offsetWidth
width
.
value
=
th
.
offsetWidth
watchThSizeChange
(
th
)
}
}
},
50
)
},
50
)
...
@@ -22,13 +40,14 @@ export default function useElTableColumnWidth(
...
@@ -22,13 +40,14 @@ export default function useElTableColumnWidth(
const
el
=
tableWrapperRef
.
value
const
el
=
tableWrapperRef
.
value
if
(
!
el
)
return
if
(
!
el
)
return
cleanupResizeEventListener
=
()
=>
{
cleanupResizeEventListener
=
()
=>
{
removeResizeListener
(
el
,
onT
hOrderDetail
Resize
)
removeResizeListener
(
el
,
onT
ableWrapper
Resize
)
}
}
addResizeListener
(
el
,
onT
hOrderDetail
Resize
)
addResizeListener
(
el
,
onT
ableWrapper
Resize
)
})
})
onBeforeUnmount
(()
=>
{
onBeforeUnmount
(()
=>
{
cleanupResizeEventListener
?.()
cleanupResizeEventListener
?.()
cleanupThResizeEventListener
?.()
})
})
return
[
tableWrapperRef
,
width
]
return
[
tableWrapperRef
,
width
]
...
...
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