-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 集成PageSpy #4820
base: main
Are you sure you want to change the base?
feat: 集成PageSpy #4820
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ export { | |
ChevronsLeft, | ||
ChevronsRight, | ||
CircleHelp, | ||
CloudUpload, | ||
Copy, | ||
CornerDownLeft, | ||
Ellipsis, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import type { SegmentedItem } from '@vben-core/shadcn-ui'; | |
|
||
import { computed, ref } from 'vue'; | ||
|
||
import { Copy, RotateCw } from '@vben/icons'; | ||
import { CloudUpload, Copy, RotateCw } from '@vben/icons'; | ||
import { $t, loadLocaleMessages } from '@vben/locales'; | ||
import { | ||
clearPreferencesCache, | ||
|
@@ -30,7 +30,7 @@ import { | |
} from '@vben-core/shadcn-ui'; | ||
import { globalShareState } from '@vben-core/shared/global-state'; | ||
|
||
import { useClipboard } from '@vueuse/core'; | ||
import { useClipboard, useThrottleFn } from '@vueuse/core'; | ||
|
||
import { | ||
Animation, | ||
|
@@ -217,6 +217,18 @@ async function handleReset() { | |
resetPreferences(); | ||
await loadLocaleMessages(preferences.app.locale); | ||
} | ||
const harbor = computed(() => window.$harbor); | ||
// 防抖 | ||
const handleUploadLog = useThrottleFn(() => { | ||
if (!harbor.value) { | ||
return; | ||
} | ||
harbor.value.onOfflineLog('upload'); | ||
message.copyPreferencesSuccess?.( | ||
$t('preferences.logUploadSuccessTitle'), | ||
$t('preferences.logUploadSuccess'), | ||
); | ||
}, 5000); | ||
</script> | ||
|
||
<template> | ||
|
@@ -228,6 +240,13 @@ async function handleReset() { | |
> | ||
<template #extra> | ||
<div class="flex items-center"> | ||
<VbenIconButton | ||
:disabled="!harbor" | ||
:tooltip="$t('preferences.logUpload')" | ||
class="relative" | ||
> | ||
<CloudUpload class="size-4" @click="handleUploadLog" /> | ||
</VbenIconButton> | ||
Comment on lines
+243
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve upload button UX and accessibility The upload button implementation has several areas for improvement:
<VbenIconButton
:disabled="!harbor"
:tooltip="$t('preferences.logUpload')"
+ :loading="isUploading"
class="relative"
+ aria-label="Upload logs"
+ @click="handleUploadLog"
>
- <CloudUpload class="size-4" @click="handleUploadLog" />
+ <CloudUpload class="size-4" />
</VbenIconButton>
|
||
<VbenIconButton | ||
:disabled="!diffPreference" | ||
:tooltip="$t('preferences.resetTip')" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,35 @@ | |
})(); | ||
} | ||
</script> | ||
<!-- 可以使用自己的部署的PageSpy的sdk 修改引入的地址即可 --> | ||
<!-- https://pagespy.mufei88.com 为vben测试sdk地址 --> | ||
<script | ||
crossorigin="anonymous" | ||
src="https://pagespy.mufei88.com/page-spy/index.min.js" | ||
></script> | ||
<script | ||
crossorigin="anonymous" | ||
src="https://pagespy.mufei88.com/plugin/data-harbor/index.min.js" | ||
></script> | ||
<script | ||
crossorigin="anonymous" | ||
src="https://pagespy.mufei88.com/plugin/rrweb/index.min.js" | ||
></script> | ||
Comment on lines
+32
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Enhance the security of external script loading The current implementation loads scripts from an external domain without proper security measures:
Apply these security enhancements: <script
crossorigin="anonymous"
+ integrity="sha384-[HASH]"
+ defer
- src="https://pagespy.mufei88.com/page-spy/index.min.js"
+ src="https://pagespy.mufei88.com/page-spy/1.x.x/index.min.js"
></script> Note: Replace
|
||
<script> | ||
window.$harbor = new DataHarborPlugin(); | ||
window.$rrweb = new RRWebPlugin(); | ||
|
||
[window.$harbor, window.$rrweb].forEach((p) => { | ||
PageSpy.registerPlugin(p); | ||
}); | ||
// 实例化的参数都是可选的 | ||
window.$pageSpy = new PageSpy({ | ||
project: '<%= VITE_APP_TITLE %>', | ||
autoRender: false, | ||
title: 'Vben Admin', | ||
}); | ||
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Configuration values need to be consistent with environment variables The verification reveals inconsistencies in the configuration:
The configuration should be updated to: window.$pageSpy = new PageSpy({
project: '<%= VITE_APP_TITLE %>',
autoRender: false,
title: '<%= VITE_APP_TITLE %>',
}); 🔗 Analysis chainVerify configuration parameters The configuration uses hardcoded values and mixes environment variables. Let's verify the configuration values across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for PageSpy configuration and title usage
# Check for VITE_APP_TITLE usage
echo "Checking VITE_APP_TITLE usage:"
rg "VITE_APP_TITLE" -A 2
# Check for hardcoded 'Vben Admin' title
echo "\nChecking hardcoded title usage:"
rg "'Vben Admin'" -A 2
Length of output: 6028 |
||
// 之后即可使用 PageSpy,前往 https://pagespy.mufei88.com 体验 | ||
</script> | ||
Comment on lines
+44
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve implementation robustness and environment handling The current implementation has several areas for improvement:
Consider refactoring to: <script>
+ // Only initialize in non-production environments or based on configuration
+ if (import.meta.env.DEV || window._VBEN_ADMIN_PRO_APP_CONF_.enablePageSpy) {
+ try {
+ const harbor = new DataHarborPlugin();
+ const rrweb = new RRWebPlugin();
- [window.$harbor, window.$rrweb].forEach((p) => {
+ [harbor, rrweb].forEach((p) => {
PageSpy.registerPlugin(p);
});
- window.$pageSpy = new PageSpy({
+ const pageSpy = new PageSpy({
project: '<%= VITE_APP_TITLE %>',
autoRender: false,
title: 'Vben Admin',
});
+
+ // If needed, expose through a namespaced object instead of directly on window
+ window.__VBEN__ = {
+ ...window.__VBEN__,
+ debug: { pageSpy, harbor, rrweb }
+ };
+ } catch (error) {
+ console.error('Failed to initialize PageSpy:', error);
+ }
+ }
</script>
|
||
</head> | ||
<body> | ||
<div id="app"></div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance error handling and user feedback in log upload
The log upload function needs improvements in several areas:
📝 Committable suggestion