Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yma16
可视化 csdn 数据
提交
58651c29
可
可视化 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看板
提交
58651c29
编写于
3月 09, 2024
作者:
Q
qq_38870145
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sat Mar 9 21:46:00 CST 2024 inscode
上级
1a6c548b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
134 addition
and
35 deletion
+134
-35
src/App.vue
src/App.vue
+32
-14
src/components/visualPerformance/index.vue
src/components/visualPerformance/index.vue
+87
-10
src/utils/index.js
src/utils/index.js
+15
-11
未找到文件。
src/App.vue
浏览文件 @
58651c29
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
<
script
setup
>
<
script
setup
>
import
{
ref
}
from
"
vue
"
;
import
{
ref
,
onBeforeMount
}
from
"
vue
"
;
import
zhCN
from
"
ant-design-vue/es/locale/zh_CN
"
;
import
{
ListenDomChange
}
from
'
@/utils/index
'
import
dayjs
from
"
dayjs
"
;
import
zhCN
from
"
ant-design-vue/es/locale/zh_CN
"
;
import
"
dayjs/locale/zh-cn
"
;
import
dayjs
from
"
dayjs
"
;
/** 下载图片 */
import
"
dayjs/locale/zh-cn
"
;
/** 下载图片 */
const
downloadBase64
=
(
content
,
fileName
)
=>
{
const
downloadBase64
=
(
content
,
fileName
)
=>
{
const
base64ToBlob
=
function
(
code
)
{
const
base64ToBlob
=
function
(
code
)
{
let
parts
=
code
.
split
(
'
;base64,
'
);
let
parts
=
code
.
split
(
'
;base64,
'
);
...
@@ -45,8 +46,25 @@ const shotAction = () => {
...
@@ -45,8 +46,25 @@ const shotAction = () => {
});
});
}
}
dayjs
.
locale
(
"
zh-cn
"
);
dayjs
.
locale
(
"
zh-cn
"
);
const
locale
=
ref
(
zhCN
);
const
locale
=
ref
(
zhCN
);
const
findAppCount
=
ref
(
0
)
const
findAppDom
=
()
=>
{
const
appDom
=
document
.
getElementById
(
'
app
'
)
findAppCount
.
value
+=
1
if
(
appDom
)
{
const
listenDomChange
=
new
ListenDomChange
(
appDom
)
console
.
log
(
'
getPerformance
'
,
listenDomChange
.
getPerformance
())
}
else
if
(
findAppCount
<=
1000
)
{
findAppDom
()
}
}
onBeforeMount
(()
=>
{
findAppDom
();
})
</
script
>
</
script
>
...
@@ -54,16 +72,16 @@ const shotAction = () => {
...
@@ -54,16 +72,16 @@ const shotAction = () => {
<!-- 国际化配置-->
<!-- 国际化配置-->
<a-config-provider
:locale=
"locale"
>
<a-config-provider
:locale=
"locale"
>
<div
id=
"app"
>
<div
id=
"app"
>
<router-view/>
<router-view
/>
</div>
</div>
</a-config-provider>
</a-config-provider>
</
template
>
</
template
>
<
style
scoped
>
<
style
scoped
>
#app
{
#app
{
width
:
100vw
;
width
:
100vw
;
height
:
100vh
;
height
:
100vh
;
background-size
:
100%
;
background-size
:
100%
;
background
:
linear-gradient
(
rgba
(
38
,
38
,
38
,
0.5
),
rgba
(
40
,
140
,
234
,
0.6
)),
url("/static/img/previewFix.jpg")
no-repeat
center
;
background
:
linear-gradient
(
rgba
(
38
,
38
,
38
,
0.5
),
rgba
(
40
,
140
,
234
,
0.6
)),
url("/static/img/previewFix.jpg")
no-repeat
center
;
}
}
</
style
>
</
style
>
src/components/visualPerformance/index.vue
浏览文件 @
58651c29
...
@@ -2,15 +2,82 @@
...
@@ -2,15 +2,82 @@
import
{
reactive
,
onMounted
}
from
'
vue
'
;
import
{
reactive
,
onMounted
}
from
'
vue
'
;
import
*
as
echarts
from
'
echarts
'
;
import
*
as
echarts
from
'
echarts
'
;
const
state
=
reactive
({
const
state
=
reactive
({
title
:
'
性能指标可视化
'
,
leftTitle
:
'
原生的performance
'
,
leftDomId
:
'
visual-performance-id
'
,
rightTitle
:
'
性能指标可视化
'
,
rightDomId
:
'
visual-performance-id-right
'
,
chartTitle
:
'
性能指标
'
,
echartInstance
:
null
,
echartInstance
:
null
,
domId
:
'
visual-performance-id
'
})
})
const
initChart
=
()
=>
{
const
initLeftChart
=
()
=>
{
// 基于准备好的dom,初始化echarts实例
const
domInstance
=
document
.
getElementById
(
state
.
leftDomId
)
if
(
domInstance
)
{
domInstance
.
removeAttribute
(
'
_echarts_instance_
'
)
}
else
{
return
}
console
.
log
(
performance
)
console
.
log
(
Object
.
keys
(
performance
.
timing
))
const
label
=
[]
const
data
=
[]
for
(
let
key
in
performance
.
timing
)
{
label
.
push
(
key
)
data
.
push
(
performance
.
timing
[
key
])
}
const
myChart
=
echarts
.
init
(
domInstance
);
const
option
=
{
title
:
{
text
:
'
performance
'
},
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
:
label
},
series
:
[
{
name
:
'
performance
'
,
type
:
'
bar
'
,
data
:
data
}
]
};
console
.
log
(
'
option
'
,
option
)
// 使用刚指定的配置项和数据显示图表。
myChart
.
setOption
(
option
,
true
);
// 监听
state
.
echartInstance
=
myChart
;
myChart
.
on
(
'
click
'
,
function
(
params
)
{
console
.
log
(
'
params
'
,
params
)
});
window
.
onresize
=
myChart
.
resize
;
}
const
initRightChart
=
()
=>
{
// 基于准备好的dom,初始化echarts实例
// 基于准备好的dom,初始化echarts实例
const
domInstance
=
document
.
getElementById
(
state
.
d
omId
)
const
domInstance
=
document
.
getElementById
(
state
.
rightD
omId
)
if
(
domInstance
)
{
if
(
domInstance
)
{
domInstance
.
removeAttribute
(
'
_echarts_instance_
'
)
domInstance
.
removeAttribute
(
'
_echarts_instance_
'
)
}
}
...
@@ -20,7 +87,7 @@ const initChart = () => {
...
@@ -20,7 +87,7 @@ const initChart = () => {
const
myChart
=
echarts
.
init
(
domInstance
);
const
myChart
=
echarts
.
init
(
domInstance
);
const
option
=
{
const
option
=
{
title
:
{
title
:
{
text
:
'
World Population
'
text
:
state
.
chartTitle
},
},
tooltip
:
{
tooltip
:
{
trigger
:
'
axis
'
,
trigger
:
'
axis
'
,
...
@@ -62,18 +129,28 @@ const initChart = () => {
...
@@ -62,18 +129,28 @@ const initChart = () => {
window
.
onresize
=
myChart
.
resize
;
window
.
onresize
=
myChart
.
resize
;
}
}
onMounted
(()
=>
{
onMounted
(()
=>
{
initChart
()
initLeftChart
()
initRightChart
()
})
})
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
<a-card
:title=
"state.title"
style=
"width: 900px"
>
<div
style=
"display:flex;justify-content: space-between;"
>
<div
:id=
"state.domId"
style=
"width: 800px;height:600px;"
>
<a-card
:title=
"state.leftTitle"
style=
"width: 600px"
>
<div
:id=
"state.leftDomId"
style=
"width: 500px;height:600px;"
>
</div>
</a-card>
<a-card
:title=
"state.rightTitle"
style=
"width: 600px"
>
<div
:id=
"state.rightDOmId"
style=
"width: 500px;height:600px;"
>
</div>
</div>
</a-card>
</a-card>
</div>
</div>
</div>
</
template
>
</
template
>
\ No newline at end of file
src/utils/index.js
浏览文件 @
58651c29
...
@@ -10,9 +10,10 @@ class ListenDomChange {
...
@@ -10,9 +10,10 @@ class ListenDomChange {
this
.
dom
=
dom
;
this
.
dom
=
dom
;
this
.
callbackDomChange
=
callbackDomChange
;
this
.
callbackDomChange
=
callbackDomChange
;
// 初始化为{}
// 初始化为{}
this
.
performanceConfig
=
{}
this
.
performanceConfig
=
{}
// 计算performanceConfig
// 计算performanceConfig
this
.
calcPerformance
()
this
.
calcPerformance
()
this
.
mutationListen
()
}
}
// 监听 dom变化
// 监听 dom变化
mutationListen
()
{
mutationListen
()
{
...
@@ -24,6 +25,7 @@ class ListenDomChange {
...
@@ -24,6 +25,7 @@ class ListenDomChange {
// 当观察到变动时执行的回调函数
// 当观察到变动时执行的回调函数
const
callback
=
function
(
mutationsList
,
observer
)
{
const
callback
=
function
(
mutationsList
,
observer
)
{
console
.
log
(
'
change_______________
'
,
mutationsList
)
// Use traditional 'for loops' for IE 11
// Use traditional 'for loops' for IE 11
for
(
let
mutation
of
mutationsList
)
{
for
(
let
mutation
of
mutationsList
)
{
if
(
mutation
.
type
===
"
childList
"
)
{
if
(
mutation
.
type
===
"
childList
"
)
{
...
@@ -32,25 +34,25 @@ class ListenDomChange {
...
@@ -32,25 +34,25 @@ class ListenDomChange {
console
.
log
(
"
The
"
+
mutation
.
attributeName
+
"
attribute was modified.
"
);
console
.
log
(
"
The
"
+
mutation
.
attributeName
+
"
attribute was modified.
"
);
}
}
}
}
console
.
log
(
'
change
'
,
change
)
};
};
// 创建一个观察器实例并传入回调函数
// 创建一个观察器实例并传入回调函数
this
.
observer
=
new
MutationObserver
(
callback
);
this
.
observer
=
new
MutationObserver
(
callback
);
// 以上述配置开始观察目标节点
// 以上述配置开始观察目标节点
this
.
observer
.
observe
r
.
observe
(
targetNode
,
config
);
this
.
observer
.
observe
(
targetNode
,
config
);
// 之后,可停止观察
// 之后,可停止观察
this
.
observer
.
observer
.
disconnect
();
this
.
observer
.
disconnect
();
}
}
getPerformance
(){
getPerformance
()
{
return
performance
return
this
.
performanceConfig
}
}
setPerformance
(
key
,
value
)
{
setPerformance
(
key
,
value
)
{
this
.
calcPerformance
[
key
]
=
value
this
.
performanceConfig
[
key
]
=
value
}
}
calcPerformance
()
{
calcPerformance
()
{
...
@@ -70,19 +72,21 @@ class ListenDomChange {
...
@@ -70,19 +72,21 @@ 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
)
this
.
setPerformance
(
'
time to first paint
'
,
firstPaint
-
activationStart
)
setPerformance
(
'
time to first-contentful-paint
'
,
firstContentfulPaint
-
activationStart
)
this
.
setPerformance
(
'
time to first-contentful-paint
'
,
firstContentfulPaint
-
activationStart
)
const
entries
=
performance
.
getEntriesByType
(
"
navigation
"
);
const
entries
=
performance
.
getEntriesByType
(
"
navigation
"
);
const
that
=
this
entries
.
forEach
((
entry
)
=>
{
entries
.
forEach
((
entry
)
=>
{
console
.
log
(
`
${
entry
.
name
}
: domComplete time:
${
entry
.
domComplete
}
ms`
);
console
.
log
(
`
${
entry
.
name
}
: domComplete time:
${
entry
.
domComplete
}
ms`
);
that
.
setPerformance
(
'
domComplete time
'
,
entry
.
domComplete
)
const
domContentLoadedTime
=
const
domContentLoadedTime
=
entry
.
domContentLoadedEventEnd
-
entry
.
domContentLoadedEventStart
;
entry
.
domContentLoadedEventEnd
-
entry
.
domContentLoadedEventStart
;
console
.
log
(
console
.
log
(
`
${
entry
.
name
}
: DOMContentLoaded processing time:
${
domContentLoadedTime
}
ms`
,
`
${
entry
.
name
}
: DOMContentLoaded processing time:
${
domContentLoadedTime
}
ms`
,
);
);
setPerformance
(
entry
.
name
,
domContentLoadedTime
)
that
.
setPerformance
(
entry
.
name
,
domContentLoadedTime
)
});
});
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录