Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
najiu-frontend
najiu-admin-template
Commits
9abf1763
Commit
9abf1763
authored
Oct 30, 2020
by
vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(modal): optimize table embedding height calculation problem
parent
84c9d78f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
34 deletions
+52
-34
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+5
-0
BasicModal.tsx
src/components/Modal/src/BasicModal.tsx
+3
-3
ModalWrapper.tsx
src/components/Modal/src/ModalWrapper.tsx
+19
-16
provideModal.ts
src/components/Modal/src/provideModal.ts
+11
-0
useTableScroll.ts
src/components/Table/src/hooks/useTableScroll.ts
+14
-15
No files found.
CHANGELOG.zh_CN.md
View file @
9abf1763
...
...
@@ -12,6 +12,11 @@
-
表单代码优化重构
### ⚡ Performance Improvements
-
Modal slot 可以覆盖
-
优化表格嵌入高度计算问题
### 🎫 Chores
-
添加部分注释
...
...
src/components/Modal/src/BasicModal.tsx
View file @
9abf1763
...
...
@@ -225,11 +225,11 @@ export default defineComponent({
{
...
{
...
attrs
,
...
props
,
...
unref
(
getProps
)
}}
>
{
{
...
extendSlots
(
slots
,
[
'
default
'
]),
default
:
()
=>
renderContent
(),
closeIcon
:
()
=>
renderClose
(),
footer
:
()
=>
renderFooter
(),
closeIcon
:
()
=>
renderClose
(),
title
:
()
=>
renderTitle
(),
...
extendSlots
(
slots
,
[
'
default
'
]),
default
:
()
=>
renderContent
(),
}
}
</
Modal
>
);
...
...
src/components/Modal/src/ModalWrapper.tsx
View file @
9abf1763
...
...
@@ -15,10 +15,12 @@ import {
import
{
Spin
}
from
'
ant-design-vue
'
;
import
{
useWindowSizeFn
}
from
'
/@/hooks/event/useWindowSize
'
;
import
{
useTimeout
}
from
'
/@/hooks/core/useTimeout
'
;
//
import { useTimeout } from '/@/hooks/core/useTimeout';
import
{
getSlot
}
from
'
/@/utils/helper/tsxHelper
'
;
import
{
useElResize
}
from
'
/@/hooks/event/useElResize
'
;
import
{
provideModal
}
from
'
./provideModal
'
;
export
default
defineComponent
({
name
:
'
ModalWrapper
'
,
props
:
{
...
...
@@ -56,6 +58,11 @@ export default defineComponent({
const
wrapperRef
=
ref
<
HTMLElement
|
null
>
(
null
);
const
spinRef
=
ref
<
any
>
(
null
);
const
realHeightRef
=
ref
(
0
);
// 重试次数
// let tryCount = 0;
let
stopElResizeFn
:
Fn
=
()
=>
{};
provideModal
(
setModalHeight
);
const
wrapStyle
=
computed
(()
=>
{
return
{
...
...
@@ -65,10 +72,6 @@ export default defineComponent({
};
});
// 重试次数
let
tryCount
=
0
;
let
stopElResizeFn
:
Fn
=
()
=>
{};
watchEffect
(()
=>
{
setModalHeight
();
});
...
...
@@ -123,17 +126,17 @@ export default defineComponent({
}
await
nextTick
();
const
spinEl
=
unref
(
spinRef
);
if
(
!
spinEl
)
{
useTimeout
(()
=>
{
// retry
if
(
tryCount
<
3
)
{
setModalHeight
();
}
tryCount
++
;
},
10
);
return
;
}
tryCount
=
0
;
//
if (!spinEl) {
//
useTimeout(() => {
//
// retry
//
if (tryCount < 3) {
//
setModalHeight();
//
}
//
tryCount++;
//
}, 10);
//
return;
//
}
//
tryCount = 0;
const
spinContainerEl
=
spinEl
.
$el
.
querySelector
(
'
.ant-spin-container
'
)
as
HTMLElement
;
if
(
!
spinContainerEl
)
return
;
...
...
src/components/Modal/src/provideModal.ts
0 → 100644
View file @
9abf1763
import
{
provide
,
inject
}
from
'
vue
'
;
const
key
=
Symbol
(
'
basic-modal
'
);
export
function
provideModal
(
redoHeight
:
Fn
)
{
provide
(
key
,
redoHeight
);
}
export
function
injectModal
():
Fn
{
return
inject
(
key
)
as
Fn
;
}
src/components/Table/src/hooks/useTableScroll.ts
View file @
9abf1763
...
...
@@ -6,47 +6,44 @@ import { isBoolean } from '/@/utils/is';
import
{
useTimeout
}
from
'
/@/hooks/core/useTimeout
'
;
import
{
useWindowSizeFn
}
from
'
/@/hooks/event/useWindowSize
'
;
import
{
useProps
}
from
'
./useProps
'
;
import
{
injectModal
}
from
'
/@/components/Modal/src/provideModal
'
;
export
function
useTableScroll
(
refProps
:
ComputedRef
<
BasicTableProps
>
,
tableElRef
:
Ref
<
any
>
)
{
const
{
propsRef
}
=
useProps
(
refProps
);
const
tableHeightRef
:
Ref
<
number
|
null
>
=
ref
(
null
);
const
redoModalHeight
=
injectModal
();
watch
(
()
=>
unref
(
propsRef
).
canResize
,
()
=>
{
redoHeight
();
}
);
function
redoHeight
()
{
const
{
canResize
}
=
unref
(
propsRef
);
if
(
!
canResize
)
{
return
;
}
if
(
!
canResize
)
return
;
calcTableHeight
();
}
async
function
calcTableHeight
(
cb
?:
()
=>
void
)
{
const
{
canResize
,
resizeHeightOffset
,
pagination
,
maxHeight
}
=
unref
(
propsRef
);
if
(
!
canResize
)
{
return
;
}
if
(
!
canResize
)
return
;
await
nextTick
();
const
table
=
unref
(
tableElRef
)
as
any
;
if
(
!
table
)
return
;
if
(
!
table
)
{
return
;
}
const
tableEl
:
Element
=
table
.
$el
;
if
(
!
tableEl
)
{
return
;
}
if
(
!
tableEl
)
return
;
const
el
:
HTMLElement
|
null
=
tableEl
.
querySelector
(
'
.ant-table-thead
'
);
// const layoutMain: Element | null = document.querySelector('.default-layout__main ');
if
(
!
el
)
{
return
;
}
if
(
!
el
)
return
;
// 表格距离底部高度
const
{
bottomIncludeBody
}
=
getViewportOffset
(
el
);
// 表格高度+距离底部高度-自定义偏移量
...
...
@@ -89,6 +86,8 @@ export function useTableScroll(refProps: ComputedRef<BasicTableProps>, tableElRe
tableHeightRef
.
value
=
tableHeightRef
.
value
!
>
maxHeight
!
?
(
maxHeight
as
number
)
:
tableHeightRef
.
value
;
cb
&&
cb
();
// 解决表格放modal内的时候,modal自适应高度计算问题
redoModalHeight
&&
redoModalHeight
();
},
0
);
}
...
...
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