vite-uni-dev-tool 0.0.48 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/const.cjs +1 -0
- package/dist/const.d.ts +78 -161
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +1 -47
- package/dist/core-shared.d.ts +44 -0
- package/dist/core-shared.d.ts.map +1 -0
- package/dist/core-shared.js +1 -0
- package/dist/core.d.ts +2 -40
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +4 -159
- package/dist/i18n/index.cjs +1 -0
- package/dist/i18n/index.d.ts +9 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/instance.cjs +1 -0
- package/dist/i18n/instance.d.ts +15 -0
- package/dist/i18n/instance.d.ts.map +1 -0
- package/dist/i18n/instance.js +1 -0
- package/dist/i18n/locales/en.cjs +1 -0
- package/dist/i18n/locales/en.d.ts +470 -0
- package/dist/i18n/locales/en.d.ts.map +1 -0
- package/dist/i18n/locales/en.js +1 -0
- package/dist/i18n/locales/zh-Hans.cjs +1 -0
- package/dist/i18n/locales/zh-Hans.d.ts +476 -0
- package/dist/i18n/locales/zh-Hans.d.ts.map +1 -0
- package/dist/i18n/locales/zh-Hans.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/devConsole/index.cjs +4 -0
- package/dist/{devConsole → modules/devConsole}/index.d.ts +1 -1
- package/dist/modules/devConsole/index.d.ts.map +1 -0
- package/dist/modules/devConsole/index.js +4 -0
- package/dist/modules/devEvent/index.cjs +5 -0
- package/dist/modules/devEvent/index.d.ts +115 -0
- package/dist/modules/devEvent/index.d.ts.map +1 -0
- package/dist/modules/devEvent/index.js +5 -0
- package/dist/modules/devIntercept/index.cjs +13 -0
- package/dist/modules/devIntercept/index.d.ts +71 -0
- package/dist/modules/devIntercept/index.d.ts.map +1 -0
- package/dist/modules/devIntercept/index.js +13 -0
- package/dist/modules/devStore/index.cjs +1 -0
- package/dist/modules/devStore/index.d.ts +159 -0
- package/dist/modules/devStore/index.d.ts.map +1 -0
- package/dist/modules/devStore/index.js +1 -0
- package/dist/modules/devToolInfo/index.cjs +1 -0
- package/dist/modules/devToolInfo/index.d.ts +27 -0
- package/dist/modules/devToolInfo/index.d.ts.map +1 -0
- package/dist/modules/devToolInfo/index.js +1 -0
- package/dist/plugins/uniDevTool/transform/transformApp.cjs +44 -0
- package/dist/plugins/uniDevTool/transform/transformApp.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformApp.js +17 -17
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -0
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +41 -0
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +1 -2
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformVue.js +32 -19
- package/dist/plugins/uniDevTool/uniDevTool.cjs +5 -0
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -11
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.cjs +19 -0
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.d.ts.map +1 -1
- package/dist/plugins/uniGlobalComponents/uniGlobalComponents.js +11 -19
- package/dist/plugins/uniParseStock/index.d.ts +10 -0
- package/dist/plugins/uniParseStock/index.d.ts.map +1 -0
- package/dist/plugins/utils/index.cjs +2 -0
- package/dist/plugins/utils/index.d.ts +1 -3
- package/dist/plugins/utils/index.d.ts.map +1 -1
- package/dist/plugins/utils/index.js +2 -2
- package/dist/shims-uni.d.ts +140 -0
- package/dist/type.d.ts +174 -16
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/array.cjs +1 -0
- package/dist/utils/array.d.ts.map +1 -1
- package/dist/utils/array.js +1 -12
- package/dist/utils/date.cjs +1 -0
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/date.js +1 -59
- package/dist/utils/file.cjs +1 -0
- package/dist/utils/file.d.ts.map +1 -1
- package/dist/utils/file.js +1 -85
- package/dist/utils/function.cjs +1 -0
- package/dist/utils/function.d.ts +13 -0
- package/dist/utils/function.d.ts.map +1 -1
- package/dist/utils/function.js +1 -68
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -63
- package/dist/utils/ip.cjs +1 -0
- package/dist/utils/ip.d.ts +1 -1
- package/dist/utils/ip.d.ts.map +1 -1
- package/dist/utils/ip.js +1 -45
- package/dist/utils/language.cjs +1 -0
- package/dist/utils/language.d.ts +2 -1
- package/dist/utils/language.d.ts.map +1 -1
- package/dist/utils/language.js +1 -63
- package/dist/utils/object.cjs +1 -0
- package/dist/utils/object.d.ts +4 -5
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/object.js +1 -136
- package/dist/utils/openLink.cjs +1 -0
- package/dist/utils/openLink.d.ts.map +1 -1
- package/dist/utils/openLink.js +1 -28
- package/dist/utils/page.cjs +1 -0
- package/dist/utils/page.d.ts.map +1 -1
- package/dist/utils/page.js +1 -7
- package/dist/utils/platform.cjs +1 -0
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/platform.js +1 -17
- package/dist/utils/string.cjs +1 -0
- package/dist/utils/string.d.ts.map +1 -1
- package/dist/utils/string.js +1 -114
- package/dist/utils/utils.cjs +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +1 -126
- package/dist/v3/AppTransition/index.vue +170 -0
- package/dist/v3/AutoSizer/index.vue +4 -5
- package/dist/v3/AutoSizer/index1.vue +4 -6
- package/dist/v3/AutoSizer/utils.ts +1 -1
- package/dist/v3/CaptureScreen/index.vue +19 -8
- package/dist/v3/CircularButton/index.vue +64 -13
- package/dist/v3/ConsoleList/ConsoleItem.vue +56 -5
- package/dist/v3/ConsoleList/RunJSInput.vue +10 -6
- package/dist/v3/ConsoleList/index.vue +51 -35
- package/dist/v3/CustomSwiper/CustomSwiperItem.vue +49 -0
- package/dist/v3/CustomSwiper/index.vue +104 -0
- package/dist/v3/DevTool/fps-collector.render.ts +148 -0
- package/dist/v3/DevTool/index.vue +209 -102
- package/dist/v3/DevToolButton/index.vue +40 -59
- package/dist/v3/DevToolTitle/index.vue +4 -1
- package/dist/v3/DevToolWindow/DevToolOverlay.vue +182 -0
- package/dist/v3/DevToolWindow/const.ts +47 -69
- package/dist/v3/DevToolWindow/hooks/dataUtils.ts +48 -0
- package/dist/v3/DevToolWindow/hooks/useDevToolData.ts +338 -0
- package/dist/v3/DevToolWindow/hooks/useDevToolHandlers.ts +549 -0
- package/dist/v3/DevToolWindow/hooks/useDevToolOverlay.ts +184 -0
- package/dist/v3/DevToolWindow/index.css +89 -0
- package/dist/v3/DevToolWindow/index.vue +800 -1450
- package/dist/v3/DraggableContainer/index.vue +456 -0
- package/dist/v3/ElEvent/ElEventItem.vue +4 -3
- package/dist/v3/ElEvent/index.vue +26 -9
- package/dist/v3/Empty/index.vue +1 -0
- package/dist/v3/FilterInput/index.vue +8 -22
- package/dist/v3/FilterSelect/index.vue +37 -24
- package/dist/v3/Instance/components/InstanceTreeNode.vue +265 -0
- package/dist/v3/Instance/flatten.ts +226 -0
- package/dist/v3/Instance/index.vue +94 -0
- package/dist/v3/Instance/registry.ts +49 -0
- package/dist/v3/Instance/transformTree.ts +375 -0
- package/dist/v3/Instance/transformTreeCtx.ts +268 -0
- package/dist/v3/{InstanceTree → Instance}/typing.d.ts +15 -2
- package/dist/v3/InstanceDetail/index.vue +433 -44
- package/dist/v3/JsonDetail/index.vue +12 -8
- package/dist/v3/JsonPretty/components/Brackets/index.vue +1 -0
- package/dist/v3/JsonPretty/components/Carets/index.vue +2 -1
- package/dist/v3/JsonPretty/components/CheckController/index.vue +26 -15
- package/dist/v3/JsonPretty/components/TreeNode/index.vue +42 -20
- package/dist/v3/JsonPretty/index.vue +60 -37
- package/dist/v3/JsonPretty/utils/index.ts +41 -44
- package/dist/v3/MovableContainer/index.vue +89 -0
- package/dist/v3/NFCList/NFCItem.vue +14 -14
- package/dist/v3/NFCList/NFCTool.vue +99 -81
- package/dist/v3/NFCList/index.vue +14 -10
- package/dist/v3/NetworkList/InterceptConfig.vue +154 -364
- package/dist/v3/NetworkList/InterceptItem.vue +14 -6
- package/dist/v3/NetworkList/NetworkDetail.vue +34 -29
- package/dist/v3/NetworkList/NetworkIntercept.vue +11 -8
- package/dist/v3/NetworkList/NetworkItem.vue +27 -11
- package/dist/v3/NetworkList/NetworkSend.vue +132 -290
- package/dist/v3/NetworkList/hooks/useNetworkForm.ts +86 -0
- package/dist/v3/NetworkList/index.vue +32 -24
- package/dist/v3/NetworkList/utils.ts +101 -0
- package/dist/v3/Performance/index.vue +495 -0
- package/dist/v3/Performance/modules/PerformanceMetrics.vue +153 -0
- package/dist/v3/Performance/modules/PerformanceWidget.vue +249 -0
- package/dist/v3/Performance/modules/usePerformanceChart.ts +460 -0
- package/dist/v3/Performance/modules/usePerformanceData.ts +258 -0
- package/dist/v3/Pick/index.vue +322 -0
- package/dist/v3/PiniaList/index.vue +38 -17
- package/dist/v3/RouteList/index.vue +32 -15
- package/dist/v3/RunJS/index.vue +30 -10
- package/dist/v3/ScanCodeList/ScanCodeItem.vue +2 -9
- package/dist/v3/ScanCodeList/index.vue +12 -9
- package/dist/v3/SettingButton/index.vue +45 -0
- package/dist/v3/SettingList/index.css +120 -0
- package/dist/v3/SettingList/index.vue +96 -537
- package/dist/v3/SettingList/modules/SettingDevTool.vue +208 -0
- package/dist/v3/SettingList/modules/SettingInfo.vue +119 -0
- package/dist/v3/SettingList/modules/SettingLanguage.vue +74 -0
- package/dist/v3/SettingList/modules/SettingLog.vue +230 -0
- package/dist/v3/SettingList/modules/SettingNetwork.vue +120 -0
- package/dist/v3/SettingList/modules/SettingTheme.vue +312 -0
- package/dist/v3/SourceCode/Line.vue +15 -2
- package/dist/v3/SourceCode/index.vue +25 -24
- package/dist/v3/SourceCode/parseCode.ts +114 -56
- package/dist/v3/StorageList/index.vue +33 -33
- package/dist/v3/Tabs/index.vue +31 -28
- package/dist/v3/Tag/index.vue +39 -20
- package/dist/v3/TransferList/TransferDetail.vue +268 -0
- package/dist/v3/TransferList/TransferItem.vue +125 -0
- package/dist/v3/TransferList/index.vue +181 -0
- package/dist/v3/UniEvent/UniEventItem.vue +1 -0
- package/dist/v3/UniEvent/index.vue +28 -29
- package/dist/v3/{VirtualListPro → VirtualList}/AutoSize.vue +1 -1
- package/dist/v3/VirtualList/index.vue +382 -82
- package/dist/v3/VuexList/index.vue +38 -17
- package/dist/v3/WebSocket/WebSocketDetail.vue +142 -80
- package/dist/v3/WebSocket/WebSocketItem.vue +10 -4
- package/dist/v3/WebSocket/index.vue +44 -30
- package/dist/v3/hooks/useNFC/index.ts +6 -6
- package/dist/v3/hooks/useNFC/typing.d.ts +2 -2
- package/dist/v3/hooks/useNFC/useNFCAndroid.ts +215 -626
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.ts +54 -85
- package/dist/v3/hooks/useNFC/utils.ts +3 -3
- package/dist/v3/hooks/useRequest/index.ts +2 -2
- package/dist/v3/hooks/useScanCode/index.ts +10 -8
- package/dist/v3/styles/theme.css +290 -0
- package/dist/v3/styles/theme.ts +12 -0
- package/package.json +25 -5
- package/dist/devConsole/index.d.ts.map +0 -1
- package/dist/devConsole/index.js +0 -273
- package/dist/devEvent/index.d.ts +0 -328
- package/dist/devEvent/index.d.ts.map +0 -1
- package/dist/devEvent/index.js +0 -697
- package/dist/devEventBus/index.d.ts +0 -42
- package/dist/devEventBus/index.d.ts.map +0 -1
- package/dist/devEventBus/index.js +0 -70
- package/dist/devIntercept/index.d.ts +0 -281
- package/dist/devIntercept/index.d.ts.map +0 -1
- package/dist/devIntercept/index.js +0 -949
- package/dist/devRunJS/index.d.ts +0 -67
- package/dist/devRunJS/index.d.ts.map +0 -1
- package/dist/devStore/index.d.ts +0 -199
- package/dist/devStore/index.d.ts.map +0 -1
- package/dist/devStore/index.js +0 -562
- package/dist/devToolInfo/index.d.ts +0 -17
- package/dist/devToolInfo/index.d.ts.map +0 -1
- package/dist/devToolInfo/index.js +0 -15
- package/dist/v3/AutoSizer/utils.d.ts +0 -5
- package/dist/v3/AutoSizer/utils.d.ts.map +0 -1
- package/dist/v3/ConsoleList/staticTips.d.ts +0 -13
- package/dist/v3/ConsoleList/staticTips.d.ts.map +0 -1
- package/dist/v3/DevToolWindow/const.d.ts +0 -46
- package/dist/v3/DevToolWindow/const.d.ts.map +0 -1
- package/dist/v3/InstanceTree/components/InstanceTreeNode.vue +0 -81
- package/dist/v3/InstanceTree/flatten.d.ts +0 -10
- package/dist/v3/InstanceTree/flatten.d.ts.map +0 -1
- package/dist/v3/InstanceTree/flatten.ts +0 -75
- package/dist/v3/InstanceTree/index.vue +0 -51
- package/dist/v3/InstanceTree/transformTree.d.ts +0 -17
- package/dist/v3/InstanceTree/transformTree.d.ts.map +0 -1
- package/dist/v3/InstanceTree/transformTree.ts +0 -237
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts +0 -4
- package/dist/v3/JsonPretty/hooks/useClipboard.d.ts.map +0 -1
- package/dist/v3/JsonPretty/hooks/useError.d.ts +0 -8
- package/dist/v3/JsonPretty/hooks/useError.d.ts.map +0 -1
- package/dist/v3/JsonPretty/type.d.ts +0 -94
- package/dist/v3/JsonPretty/type.d.ts.map +0 -1
- package/dist/v3/JsonPretty/utils/index.d.ts +0 -10
- package/dist/v3/JsonPretty/utils/index.d.ts.map +0 -1
- package/dist/v3/NFCList/const.d.ts +0 -13
- package/dist/v3/NFCList/const.d.ts.map +0 -1
- package/dist/v3/NetworkList/const.d.ts +0 -5
- package/dist/v3/NetworkList/const.d.ts.map +0 -1
- package/dist/v3/SourceCode/parseCode.d.ts +0 -27
- package/dist/v3/SourceCode/parseCode.d.ts.map +0 -1
- package/dist/v3/UploadList/UploadDetail.vue +0 -255
- package/dist/v3/UploadList/UploadItem.vue +0 -122
- package/dist/v3/UploadList/index.vue +0 -125
- package/dist/v3/VirtualListPro/index.vue +0 -229
- package/dist/v3/hooks/useContainerStyle.d.ts +0 -15
- package/dist/v3/hooks/useContainerStyle.d.ts.map +0 -1
- package/dist/v3/hooks/useNFC/index.d.ts +0 -5
- package/dist/v3/hooks/useNFC/index.d.ts.map +0 -1
- package/dist/v3/hooks/useNFC/useNFCAndroid.d.ts +0 -2
- package/dist/v3/hooks/useNFC/useNFCAndroid.d.ts.map +0 -1
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.d.ts +0 -2
- package/dist/v3/hooks/useNFC/useNFCMpWeiXin.d.ts.map +0 -1
- package/dist/v3/hooks/useNFC/utils.d.ts +0 -95
- package/dist/v3/hooks/useNFC/utils.d.ts.map +0 -1
- package/dist/v3/hooks/useRequest/index.d.ts +0 -126
- package/dist/v3/hooks/useRequest/index.d.ts.map +0 -1
- package/dist/v3/hooks/useRequest/utils.d.ts +0 -35
- package/dist/v3/hooks/useRequest/utils.d.ts.map +0 -1
- package/dist/v3/hooks/useScanCode/index.d.ts +0 -36
- package/dist/v3/hooks/useScanCode/index.d.ts.map +0 -1
- /package/dist/v3/{VirtualListPro → VirtualList}/readme.md +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<DraggableContainer
|
|
3
|
+
:width="width"
|
|
4
|
+
:height="height"
|
|
5
|
+
:x="x"
|
|
6
|
+
:y="y"
|
|
7
|
+
:zIndex="zIndex"
|
|
8
|
+
:resizable="true"
|
|
9
|
+
:customStyle="customStyle"
|
|
10
|
+
@update:x="(val) => (x = val)"
|
|
11
|
+
@update:y="(val) => (y = val)"
|
|
12
|
+
@update:width="(val) => (width = val)"
|
|
13
|
+
@update:height="(val) => (height = val)"
|
|
14
|
+
@change="onDebounceChange">
|
|
15
|
+
<view class="performance-monitor performance-widget">
|
|
16
|
+
<CircularButton
|
|
17
|
+
text="×"
|
|
18
|
+
class="close-btn"
|
|
19
|
+
@click.stop="onClose"
|
|
20
|
+
@touchstart.stop
|
|
21
|
+
@mousedown.stop />
|
|
22
|
+
<!-- 图表容器 -->
|
|
23
|
+
<canvas
|
|
24
|
+
canvas-id="fpsChartWidget"
|
|
25
|
+
class="fps-chart-container"
|
|
26
|
+
:style="{ backgroundColor: chartBgColor }"
|
|
27
|
+
id="fpsChartWidget"></canvas>
|
|
28
|
+
<PerformanceMetrics
|
|
29
|
+
:is-tab="false"
|
|
30
|
+
:fps="fps"
|
|
31
|
+
:cpuLoad="cpuLoad"
|
|
32
|
+
:memory="memory"
|
|
33
|
+
:showFps="showFps"
|
|
34
|
+
:showCpu="showCpu"
|
|
35
|
+
:showMemory="showMemory" />
|
|
36
|
+
</view>
|
|
37
|
+
</DraggableContainer>
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup lang="ts">
|
|
41
|
+
import { computed, onMounted, onUnmounted, getCurrentInstance, ref } from 'vue';
|
|
42
|
+
import DraggableContainer from '../../DraggableContainer/index.vue';
|
|
43
|
+
import PerformanceMetrics from './PerformanceMetrics.vue';
|
|
44
|
+
import { usePerformanceData } from './usePerformanceData';
|
|
45
|
+
import { usePerformanceChart } from './usePerformanceChart';
|
|
46
|
+
import CircularButton from '../../CircularButton/index.vue';
|
|
47
|
+
import { MSG_TYPE, DEV_CORE_MESSAGE } from '../../../const';
|
|
48
|
+
import { getDevToolInfo, setDevToolInfo } from '../../../modules/devToolInfo';
|
|
49
|
+
import { debounce } from '../../../utils';
|
|
50
|
+
|
|
51
|
+
const props = withDefaults(
|
|
52
|
+
defineProps<{
|
|
53
|
+
width?: string;
|
|
54
|
+
height?: string;
|
|
55
|
+
zIndex?: number;
|
|
56
|
+
customStyle?: Record<string, any>;
|
|
57
|
+
theme?: string;
|
|
58
|
+
}>(),
|
|
59
|
+
{
|
|
60
|
+
width: '240px',
|
|
61
|
+
height: '180px',
|
|
62
|
+
zIndex: 1000,
|
|
63
|
+
theme: 'light',
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// 根据主题计算颜色
|
|
68
|
+
const isDark = computed(() => props.theme === 'dark');
|
|
69
|
+
const isEye = computed(() => props.theme === 'eye');
|
|
70
|
+
|
|
71
|
+
const chartBgColor = computed(() => {
|
|
72
|
+
if (isDark.value) return 'rgba(255, 255, 255, 0.08)';
|
|
73
|
+
if (isEye.value) return 'rgba(101, 123, 131, 0.05)'; // Muted blue-grey for eye mode
|
|
74
|
+
return 'rgba(0, 0, 0, 0.05)';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const instance = getCurrentInstance();
|
|
78
|
+
const stepSize = 5;
|
|
79
|
+
|
|
80
|
+
// Hooks
|
|
81
|
+
const performanceData = usePerformanceData();
|
|
82
|
+
const { fps, cpuLoad, memory, performanceMonitorEnabled } = performanceData;
|
|
83
|
+
|
|
84
|
+
const showFps = ref(true);
|
|
85
|
+
const showCpu = ref(true);
|
|
86
|
+
const showMemory = ref(true);
|
|
87
|
+
const x = ref(10);
|
|
88
|
+
const y = ref(200);
|
|
89
|
+
const width = ref(parseInt(props.width) || 240);
|
|
90
|
+
const height = ref(parseInt(props.height) || 180);
|
|
91
|
+
|
|
92
|
+
function loadSettings() {
|
|
93
|
+
const info = getDevToolInfo();
|
|
94
|
+
if (info && info.performanceSettings) {
|
|
95
|
+
showFps.value = info.performanceSettings.showFps ?? true;
|
|
96
|
+
showCpu.value = info.performanceSettings.showCpu ?? true;
|
|
97
|
+
showMemory.value = info.performanceSettings.showMemory ?? true;
|
|
98
|
+
performanceMonitorEnabled.value =
|
|
99
|
+
info.performanceSettings.enableMonitor ?? false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const performanceChart = usePerformanceChart({
|
|
104
|
+
theme: computed(() => props.theme),
|
|
105
|
+
isDark,
|
|
106
|
+
instance,
|
|
107
|
+
canvasIdFn: () => 'fpsChartWidget',
|
|
108
|
+
stepSize,
|
|
109
|
+
data: performanceData,
|
|
110
|
+
config: {
|
|
111
|
+
showFps,
|
|
112
|
+
showCpu,
|
|
113
|
+
showMemory,
|
|
114
|
+
},
|
|
115
|
+
props: { mode: 'widget' },
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const onDebounceChange = debounce(
|
|
119
|
+
(detail: { x: number; y: number; width: number; height: number }) => {
|
|
120
|
+
setDevToolInfo({
|
|
121
|
+
performancePosition: {
|
|
122
|
+
left: detail.x,
|
|
123
|
+
top: detail.y,
|
|
124
|
+
width: detail.width,
|
|
125
|
+
height: detail.height,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// 调整大小时重新初始化画布
|
|
130
|
+
performanceChart.initCanvas(() => {
|
|
131
|
+
performanceData.initData(
|
|
132
|
+
Math.ceil(performanceChart.canvasWidth.value / stepSize) + 4,
|
|
133
|
+
);
|
|
134
|
+
if (performanceMonitorEnabled.value) {
|
|
135
|
+
performanceChart.startRenderLoop();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
500,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const onClose = () => {
|
|
143
|
+
// 关闭悬浮窗时,同时关闭监测功能
|
|
144
|
+
performanceMonitorEnabled.value = false;
|
|
145
|
+
performanceData.stopHeartbeat();
|
|
146
|
+
performanceChart.stopRenderLoop();
|
|
147
|
+
|
|
148
|
+
// 更新本地存储
|
|
149
|
+
setDevToolInfo({
|
|
150
|
+
performanceVisible: false,
|
|
151
|
+
performanceSettings: {
|
|
152
|
+
showFps: showFps.value,
|
|
153
|
+
showCpu: showCpu.value,
|
|
154
|
+
showMemory: showMemory.value,
|
|
155
|
+
enableMonitor: false, // 关闭监测
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// 通知 DevTool 组件更新悬浮窗可见性
|
|
160
|
+
uni.$emit(DEV_CORE_MESSAGE, { type: MSG_TYPE.PERF_VISIBLE, data: false });
|
|
161
|
+
// 通知 Performance Tab 页面监测已关闭
|
|
162
|
+
uni.$emit(MSG_TYPE.PERF_MONITOR, false);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const onMonitorChange = (enabled: boolean) => {
|
|
166
|
+
performanceMonitorEnabled.value = enabled;
|
|
167
|
+
if (enabled) {
|
|
168
|
+
performanceData.initData(
|
|
169
|
+
Math.ceil(performanceChart.canvasWidth.value / stepSize) + 4,
|
|
170
|
+
);
|
|
171
|
+
performanceData.startHeartbeat();
|
|
172
|
+
performanceChart.startRenderLoop();
|
|
173
|
+
} else {
|
|
174
|
+
performanceData.stopHeartbeat();
|
|
175
|
+
performanceChart.stopRenderLoop();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
onMounted(() => {
|
|
180
|
+
const info = getDevToolInfo();
|
|
181
|
+
if (info && info.performancePosition) {
|
|
182
|
+
x.value = info.performancePosition.left;
|
|
183
|
+
y.value = info.performancePosition.top;
|
|
184
|
+
if (info.performancePosition.width)
|
|
185
|
+
width.value = info.performancePosition.width;
|
|
186
|
+
if (info.performancePosition.height)
|
|
187
|
+
height.value = info.performancePosition.height;
|
|
188
|
+
}
|
|
189
|
+
loadSettings();
|
|
190
|
+
|
|
191
|
+
performanceChart.initCanvas(() => {
|
|
192
|
+
performanceData.initData(
|
|
193
|
+
Math.ceil(performanceChart.canvasWidth.value / stepSize) + 4,
|
|
194
|
+
);
|
|
195
|
+
if (performanceMonitorEnabled.value) {
|
|
196
|
+
performanceChart.startRenderLoop();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (performanceMonitorEnabled.value) {
|
|
201
|
+
performanceData.startHeartbeat();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
uni.$on(MSG_TYPE.PERF_MONITOR, onMonitorChange);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
onUnmounted(() => {
|
|
208
|
+
performanceChart.resetCanvas();
|
|
209
|
+
uni.$off(MSG_TYPE.PERF_MONITOR, onMonitorChange);
|
|
210
|
+
});
|
|
211
|
+
</script>
|
|
212
|
+
|
|
213
|
+
<style scoped>
|
|
214
|
+
.performance-widget {
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
width: 100%;
|
|
218
|
+
height: 100%;
|
|
219
|
+
padding: 8px;
|
|
220
|
+
background-color: var(--dev-tool-bg2-color, rgb(255 255 255 / 90%));
|
|
221
|
+
backdrop-filter: blur(10px);
|
|
222
|
+
box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
|
|
223
|
+
border-radius: 8px;
|
|
224
|
+
position: relative;
|
|
225
|
+
box-sizing: border-box;
|
|
226
|
+
overflow: hidden;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.fps-chart-container {
|
|
230
|
+
width: 100%;
|
|
231
|
+
flex: 1;
|
|
232
|
+
min-height: 40px;
|
|
233
|
+
margin-bottom: 4px;
|
|
234
|
+
border-radius: 4px;
|
|
235
|
+
overflow: hidden;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.close-btn {
|
|
239
|
+
position: absolute;
|
|
240
|
+
top: 4px;
|
|
241
|
+
right: 4px;
|
|
242
|
+
z-index: 10;
|
|
243
|
+
width: 20px;
|
|
244
|
+
height: 20px;
|
|
245
|
+
font-size: 14px;
|
|
246
|
+
line-height: 1;
|
|
247
|
+
background-color: var(--dev-tool-bg-color, rgb(255 255 255 / 80%));
|
|
248
|
+
}
|
|
249
|
+
</style>
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { ref, computed, nextTick } from 'vue';
|
|
2
|
+
import { raf, caf } from '../../../utils';
|
|
3
|
+
|
|
4
|
+
export function usePerformanceChart(opts: {
|
|
5
|
+
theme: any;
|
|
6
|
+
isDark: any;
|
|
7
|
+
instance: any;
|
|
8
|
+
canvasIdFn: () => string;
|
|
9
|
+
stepSize: number;
|
|
10
|
+
data: any; // from usePerformanceData
|
|
11
|
+
config: {
|
|
12
|
+
showFps: any;
|
|
13
|
+
showCpu: any;
|
|
14
|
+
showMemory: any;
|
|
15
|
+
};
|
|
16
|
+
props: any;
|
|
17
|
+
}) {
|
|
18
|
+
const canvasWidth = ref(0);
|
|
19
|
+
const canvasHeight = ref(0);
|
|
20
|
+
let canvasCtx: UniApp.CanvasContext | null = null;
|
|
21
|
+
let renderTimer: number | null = null;
|
|
22
|
+
// 使用标志变量控制渲染循环,确保在 Android 平台能正确停止
|
|
23
|
+
let isRunning = false;
|
|
24
|
+
|
|
25
|
+
// Colors
|
|
26
|
+
const textColor = computed(() => {
|
|
27
|
+
if (opts.theme.value === 'eye') return '#586e75';
|
|
28
|
+
return opts.isDark.value ? '#ffffff' : '#000000';
|
|
29
|
+
});
|
|
30
|
+
const chartBgColor = computed(() => {
|
|
31
|
+
if (opts.theme.value === 'eye') return 'rgba(88, 110, 117, 0.05)';
|
|
32
|
+
return opts.isDark.value
|
|
33
|
+
? 'rgba(255, 255, 255, 0.08)'
|
|
34
|
+
: 'rgba(0, 0, 0, 0.05)';
|
|
35
|
+
});
|
|
36
|
+
const mainLineColor = computed(() => {
|
|
37
|
+
if (opts.theme.value === 'eye') return 'rgba(88, 110, 117, 0.3)';
|
|
38
|
+
return opts.isDark.value
|
|
39
|
+
? 'rgba(255, 255, 255, 0.4)'
|
|
40
|
+
: 'rgba(0, 0, 0, 0.2)';
|
|
41
|
+
});
|
|
42
|
+
const subLineColor = computed(() => {
|
|
43
|
+
if (opts.theme.value === 'eye') return 'rgba(88, 110, 117, 0.1)';
|
|
44
|
+
return opts.isDark.value
|
|
45
|
+
? 'rgba(255, 255, 255, 0.15)'
|
|
46
|
+
: 'rgba(0, 0, 0, 0.08)';
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function initCanvas(onReady?: () => void) {
|
|
50
|
+
const canvasId = opts.canvasIdFn();
|
|
51
|
+
canvasCtx = uni.createCanvasContext(canvasId, opts.instance?.proxy);
|
|
52
|
+
|
|
53
|
+
const queryCanvas = (retryCount = 0) => {
|
|
54
|
+
uni
|
|
55
|
+
.createSelectorQuery()
|
|
56
|
+
.in(opts.instance?.proxy)
|
|
57
|
+
.select(`#${canvasId}`)
|
|
58
|
+
.boundingClientRect((rect) => {
|
|
59
|
+
const r = rect as any;
|
|
60
|
+
if (r && r.width > 0 && r.height > 0) {
|
|
61
|
+
canvasWidth.value = r.width;
|
|
62
|
+
canvasHeight.value = r.height;
|
|
63
|
+
|
|
64
|
+
// Initialize data if needed (call initDate from usePerformanceData)
|
|
65
|
+
const points = Math.ceil(canvasWidth.value / opts.stepSize) + 4;
|
|
66
|
+
opts.data.initData(points);
|
|
67
|
+
|
|
68
|
+
if (onReady) onReady();
|
|
69
|
+
} else {
|
|
70
|
+
// Android 平台在二次打开时可能需要多一点时间才能获取到正确的宽高
|
|
71
|
+
// 增加重试机制:每 50ms 重试一次,最多重试 10 次 (500ms)
|
|
72
|
+
if (retryCount < 10) {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
queryCanvas(retryCount + 1);
|
|
75
|
+
}, 50);
|
|
76
|
+
} else {
|
|
77
|
+
console.warn(
|
|
78
|
+
`[UniDevTool] Failed to get canvas rect for ${canvasId}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
.exec();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
nextTick(() => {
|
|
87
|
+
// 首次尝试稍微延迟一点,避开极其短暂的中间状态
|
|
88
|
+
setTimeout(() => queryCanvas(), 50);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function startRenderLoop() {
|
|
93
|
+
// 避免重复启动
|
|
94
|
+
if (isRunning) return;
|
|
95
|
+
isRunning = true;
|
|
96
|
+
|
|
97
|
+
const render = () => {
|
|
98
|
+
// 检查标志位,如果已停止则不再继续
|
|
99
|
+
if (!isRunning) return;
|
|
100
|
+
drawChart();
|
|
101
|
+
renderTimer = raf(render);
|
|
102
|
+
};
|
|
103
|
+
render();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function stopRenderLoop() {
|
|
107
|
+
isRunning = false;
|
|
108
|
+
if (renderTimer) {
|
|
109
|
+
caf(renderTimer);
|
|
110
|
+
renderTimer = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resetCanvas() {
|
|
115
|
+
stopRenderLoop();
|
|
116
|
+
canvasCtx = null;
|
|
117
|
+
canvasWidth.value = 0;
|
|
118
|
+
canvasHeight.value = 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function drawChart() {
|
|
122
|
+
if (!canvasCtx || !canvasWidth.value || !canvasHeight.value) return;
|
|
123
|
+
|
|
124
|
+
const ctx = canvasCtx;
|
|
125
|
+
const w = canvasWidth.value;
|
|
126
|
+
const h = canvasHeight.value;
|
|
127
|
+
const bottomPadding = 12;
|
|
128
|
+
const drawH = h - bottomPadding;
|
|
129
|
+
|
|
130
|
+
// Data aliases
|
|
131
|
+
const {
|
|
132
|
+
fpsHistory: fList,
|
|
133
|
+
cpuHistory: cList,
|
|
134
|
+
memoryHistory: mList,
|
|
135
|
+
timeHistory: tList,
|
|
136
|
+
displayMaxScale: currentScale,
|
|
137
|
+
} = opts.data;
|
|
138
|
+
|
|
139
|
+
// Props aliases
|
|
140
|
+
const config = opts.config;
|
|
141
|
+
const props = opts.props;
|
|
142
|
+
|
|
143
|
+
// 计算平滑偏移量
|
|
144
|
+
const now = Date.now();
|
|
145
|
+
|
|
146
|
+
// 强制使用当前时间作为最右侧锚点
|
|
147
|
+
// 这样数据永远不会往右移动,只会随着时间推移自然向左滚动
|
|
148
|
+
const rightEdgeTime = now;
|
|
149
|
+
|
|
150
|
+
const getX = (ts: number) => {
|
|
151
|
+
if (!ts) return -100; // 兜底处理无效数据
|
|
152
|
+
return w - ((rightEdgeTime - ts) / 1000) * opts.stepSize;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const activeMetrics = [
|
|
156
|
+
{ key: 'cpu', show: config.showCpu.value },
|
|
157
|
+
{ key: 'memory', show: config.showMemory.value },
|
|
158
|
+
{ key: 'fps', show: config.showFps.value },
|
|
159
|
+
].filter((m) => m.show);
|
|
160
|
+
|
|
161
|
+
const count = activeMetrics.length;
|
|
162
|
+
const isSplit = count > 1;
|
|
163
|
+
const chartHeight = count > 0 ? drawH / count : drawH;
|
|
164
|
+
|
|
165
|
+
let cpuY = 0;
|
|
166
|
+
let memY = 0;
|
|
167
|
+
let fpsY = 0;
|
|
168
|
+
|
|
169
|
+
activeMetrics.forEach((m, i) => {
|
|
170
|
+
if (m.key === 'cpu') cpuY = i * chartHeight;
|
|
171
|
+
if (m.key === 'memory') memY = i * chartHeight;
|
|
172
|
+
if (m.key === 'fps') fpsY = i * chartHeight;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// 1. 绘制背景网格
|
|
176
|
+
const maxFps = Math.max(...fList.value, 0);
|
|
177
|
+
let targetScale = 60;
|
|
178
|
+
if (maxFps > 144) targetScale = 240;
|
|
179
|
+
else if (maxFps > 120) targetScale = 144;
|
|
180
|
+
else if (maxFps > 90) targetScale = 120;
|
|
181
|
+
|
|
182
|
+
const getStandardPoints = (scale: number) => {
|
|
183
|
+
return [0, 30, 60, 100, 144, 240].filter(
|
|
184
|
+
(p) => p <= Math.max(scale, currentScale.value),
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
ctx.setLineWidth(1);
|
|
189
|
+
ctx.setFontSize(props.mode === 'widget' ? 10 : 12);
|
|
190
|
+
|
|
191
|
+
// --- FPS ---
|
|
192
|
+
if (config.showFps.value) {
|
|
193
|
+
const fpsPoints = getStandardPoints(targetScale);
|
|
194
|
+
fpsPoints.forEach((p) => {
|
|
195
|
+
const yPos =
|
|
196
|
+
fpsY + (chartHeight - (p / currentScale.value) * chartHeight);
|
|
197
|
+
if (yPos < fpsY - 5 || yPos > fpsY + chartHeight + 5) return;
|
|
198
|
+
|
|
199
|
+
ctx.beginPath();
|
|
200
|
+
ctx.setStrokeStyle(
|
|
201
|
+
p === 0 || p === 60 || p === targetScale
|
|
202
|
+
? mainLineColor.value
|
|
203
|
+
: subLineColor.value,
|
|
204
|
+
);
|
|
205
|
+
ctx.setLineDash(
|
|
206
|
+
p === 0 || p === 60 || p === targetScale ? [] : [2, 4],
|
|
207
|
+
0,
|
|
208
|
+
);
|
|
209
|
+
ctx.moveTo(0, yPos);
|
|
210
|
+
ctx.lineTo(w, yPos);
|
|
211
|
+
ctx.stroke();
|
|
212
|
+
|
|
213
|
+
ctx.setFillStyle(textColor.value);
|
|
214
|
+
if (p !== 0 && (p === 60 || p === targetScale)) {
|
|
215
|
+
ctx.setTextBaseline(p === targetScale ? 'top' : 'bottom');
|
|
216
|
+
ctx.fillText(`${p}${isSplit ? ' FPS' : ''}`, 0, yPos);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// --- CPU ---
|
|
222
|
+
if (config.showCpu.value) {
|
|
223
|
+
const cpuPoints = [0, 50, 100];
|
|
224
|
+
cpuPoints.forEach((p) => {
|
|
225
|
+
const yPos = cpuY + (chartHeight - (p / 100) * chartHeight);
|
|
226
|
+
if (yPos < cpuY - 5 || yPos > cpuY + chartHeight + 5) return;
|
|
227
|
+
|
|
228
|
+
if (!isSplit || p !== 0) {
|
|
229
|
+
ctx.beginPath();
|
|
230
|
+
ctx.setStrokeStyle(
|
|
231
|
+
p === 0 || p === 100 ? mainLineColor.value : subLineColor.value,
|
|
232
|
+
);
|
|
233
|
+
ctx.setLineDash(p === 0 || p === 100 ? [] : [2, 4], 0);
|
|
234
|
+
ctx.moveTo(0, yPos);
|
|
235
|
+
ctx.lineTo(w, yPos);
|
|
236
|
+
ctx.stroke();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
ctx.setFillStyle(textColor.value);
|
|
240
|
+
if (p !== 0) {
|
|
241
|
+
ctx.setTextBaseline(p === 100 ? 'top' : 'middle');
|
|
242
|
+
ctx.fillText(`${p}${isSplit ? '%' : ''}`, 0, yPos);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// --- Memory ---
|
|
248
|
+
const maxMem = Math.max(...mList.value, 100);
|
|
249
|
+
let targetMemScale = Math.ceil(maxMem / 100) * 100;
|
|
250
|
+
if (targetMemScale === 0) targetMemScale = 100;
|
|
251
|
+
|
|
252
|
+
if (config.showMemory.value) {
|
|
253
|
+
const memPoints = [0, targetMemScale / 2, targetMemScale];
|
|
254
|
+
memPoints.forEach((p) => {
|
|
255
|
+
const yPos = memY + (chartHeight - (p / targetMemScale) * chartHeight);
|
|
256
|
+
if (yPos < memY - 5 || yPos > memY + chartHeight + 5) return;
|
|
257
|
+
|
|
258
|
+
if (!isSplit || p !== 0) {
|
|
259
|
+
ctx.beginPath();
|
|
260
|
+
ctx.setStrokeStyle(
|
|
261
|
+
p === 0 || p === targetMemScale
|
|
262
|
+
? mainLineColor.value
|
|
263
|
+
: subLineColor.value,
|
|
264
|
+
);
|
|
265
|
+
ctx.setLineDash(p === 0 || p === targetMemScale ? [] : [2, 4], 0);
|
|
266
|
+
ctx.moveTo(0, yPos);
|
|
267
|
+
ctx.lineTo(w, yPos);
|
|
268
|
+
ctx.stroke();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
ctx.setFillStyle(textColor.value);
|
|
272
|
+
if (p !== 0) {
|
|
273
|
+
ctx.setTextBaseline(p === targetMemScale ? 'top' : 'middle');
|
|
274
|
+
ctx.fillText(`${p.toFixed(0)}${isSplit ? 'M' : ''}`, 0, yPos);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Split Lines
|
|
280
|
+
if (isSplit) {
|
|
281
|
+
ctx.setStrokeStyle(mainLineColor.value);
|
|
282
|
+
ctx.setLineDash([], 0);
|
|
283
|
+
for (let i = 1; i < count; i++) {
|
|
284
|
+
const y = chartHeight * i;
|
|
285
|
+
ctx.beginPath();
|
|
286
|
+
ctx.moveTo(0, y);
|
|
287
|
+
ctx.lineTo(w, y);
|
|
288
|
+
ctx.stroke();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Vertical Grid & Time Layout
|
|
293
|
+
const timeList = tList.value;
|
|
294
|
+
|
|
295
|
+
// Vertical Grid - 基于时间绘制,不再基于数组索引,保证网格绝对均匀
|
|
296
|
+
ctx.setStrokeStyle(subLineColor.value);
|
|
297
|
+
ctx.setLineDash([2, 4], 0);
|
|
298
|
+
|
|
299
|
+
const startTimeOnScreen = rightEdgeTime - (w / opts.stepSize) * 1000;
|
|
300
|
+
const startGridSec = Math.ceil(startTimeOnScreen / 5000) * 5000;
|
|
301
|
+
|
|
302
|
+
for (let t = startGridSec; t <= rightEdgeTime; t += 5000) {
|
|
303
|
+
const xPos = getX(t);
|
|
304
|
+
if (xPos >= 0 && xPos <= w) {
|
|
305
|
+
ctx.beginPath();
|
|
306
|
+
ctx.moveTo(xPos, 0);
|
|
307
|
+
ctx.lineTo(xPos, drawH);
|
|
308
|
+
ctx.stroke();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Time Axis
|
|
313
|
+
if (timeList.length > 0) {
|
|
314
|
+
ctx.setLineDash([], 0);
|
|
315
|
+
ctx.setStrokeStyle(mainLineColor.value);
|
|
316
|
+
ctx.beginPath();
|
|
317
|
+
ctx.moveTo(0, drawH);
|
|
318
|
+
ctx.lineTo(w, drawH);
|
|
319
|
+
ctx.stroke();
|
|
320
|
+
|
|
321
|
+
ctx.setFillStyle(textColor.value);
|
|
322
|
+
ctx.setFontSize(10);
|
|
323
|
+
ctx.setTextAlign('center');
|
|
324
|
+
|
|
325
|
+
const formatTime = (ts: number) => {
|
|
326
|
+
const d = new Date(ts);
|
|
327
|
+
return `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}:${d.getSeconds().toString().padStart(2, '0')}`;
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const startTimeLabel = Math.ceil(startTimeOnScreen / 15000) * 15000;
|
|
331
|
+
for (let t = startTimeLabel; t <= rightEdgeTime; t += 15000) {
|
|
332
|
+
const xPos = getX(t);
|
|
333
|
+
if (xPos >= 0 && xPos <= w) {
|
|
334
|
+
const timeStr = formatTime(t);
|
|
335
|
+
ctx.setTextBaseline('bottom');
|
|
336
|
+
ctx.fillText(timeStr, xPos, h);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
ctx.setTextAlign('left');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const drawAreaChart = (
|
|
343
|
+
list: number[],
|
|
344
|
+
startY: number,
|
|
345
|
+
height: number,
|
|
346
|
+
maxVal: number,
|
|
347
|
+
color: string,
|
|
348
|
+
gradientStart: string,
|
|
349
|
+
gradientEnd: string,
|
|
350
|
+
) => {
|
|
351
|
+
const bottomY = startY + height;
|
|
352
|
+
if (list.length === 0) return;
|
|
353
|
+
|
|
354
|
+
const getValY = (val: number) =>
|
|
355
|
+
startY + (height - (val / maxVal) * height);
|
|
356
|
+
|
|
357
|
+
// 1. 准备渐变
|
|
358
|
+
const gradient = ctx.createLinearGradient(0, startY, 0, bottomY);
|
|
359
|
+
gradient.addColorStop(0, gradientStart);
|
|
360
|
+
gradient.addColorStop(1, gradientEnd);
|
|
361
|
+
ctx.setFillStyle(gradient);
|
|
362
|
+
|
|
363
|
+
// 2. 绘制填充面积
|
|
364
|
+
ctx.beginPath();
|
|
365
|
+
ctx.setLineDash([], 0);
|
|
366
|
+
|
|
367
|
+
const x0 = getX(timeList[0]);
|
|
368
|
+
const y0 = getValY(list[0]);
|
|
369
|
+
ctx.moveTo(x0, bottomY);
|
|
370
|
+
ctx.lineTo(x0, y0);
|
|
371
|
+
|
|
372
|
+
let lastY = y0;
|
|
373
|
+
for (let i = 1; i < list.length; i++) {
|
|
374
|
+
const x = getX(timeList[i]);
|
|
375
|
+
lastY = getValY(list[i]);
|
|
376
|
+
ctx.lineTo(x, lastY);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// 延伸到右侧边缘
|
|
380
|
+
ctx.lineTo(w, lastY);
|
|
381
|
+
ctx.lineTo(w, bottomY);
|
|
382
|
+
ctx.closePath();
|
|
383
|
+
ctx.fill();
|
|
384
|
+
|
|
385
|
+
// 3. 绘制顶部线条
|
|
386
|
+
ctx.beginPath();
|
|
387
|
+
ctx.setLineWidth(2);
|
|
388
|
+
ctx.setStrokeStyle(color);
|
|
389
|
+
ctx.moveTo(x0, y0);
|
|
390
|
+
for (let i = 1; i < list.length; i++) {
|
|
391
|
+
const x = getX(timeList[i]);
|
|
392
|
+
ctx.lineTo(x, getValY(list[i]));
|
|
393
|
+
}
|
|
394
|
+
ctx.lineTo(w, lastY);
|
|
395
|
+
ctx.stroke();
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
if (config.showCpu.value) {
|
|
399
|
+
drawAreaChart(
|
|
400
|
+
cList.value,
|
|
401
|
+
cpuY,
|
|
402
|
+
chartHeight,
|
|
403
|
+
100,
|
|
404
|
+
'#9254de',
|
|
405
|
+
'rgba(146, 84, 222, 0.5)',
|
|
406
|
+
'rgba(146, 84, 222, 0.05)',
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (config.showMemory.value) {
|
|
411
|
+
drawAreaChart(
|
|
412
|
+
mList.value,
|
|
413
|
+
memY,
|
|
414
|
+
chartHeight,
|
|
415
|
+
targetMemScale,
|
|
416
|
+
'#409eff',
|
|
417
|
+
'rgba(64, 158, 255, 0.5)',
|
|
418
|
+
'rgba(64, 158, 255, 0.05)',
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (config.showFps.value) {
|
|
423
|
+
const currentFps = fList.value[fList.value.length - 1] || 0;
|
|
424
|
+
let colorStr = '#f56c6c';
|
|
425
|
+
let gradStart = 'rgba(245, 108, 108, 0.5)';
|
|
426
|
+
let gradEnd = 'rgba(245, 108, 108, 0.05)';
|
|
427
|
+
|
|
428
|
+
if (currentFps >= 50) {
|
|
429
|
+
colorStr = '#67c23a';
|
|
430
|
+
gradStart = 'rgba(103, 194, 58, 0.5)';
|
|
431
|
+
gradEnd = 'rgba(103, 194, 58, 0.05)';
|
|
432
|
+
} else if (currentFps >= 30) {
|
|
433
|
+
colorStr = '#e6a23c';
|
|
434
|
+
gradStart = 'rgba(230, 162, 60, 0.5)';
|
|
435
|
+
gradEnd = 'rgba(230, 162, 60, 0.05)';
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
drawAreaChart(
|
|
439
|
+
fList.value,
|
|
440
|
+
fpsY,
|
|
441
|
+
chartHeight,
|
|
442
|
+
currentScale.value,
|
|
443
|
+
colorStr,
|
|
444
|
+
gradStart,
|
|
445
|
+
gradEnd,
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
ctx.draw();
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
chartBgColor,
|
|
454
|
+
canvasWidth,
|
|
455
|
+
initCanvas,
|
|
456
|
+
startRenderLoop,
|
|
457
|
+
stopRenderLoop,
|
|
458
|
+
resetCanvas,
|
|
459
|
+
};
|
|
460
|
+
}
|