refactor(frontend): 优化可组合函数

- 改进 useClipboard, useFormDialog, useTTLAnalysis composables
This commit is contained in:
fawney19
2025-12-12 20:22:09 +08:00
parent 1f7db361ad
commit 36a84e19b4
3 changed files with 7 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import { useToast } from './useToast'
import { log } from '@/utils/logger'
export function useClipboard() {
const { success, error: showError } = useToast()
@@ -33,7 +34,7 @@ export function useClipboard() {
document.body.removeChild(textArea)
}
} catch (err) {
console.error('复制失败:', err)
log.error('复制失败:', err)
showError('复制失败,请手动选择文本进行复制')
return false
}

View File

@@ -1,4 +1,4 @@
import { ref, computed, watch, type Ref, type ComputedRef } from 'vue'
import { computed, watch, type Ref, type ComputedRef } from 'vue'
/**
* 表单对话框通用逻辑

View File

@@ -11,6 +11,7 @@ import {
type IntervalTimelineResponse
} from '@/api/cache'
import type { ChartData } from 'chart.js'
import { log } from '@/utils/logger'
// 时间范围选项
export const ANALYSIS_HOURS_OPTIONS = [
@@ -104,7 +105,7 @@ export function useTTLAnalysis() {
}
} catch (error) {
showError('获取 TTL 分析失败')
console.error(error)
log.error('获取 TTL 分析失败', error)
} finally {
ttlAnalysisLoading.value = false
}
@@ -119,7 +120,7 @@ export function useTTLAnalysis() {
})
} catch (error) {
showError('获取缓存命中分析失败')
console.error(error)
log.error('获取缓存命中分析失败', error)
} finally {
hitAnalysisLoading.value = false
}
@@ -136,7 +137,7 @@ export function useTTLAnalysis() {
})
} catch (error) {
showError('获取用户时间线数据失败')
console.error(error)
log.error('获取用户时间线数据失败', error)
} finally {
userTimelineLoading.value = false
}