Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yma16
可视化 csdn 数据
提交
7b8b2093
可
可视化 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看板
提交
7b8b2093
编写于
3月 10, 2024
作者:
Q
qq_38870145
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
c9521c44
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
148 addition
and
38 deletion
+148
-38
src/App.vue
src/App.vue
+35
-7
src/components/visualPerformance/index.vue
src/components/visualPerformance/index.vue
+52
-9
src/main.js
src/main.js
+2
-0
src/store/index.js
src/store/index.js
+13
-0
src/store/modules/common.js
src/store/modules/common.js
+33
-0
src/utils/index.js
src/utils/index.js
+13
-22
未找到文件。
src/App.vue
浏览文件 @
7b8b2093
...
@@ -2,11 +2,25 @@
...
@@ -2,11 +2,25 @@
<
script
setup
>
<
script
setup
>
import
{
ref
,
onBeforeMount
}
from
"
vue
"
;
import
{
ref
,
onBeforeMount
,
reactive
}
from
"
vue
"
;
import
{
ListenDomChange
}
from
'
@/utils/index
'
import
{
ListenDomChange
}
from
'
@/utils/index
'
import
zhCN
from
"
ant-design-vue/es/locale/zh_CN
"
;
import
zhCN
from
"
ant-design-vue/es/locale/zh_CN
"
;
import
dayjs
from
"
dayjs
"
;
import
dayjs
from
"
dayjs
"
;
import
"
dayjs/locale/zh-cn
"
;
import
"
dayjs/locale/zh-cn
"
;
import
{
useStore
}
from
"
vuex
"
;
dayjs
.
locale
(
"
zh-cn
"
);
const
locale
=
ref
(
zhCN
);
const
findAppCount
=
ref
(
0
)
const
store
=
useStore
();
const
state
=
reactive
({
performanceConfig
:
{
}
})
/** 下载图片 */
/** 下载图片 */
const
downloadBase64
=
(
content
,
fileName
)
=>
{
const
downloadBase64
=
(
content
,
fileName
)
=>
{
const
base64ToBlob
=
function
(
code
)
{
const
base64ToBlob
=
function
(
code
)
{
...
@@ -46,24 +60,38 @@ const shotAction = () => {
...
@@ -46,24 +60,38 @@ const shotAction = () => {
});
});
}
}
dayjs
.
locale
(
"
zh-cn
"
);
const
locale
=
ref
(
zhCN
);
const
findAppCount
=
ref
(
0
)
const
findAppDom
=
()
=>
{
const
findAppDom
=
()
=>
{
const
appDom
=
document
.
getElementById
(
'
app
'
)
const
appDom
=
document
.
getElementById
(
'
app
'
)
findAppCount
.
value
+=
1
findAppCount
.
value
+=
1
if
(
appDom
)
{
if
(
appDom
)
{
console
.
log
(
'
appDom
'
,
appDom
)
console
.
log
(
'
appDom
'
,
appDom
)
const
listenDomChange
=
new
ListenDomChange
(
appDom
)
const
listenDomChange
=
new
ListenDomChange
()
console
.
log
(
'
getPerformance
'
,
listenDomChange
.
getPerformance
())
// state.performanceConfig = {
// ...state.performanceConfig,
// ...listenDomChange.getPerformance()
// }
console
.
log
(
'
appDom
'
,
appDom
)
listenDomChange
.
mutationAction
(
appDom
,
()
=>
{
console
.
log
(
'
第一次渲染
'
,
performance
.
now
())
state
.
performanceConfig
=
{
...
state
.
performanceConfig
,
fmp
:
performance
.
now
()
}
store
.
commit
(
"
common/setPerformanceConfig
"
,
{
...
state
.
performanceConfig
});
})
}
}
else
if
(
findAppCount
<=
1000
)
{
else
if
(
findAppCount
<=
1000
)
{
findAppDom
()
findAppDom
()
}
}
}
}
onBeforeMount
(()
=>
{
onBeforeMount
(()
=>
{
// 白屏时间
const
fp
=
performance
.
now
()
state
.
performanceConfig
=
{
...
state
.
performanceConfig
,
fp
:
fp
}
findAppDom
();
findAppDom
();
})
})
</
script
>
</
script
>
...
...
src/components/visualPerformance/index.vue
浏览文件 @
7b8b2093
<
script
lang=
"js"
setup
>
<
script
lang=
"js"
setup
>
import
{
reactive
,
onMounted
}
from
'
vue
'
;
import
{
reactive
,
onMounted
}
from
'
vue
'
;
import
*
as
echarts
from
'
echarts
'
;
import
*
as
echarts
from
'
echarts
'
;
import
{
useStore
}
from
"
vuex
"
;
const
store
=
useStore
();
const
state
=
reactive
({
const
state
=
reactive
({
leftTitle
:
'
原生的performance
'
,
leftTitle
:
'
原生的performance
'
,
leftDomId
:
'
visual-performance-id
'
,
leftDomId
:
'
visual-performance-id
'
,
...
@@ -26,8 +30,8 @@ const initLeftChart = () => {
...
@@ -26,8 +30,8 @@ const initLeftChart = () => {
console
.
log
(
Object
.
keys
(
performance
.
timing
))
console
.
log
(
Object
.
keys
(
performance
.
timing
))
const
label
=
[]
const
label
=
[]
const
data
=
[]
const
data
=
[]
for
(
let
key
in
performance
.
timing
)
{
for
(
let
key
in
performance
.
timing
)
{
if
(
key
!=
'
toJSON
'
)
{
if
(
key
!=
'
toJSON
'
)
{
label
.
push
(
key
)
label
.
push
(
key
)
data
.
push
(
performance
.
timing
[
key
])
data
.
push
(
performance
.
timing
[
key
])
}
}
...
@@ -87,10 +91,22 @@ const initRightChart = () => {
...
@@ -87,10 +91,22 @@ const initRightChart = () => {
else
{
else
{
return
return
}
}
const
performanceConfig
=
store
.
getters
[
"
common/performanceConfig
"
]
console
.
log
(
'
performanceConfig________________
'
,
performanceConfig
)
const
label
=
[]
const
data
=
[]
Object
.
keys
(
performanceConfig
).
forEach
(
key
=>
{
data
.
push
(
performanceConfig
[
key
])
label
.
push
(
key
)
})
const
myChart
=
echarts
.
init
(
domInstance
);
const
myChart
=
echarts
.
init
(
domInstance
);
const
option
=
{
const
option
=
{
title
:
{
title
:
{
text
:
state
.
chartTitle
text
:
'
自定义计算fmp
'
},
},
tooltip
:
{
tooltip
:
{
trigger
:
'
axis
'
,
trigger
:
'
axis
'
,
...
@@ -111,13 +127,13 @@ const initRightChart = () => {
...
@@ -111,13 +127,13 @@ const initRightChart = () => {
},
},
yAxis
:
{
yAxis
:
{
type
:
'
category
'
,
type
:
'
category
'
,
data
:
[
'
fmp
'
,
'
fp
'
,
'
dns
'
,
'
res
'
,
'
dom
'
]
data
:
label
},
},
series
:
[
series
:
[
{
{
name
:
'
2011
'
,
name
:
'
fmp计算
'
,
type
:
'
bar
'
,
type
:
'
bar
'
,
data
:
[
18203
,
23489
,
29034
,
104970
,
131744
]
data
:
data
}
}
]
]
};
};
...
@@ -141,16 +157,43 @@ onMounted(() => {
...
@@ -141,16 +157,43 @@ onMounted(() => {
<
template
>
<
template
>
<div>
<div>
<div
style=
"display:flex;
justify-content: space-between;
"
>
<div
style=
"display:flex;"
>
<a-card
:title=
"state.leftTitle"
style=
"width: 600px"
>
<a-card
:title=
"state.leftTitle"
style=
"width: 600px"
>
<div
:id=
"state.leftDomId"
style=
"width: 500px;height:600px;"
>
<div
:id=
"state.leftDomId"
style=
"width: 500px;height:600px;"
>
</div>
</div>
</a-card>
<a-card
:title=
"state.rightTitle"
style=
"width: 600px;margin-left:20px"
>
<div
:id=
"state.rightDomId"
style=
"width: 500px;height:600px;"
>
</div>
<div>
</div>
</a-card>
</a-card>
<a-card
style=
"margin-left:20px"
title=
"定义"
>
<div>
<div>
fetchStart:浏览器发起资源请求时,有缓存时,则返回读取缓存的开始时间。
<br>
domainLookupStart:查询 DNS 的开始时间。
<br>
domainLookupEnd:查询 DNS 的结束时间。
<br>
connectStart:浏览器开始与服务器连接时的时间。
<br>
secureConnectionStart:如果页面使用 HTTPS,它的值是安全连接握手之前的时刻。
<br>
connectEnd:当浏览器端完成与服务器端建立连接的时刻。
<br>
responseStart:指客户端收到从服务器端(或缓存、本地资源)响应回的第一个字节的数据的时刻。
<br>
<a-card
:title=
"state.rightTitle"
style=
"width: 600px"
>
responseEnd:指客户端收到从服务器端(或缓存、本地资源)响应回的最后一个字节的数据的时刻。
<br>
<div
:id=
"state.rightDOmId"
style=
"width: 500px;height:600px;"
>
</div>
</div>
</div>
</a-card>
</a-card>
</div>
</div>
...
...
src/main.js
浏览文件 @
7b8b2093
...
@@ -4,8 +4,10 @@ import Antd from 'ant-design-vue';
...
@@ -4,8 +4,10 @@ import Antd from 'ant-design-vue';
import
'
ant-design-vue/dist/antd.css
'
;
import
'
ant-design-vue/dist/antd.css
'
;
import
'
./assets/main.css
'
import
'
./assets/main.css
'
import
Router
from
"
./router/index.js
"
;
import
Router
from
"
./router/index.js
"
;
import
store
from
"
./store/index.js
"
;
createApp
(
App
)
createApp
(
App
)
.
use
(
Antd
)
.
use
(
Antd
)
.
use
(
store
)
.
use
(
Router
)
.
use
(
Router
)
.
mount
(
'
#app
'
)
.
mount
(
'
#app
'
)
src/store/index.js
0 → 100644
浏览文件 @
7b8b2093
// @ts-ignore
import
{
createStore
,
createLogger
}
from
"
vuex
"
;
import
common
from
"
./modules/common
"
;
const
debug
=
process
.
env
.
NODE_ENV
!==
"
production
"
;
export
default
createStore
({
modules
:
{
common
,
},
strict
:
debug
,
plugins
:
debug
?
[
createLogger
()]
:
[],
});
src/store/modules/common.js
0 → 100644
浏览文件 @
7b8b2093
const
state
=
()
=>
({
performanceConfig
:
{
}
});
const
getters
=
{
performanceConfig
:
(
state
)
=>
{
return
state
.
performanceConfig
;
}
};
const
mutations
=
{
setPerformanceConfig
(
state
,
payload
)
{
console
.
log
(
'
payload
'
,
payload
)
state
.
performanceConfig
=
payload
;
}
}
const
actions
=
{
setPerformanceConfigAction
({
commit
,
state
},
payload
)
{
commit
(
"
setPerformanceConfig
"
,
payload
);
},
};
export
default
{
namespaced
:
true
,
state
,
getters
,
actions
,
mutations
,
};
\ No newline at end of file
src/utils/index.js
浏览文件 @
7b8b2093
class
ListenDomChange
{
class
ListenDomChange
{
// 监听 dom 节点
dom
=
null
;
// observer
// observer
observer
=
null
;
observer
=
null
// performance
// performance
performanceConfig
=
{}
;
performanceConfig
=
{}
constructor
(
dom
,
callbackDomChange
)
{
constructor
()
{
this
.
dom
=
dom
;
this
.
callbackDomChange
=
callbackDomChange
;
// 初始化为{}
// 初始化为{}
this
.
performanceConfig
=
{}
this
.
performanceConfig
=
{}
// 计算performanceConfig
// 计算performanceConfig
this
.
calcPerformance
()
this
.
calcPerformance
()
this
.
mutationListen
()
}
}
...
@@ -61,14 +56,15 @@ class ListenDomChange {
...
@@ -61,14 +56,15 @@ class ListenDomChange {
}
}
// 监听 dom变化
// 监听 dom变化
mutationListen
()
{
mutationAction
(
listenDom
,
callbackAction
)
{
console
.
log
(
'
listenDom
'
,
listenDom
)
// 观察器的配置(需要观察什么变动)
// 观察器的配置(需要观察什么变动)
const
config
=
{
attributes
:
true
,
childList
:
true
,
subtree
:
true
};
const
config
=
{
attributes
:
true
,
childList
:
true
,
subtree
:
true
};
// 当观察到变动时执行的回调函数
// 当观察到变动时执行的回调函数
const
callback
=
function
(
mutationsList
,
observer
)
{
const
callback
=
function
(
mutationsList
,
observer
)
{
console
.
log
(
'
this.dom
'
,
this
.
d
om
)
console
.
log
(
'
listenDom
'
,
listenD
om
)
const
renderHeight
=
this
.
d
om
.
offsetHeight
const
renderHeight
=
listenD
om
.
offsetHeight
console
.
log
(
'
renderHeight_____________
'
,
renderHeight
)
console
.
log
(
'
renderHeight_____________
'
,
renderHeight
)
console
.
log
(
'
change_______________
'
,
mutationsList
)
console
.
log
(
'
change_______________
'
,
mutationsList
)
...
@@ -82,24 +78,19 @@ class ListenDomChange {
...
@@ -82,24 +78,19 @@ class ListenDomChange {
// }
// }
if
(
parseInt
(
renderHeight
))
{
if
(
parseInt
(
renderHeight
))
{
this
.
setPerformance
(
'
fmp
'
,
performance
.
now
())
// 第一次监听dom 存在高度则判定已经渲染完root节点,不关注子节点
this
.
clearObserver
()
callbackAction
()
// 停止观察
observer
.
disconnect
();
}
}
};
};
// 创建一个观察器实例并传入回调函数
// 创建一个观察器实例并传入回调函数
this
.
observer
=
new
MutationObserver
(
callback
);
const
observer
=
new
MutationObserver
(
callback
);
// 以上述配置开始观察目标节点
// 以上述配置开始观察目标节点
this
.
observer
.
observe
(
this
.
d
om
,
config
);
observer
.
observe
(
listenD
om
,
config
);
}
}
// 可停止观察
clearObserver
()
{
this
.
observer
.
disconnect
();
}
}
}
export
{
export
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录