From 2c4dcaf1303aad28f93dd5020dc991684e29440b Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Fri, 19 Jun 2026 19:26:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8A=BD=E5=8F=96=20BugCollect=20?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=BE=85=E5=8A=A9=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增: - utils/bugCollect.ts - levelTag/statusTag/statusLabel/formatTime/platformTagType 重构: - BugCollectOverview.vue - 使用公共 levelTag - BugCollectIssues.vue - 使用公共辅助函数 - BugCollectEvents.vue - 使用公共 formatTime - BugCollectSourcemaps.vue - 使用公共辅助函数 - BugCollectRankFreq.vue - 使用公共辅助函数 - BugCollectRankRisk.vue - 使用公共辅助函数 - BugCollectIssueDetail.vue - 使用公共辅助函数 Co-Authored-By: Claude --- tenant-platform/src/utils/bugCollect.ts | 75 +++++++++++++++++++ .../views/bug-collect/BugCollectEvents.vue | 8 +- .../bug-collect/BugCollectIssueDetail.vue | 16 ---- .../views/bug-collect/BugCollectIssues.vue | 32 +------- .../views/bug-collect/BugCollectOverview.vue | 11 +-- .../views/bug-collect/BugCollectRankFreq.vue | 28 +------ .../views/bug-collect/BugCollectRankRisk.vue | 28 +------ .../bug-collect/BugCollectSourcemaps.vue | 6 +- 8 files changed, 81 insertions(+), 123 deletions(-) create mode 100644 tenant-platform/src/utils/bugCollect.ts diff --git a/tenant-platform/src/utils/bugCollect.ts b/tenant-platform/src/utils/bugCollect.ts new file mode 100644 index 0000000..a9fde39 --- /dev/null +++ b/tenant-platform/src/utils/bugCollect.ts @@ -0,0 +1,75 @@ +/** + * BugCollect 公共工具函数 + */ + +/** + * 错误级别标签类型 + */ +export function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' { + const map: Record = { + fatal: 'danger', + error: 'warning', + warning: '', + info: 'info', + } + return map[level?.toLowerCase()] ?? '' +} + +/** + * 状态标签类型 + */ +export function statusTag(status: string): '' | 'success' | 'warning' | 'info' | 'danger' { + const map: Record = { + open: 'danger', + resolved: 'success', + ignored: 'info', + } + return map[status] ?? '' +} + +/** + * 状态显示文本 + */ +export function statusLabel(status: string): string { + const map: Record = { + open: '未解决', + resolved: '已解决', + ignored: '已忽略', + } + return map[status] ?? status +} + +/** + * 格式化时间(UTC 转本地时间) + */ +export function formatTime(ts: string | null | undefined): string { + if (!ts) return '-' + // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC + const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') + return date.toLocaleString('zh-CN') +} + +/** + * 平台标签类型 + */ +export function platformTagType(platform: string): '' | 'success' | 'warning' | 'info' | 'danger' { + const map: Record = { + android: 'success', + ios: '', + harmony: 'warning', + } + return map[platform?.toLowerCase()] ?? 'info' +} + +/** + * Issue 类型标签 + */ +export function issueTypeTag(type: string): '' | 'success' | 'warning' | 'info' | 'danger' { + const map: Record = { + CRASH: 'danger', + ERROR: 'warning', + ANR: 'danger', + WARNING: '', + } + return map[type] ?? '' +} diff --git a/tenant-platform/src/views/bug-collect/BugCollectEvents.vue b/tenant-platform/src/views/bug-collect/BugCollectEvents.vue index 5f636d0..92715af 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectEvents.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectEvents.vue @@ -106,6 +106,7 @@ import { ref, onMounted, watch } from 'vue' import { bugCollectApi, type BugCollectEventItem } from '@/api/bugcollect' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { formatTime } from '@/utils/bugCollect' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -121,13 +122,6 @@ const filters = ref({ dateRange: null as [string, string] | null, }) -function formatTime(ts: string) { - if (!ts) return '-' - // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} - async function loadData() { if (!appKey.value || gateStatus.value !== 'enabled') return loading.value = true diff --git a/tenant-platform/src/views/bug-collect/BugCollectIssueDetail.vue b/tenant-platform/src/views/bug-collect/BugCollectIssueDetail.vue index 27b3a5a..ba9b0f9 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectIssueDetail.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectIssueDetail.vue @@ -156,24 +156,8 @@ function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' return map[level?.toLowerCase()] ?? '' } -function statusTag(status: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - open: 'danger', resolved: 'success', ignored: 'info', - } - return map[status] ?? '' -} -function statusLabel(status: string): string { - const map: Record = { open: '未解决', resolved: '已解决', ignored: '已忽略' } - return map[status] ?? status -} -function formatTime(ts: string): string { - if (!ts) return '-' - // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} async function handleResolve() { if (!detail.value) return diff --git a/tenant-platform/src/views/bug-collect/BugCollectIssues.vue b/tenant-platform/src/views/bug-collect/BugCollectIssues.vue index 4068746..8cbbfb9 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectIssues.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectIssues.vue @@ -102,6 +102,7 @@ import { ref, onMounted, watch } from 'vue' import { bugCollectApi, type BugCollectIssue } from '@/api/bugcollect' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { levelTag, statusTag, statusLabel, formatTime } from '@/utils/bugCollect' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -117,37 +118,6 @@ const filters = ref({ dateRange: null as [string, string] | null, }) -function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - fatal: 'danger', - error: 'warning', - warning: '', - info: 'info', - } - return map[level?.toLowerCase()] ?? '' -} - -function statusTag(status: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - open: 'danger', - resolved: 'success', - ignored: 'info', - } - return map[status] ?? '' -} - -function statusLabel(status: string): string { - const map: Record = { open: '未解决', resolved: '已解决', ignored: '已忽略' } - return map[status] ?? status -} - -function formatTime(ts: string) { - if (!ts) return '-' - // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} - async function loadData() { if (!appKey.value || gateStatus.value !== 'enabled') return loading.value = true diff --git a/tenant-platform/src/views/bug-collect/BugCollectOverview.vue b/tenant-platform/src/views/bug-collect/BugCollectOverview.vue index 6e8e6fc..4b5bccb 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectOverview.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectOverview.vue @@ -133,6 +133,7 @@ import { ref, onMounted, onBeforeUnmount, watch, nextTick } from 'vue' import { bugCollectApi, type BugCollectOverview, type BugCollectStatistics } from '@/api/bugcollect' import { Warning, Plus, User, WarningFilled } from '@element-plus/icons-vue' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { levelTag } from '@/utils/bugCollect' import * as echarts from 'echarts' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -172,16 +173,6 @@ let statusChart: echarts.ECharts | null = null let platformChart: echarts.ECharts | null = null let versionChart: echarts.ECharts | null = null -function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - fatal: 'danger', - error: 'warning', - warning: '', - info: 'info', - } - return map[level?.toLowerCase()] ?? '' -} - function getDaysAgo(days: number): string { const d = new Date() d.setDate(d.getDate() - days) diff --git a/tenant-platform/src/views/bug-collect/BugCollectRankFreq.vue b/tenant-platform/src/views/bug-collect/BugCollectRankFreq.vue index ded53c7..506b973 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectRankFreq.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectRankFreq.vue @@ -70,6 +70,7 @@ import { ref, onMounted, onBeforeUnmount, watch, nextTick } from 'vue' import { bugCollectApi, type BugCollectIssueRanking } from '@/api/bugcollect' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { levelTag, statusTag, statusLabel, formatTime } from '@/utils/bugCollect' import * as echarts from 'echarts' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -85,36 +86,9 @@ const LEVEL_COLORS: Record = { warning: '#409EFF', } -function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - fatal: 'danger', - error: 'warning', - warning: '', - info: 'info', - } - return map[level?.toLowerCase()] ?? '' -} -function statusTag(status: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - open: 'danger', - resolved: 'success', - ignored: 'info', - } - return map[status] ?? '' -} -function statusLabel(status: string): string { - const map: Record = { open: '未解决', resolved: '已解决', ignored: '已忽略' } - return map[status] ?? status -} -function formatTime(ts: string) { - if (!ts) return '-' - // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} function truncateTitle(title: string, maxLen = 30): string { if (!title) return '' diff --git a/tenant-platform/src/views/bug-collect/BugCollectRankRisk.vue b/tenant-platform/src/views/bug-collect/BugCollectRankRisk.vue index d6b5aa9..3221c44 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectRankRisk.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectRankRisk.vue @@ -75,6 +75,7 @@ import { ref, onMounted, onBeforeUnmount, watch, nextTick } from 'vue' import { bugCollectApi, type BugCollectIssueRanking } from '@/api/bugcollect' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { levelTag, statusTag, statusLabel, formatTime } from '@/utils/bugCollect' import * as echarts from 'echarts' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -90,29 +91,8 @@ const LEVEL_COLORS: Record = { warning: '#409EFF', } -function levelTag(level: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - fatal: 'danger', - error: 'warning', - warning: '', - info: 'info', - } - return map[level?.toLowerCase()] ?? '' -} -function statusTag(status: string): '' | 'success' | 'warning' | 'info' | 'danger' { - const map: Record = { - open: 'danger', - resolved: 'success', - ignored: 'info', - } - return map[status] ?? '' -} -function statusLabel(status: string): string { - const map: Record = { open: '未解决', resolved: '已解决', ignored: '已忽略' } - return map[status] ?? status -} function riskTagType(score?: number) { if (!score) return 'info' @@ -121,12 +101,6 @@ function riskTagType(score?: number) { return 'success' } -function formatTime(ts: string) { - if (!ts) return '-' - // 服务端返回 UTC 时间(无时区标识),需追加 Z 表示 UTC - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} function truncateTitle(title: string, maxLen = 30): string { if (!title) return '' diff --git a/tenant-platform/src/views/bug-collect/BugCollectSourcemaps.vue b/tenant-platform/src/views/bug-collect/BugCollectSourcemaps.vue index 22ca4c1..663da55 100644 --- a/tenant-platform/src/views/bug-collect/BugCollectSourcemaps.vue +++ b/tenant-platform/src/views/bug-collect/BugCollectSourcemaps.vue @@ -96,6 +96,7 @@ npx react-native bundle --platform android --dev false import { ref, onMounted, watch } from 'vue' import { bugCollectApi, type BugCollectSourcemap } from '@/api/bugcollect' import { useBugCollectApp } from '@/composables/useBugCollectApp' +import { levelTag, statusTag, statusLabel, formatTime } from '@/utils/bugCollect' const { apps, loadingApps, appKey, setApp, gateStatus, applyDialogVisible, applyReason, applyLoading, submitActivation } = useBugCollectApp() @@ -111,11 +112,6 @@ function platformTagType(platform: string): '' | 'success' | 'warning' | 'info' return map[platform?.toLowerCase()] ?? 'info' } -function formatTime(ts: string) { - if (!ts) return '-' - const date = ts.includes('Z') || ts.includes('+') ? new Date(ts) : new Date(ts + 'Z') - return date.toLocaleString('zh-CN') -} async function loadData() { if (!appKey.value || gateStatus.value !== 'enabled') return