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

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

View File

@@ -1,4 +1,5 @@
import { useToast } from './useToast' import { useToast } from './useToast'
import { log } from '@/utils/logger'
export function useClipboard() { export function useClipboard() {
const { success, error: showError } = useToast() const { success, error: showError } = useToast()
@@ -33,7 +34,7 @@ export function useClipboard() {
document.body.removeChild(textArea) document.body.removeChild(textArea)
} }
} catch (err) { } catch (err) {
console.error('复制失败:', err) log.error('复制失败:', err)
showError('复制失败,请手动选择文本进行复制') showError('复制失败,请手动选择文本进行复制')
return false 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 type IntervalTimelineResponse
} from '@/api/cache' } from '@/api/cache'
import type { ChartData } from 'chart.js' import type { ChartData } from 'chart.js'
import { log } from '@/utils/logger'
// 时间范围选项 // 时间范围选项
export const ANALYSIS_HOURS_OPTIONS = [ export const ANALYSIS_HOURS_OPTIONS = [
@@ -104,7 +105,7 @@ export function useTTLAnalysis() {
} }
} catch (error) { } catch (error) {
showError('获取 TTL 分析失败') showError('获取 TTL 分析失败')
console.error(error) log.error('获取 TTL 分析失败', error)
} finally { } finally {
ttlAnalysisLoading.value = false ttlAnalysisLoading.value = false
} }
@@ -119,7 +120,7 @@ export function useTTLAnalysis() {
}) })
} catch (error) { } catch (error) {
showError('获取缓存命中分析失败') showError('获取缓存命中分析失败')
console.error(error) log.error('获取缓存命中分析失败', error)
} finally { } finally {
hitAnalysisLoading.value = false hitAnalysisLoading.value = false
} }
@@ -136,7 +137,7 @@ export function useTTLAnalysis() {
}) })
} catch (error) { } catch (error) {
showError('获取用户时间线数据失败') showError('获取用户时间线数据失败')
console.error(error) log.error('获取用户时间线数据失败', error)
} finally { } finally {
userTimelineLoading.value = false userTimelineLoading.value = false
} }