Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yma16
可视化 csdn 数据
提交
1a6c548b
可
可视化 csdn 数据
项目概览
yma16
/
可视化 csdn 数据
该项目与 Fork 源项目分叉
Fork自
inscode / VueJS
通知
17
Star
15
Fork
10
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
可
可视化 csdn 数据
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1a6c548b
编写于
3月 09, 2024
作者:
Q
qq_38870145
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sat Mar 9 20:57:00 CST 2024 inscode
上级
c6f9c22c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
107 addition
and
13 deletion
+107
-13
src/components/visualPerformance/index.vue
src/components/visualPerformance/index.vue
+69
-7
src/utils/index.js
src/utils/index.js
+38
-6
未找到文件。
src/components/visualPerformance/index.vue
浏览文件 @
1a6c548b
<
script
lang=
"ts"
setup
>
<
script
lang=
"js"
setup
>
import
{
reactive
}
from
'
vue
'
;
import
{
reactive
,
onMounted
}
from
'
vue
'
;
const
state
:
any
=
reactive
({
import
*
as
echarts
from
'
echarts
'
;
title
:
'
性能指标可视化
'
const
state
=
reactive
({
title
:
'
性能指标可视化
'
,
echartInstance
:
null
,
domId
:
'
visual-performance-id
'
})
const
initChart
=
()
=>
{
// 基于准备好的dom,初始化echarts实例
const
domInstance
=
document
.
getElementById
(
state
.
domId
)
if
(
domInstance
)
{
domInstance
.
removeAttribute
(
'
_echarts_instance_
'
)
}
else
{
return
}
const
myChart
=
echarts
.
init
(
domInstance
);
const
option
=
{
title
:
{
text
:
'
World Population
'
},
tooltip
:
{
trigger
:
'
axis
'
,
axisPointer
:
{
type
:
'
shadow
'
}
},
legend
:
{},
grid
:
{
left
:
'
3%
'
,
right
:
'
4%
'
,
bottom
:
'
3%
'
,
containLabel
:
true
},
xAxis
:
{
type
:
'
value
'
,
boundaryGap
:
[
0
,
0.01
]
},
yAxis
:
{
type
:
'
category
'
,
data
:
[
'
fmp
'
,
'
fp
'
,
'
dns
'
,
'
res
'
,
'
dom
'
]
},
series
:
[
{
name
:
'
2011
'
,
type
:
'
bar
'
,
data
:
[
18203
,
23489
,
29034
,
104970
,
131744
]
}
]
};
console
.
log
(
'
option
'
,
option
)
// 使用刚指定的配置项和数据显示图表。
myChart
.
setOption
(
option
,
true
);
// 监听
state
.
echartInstance
=
myChart
;
myChart
.
on
(
'
click
'
,
function
(
params
)
{
console
.
log
(
'
params
'
,
params
)
});
window
.
onresize
=
myChart
.
resize
;
}
onMounted
(()
=>
{
initChart
()
})
})
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
<a-card
:title=
"state.title"
style=
"width:
3
00px"
>
<a-card
:title=
"state.title"
style=
"width:
9
00px"
>
<div>
<div
:id=
"state.domId"
style=
"width: 800px;height:600px;"
>
{{
state
.
title
}}
</div>
</div>
</a-card>
</a-card>
...
...
src/utils/index.js
浏览文件 @
1a6c548b
class
ListenDomChange
{
class
ListenDomChange
{
constructor
(
dom
,
callbackDomChange
)
{
// 监听 dom 节点
// 监听 dom 节点
dom
=
null
;
// observer
observer
=
null
;
// performance
performanceConfig
=
{};
constructor
(
dom
,
callbackDomChange
)
{
this
.
dom
=
dom
;
this
.
dom
=
dom
;
// 回调函数
this
.
callbackDomChange
=
callbackDomChange
;
this
.
callbackDomChange
=
callbackDomChange
;
// 初始化为{}
this
.
performanceConfig
=
{}
// 计算performanceConfig
this
.
calcPerformance
()
}
}
// 监听 dom变化
// 监听 dom变化
mutationListen
()
{
mutationListen
()
{
...
@@ -23,19 +32,28 @@ class ListenDomChange {
...
@@ -23,19 +32,28 @@ class ListenDomChange {
console
.
log
(
"
The
"
+
mutation
.
attributeName
+
"
attribute was modified.
"
);
console
.
log
(
"
The
"
+
mutation
.
attributeName
+
"
attribute was modified.
"
);
}
}
}
}
console
.
log
(
'
change
'
,
change
)
};
};
// 创建一个观察器实例并传入回调函数
// 创建一个观察器实例并传入回调函数
const
observer
=
new
MutationObserver
(
callback
);
this
.
observer
=
new
MutationObserver
(
callback
);
// 以上述配置开始观察目标节点
// 以上述配置开始观察目标节点
observer
.
observe
(
targetNode
,
config
);
this
.
observer
.
observer
.
observe
(
targetNode
,
config
);
// 之后,可停止观察
// 之后,可停止观察
observer
.
disconnect
();
this
.
observer
.
observer
.
disconnect
();
}
}
getPerformance
()
{
getPerformance
(){
return
performance
}
setPerformance
(
key
,
value
){
this
.
calcPerformance
[
key
]
=
value
}
calcPerformance
()
{
// Time to when activation occurred
// Time to when activation occurred
let
activationStart
=
let
activationStart
=
performance
.
getEntriesByType
(
"
navigation
"
)[
0
].
activationStart
;
performance
.
getEntriesByType
(
"
navigation
"
)[
0
].
activationStart
;
...
@@ -52,6 +70,20 @@ class ListenDomChange {
...
@@ -52,6 +70,20 @@ class ListenDomChange {
console
.
log
(
console
.
log
(
"
time to first-contentful-paint:
"
+
(
firstContentfulPaint
-
activationStart
),
"
time to first-contentful-paint:
"
+
(
firstContentfulPaint
-
activationStart
),
);
);
setPerformance
(
'
time to first paint
'
,
firstPaint
-
activationStart
)
setPerformance
(
'
time to first-contentful-paint
'
,
firstContentfulPaint
-
activationStart
)
const
entries
=
performance
.
getEntriesByType
(
"
navigation
"
);
entries
.
forEach
((
entry
)
=>
{
console
.
log
(
`
${
entry
.
name
}
: domComplete time:
${
entry
.
domComplete
}
ms`
);
const
domContentLoadedTime
=
entry
.
domContentLoadedEventEnd
-
entry
.
domContentLoadedEventStart
;
console
.
log
(
`
${
entry
.
name
}
: DOMContentLoaded processing time:
${
domContentLoadedTime
}
ms`
,
);
setPerformance
(
entry
.
name
,
domContentLoadedTime
)
});
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录