Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1e029dbc
authored
Sep 30, 2025
by
vent
Committed by
GitHub
Sep 30, 2025
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: 修复部分场景 echarts 在使用 v-show 时获取不到 width 的问题 (#6776)
1 parent
81bb7456
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletions
packages/effects/plugins/src/echarts/use-echarts.ts
packages/effects/plugins/src/echarts/use-echarts.ts
View file @
1e029db
...
...
@@ -32,6 +32,21 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
const
{
height
,
width
}
=
useWindowSize
();
const
resizeHandler
:
()
=>
void
=
useDebounceFn
(
resize
,
200
);
const
getChartEl
=
():
HTMLElement
|
null
=>
{
const
refValue
=
chartRef
?.
value
as
unknown
;
if
(
!
refValue
)
return
null
;
if
(
refValue
instanceof
HTMLElement
)
{
return
refValue
;
}
const
maybeComponent
=
refValue
as
{
$el
?:
HTMLElement
};
return
maybeComponent
.
$el
??
null
;
};
const
isElHidden
=
(
el
:
HTMLElement
|
null
):
boolean
=>
{
if
(
!
el
)
return
true
;
return
el
.
offsetHeight
===
0
||
el
.
offsetWidth
===
0
;
};
const
getOptions
=
computed
(():
EChartsOption
=>
{
if
(
!
isDark
.
value
)
{
return
{};
...
...
@@ -54,7 +69,7 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
const
renderEcharts
=
(
options
:
EChartsOption
,
clear
=
true
,
clear
=
true
):
Promise
<
Nullable
<
echarts
.
ECharts
>>
=>
{
cacheOptions
=
options
;
const
currentOptions
=
{
...
...
@@ -69,6 +84,13 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
return
;
}
nextTick
(()
=>
{
const
el
=
getChartEl
();
if
(
isElHidden
(
el
))
{
useTimeoutFn
(
async
()
=>
{
resolve
(
await
renderEcharts
(
currentOptions
));
},
30
);
return
;
}
useTimeoutFn
(()
=>
{
if
(
!
chartInstance
)
{
const
instance
=
initCharts
();
...
...
@@ -83,6 +105,10 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
};
function
resize
()
{
const
el
=
getChartEl
();
if
(
isElHidden
(
el
))
{
return
;
}
chartInstance
?.
resize
({
animation
:
{
duration
:
300
,
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment