Files
admin-web/src/components/ApiErrorMeta.vue
T
2026-07-30 17:59:43 +08:00

39 lines
2.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { Copy } from '@lucide/vue'
import type { ApiErrorDetails } from '@/api/http'
const props = defineProps<{ details: ApiErrorDetails }>()
async function copyIdentifier(value: string, label: string) {
try {
await navigator.clipboard.writeText(value)
ElMessage.success(`${label} 已复制`)
} catch {
ElMessage.error(`${label} 复制失败,请手动选择复制`)
}
}
</script>
<template>
<div v-if="details.code || details.requestId || details.traceId" class="api-error-meta" aria-label="接口错误追踪信息">
<span v-if="details.code" class="api-error-code">{{ details.code }}</span>
<button v-if="details.requestId" type="button" :title="`复制请求 ID:${props.details.requestId}`" @click="copyIdentifier(props.details.requestId!, '请求 ID')">
<span>请求 ID</span><code>{{ props.details.requestId }}</code><Copy :size="13" />
</button>
<button v-if="details.traceId" type="button" :title="`复制 Trace ID:${props.details.traceId}`" @click="copyIdentifier(props.details.traceId!, 'Trace ID')">
<span>Trace ID</span><code>{{ props.details.traceId }}</code><Copy :size="13" />
</button>
</div>
</template>
<style scoped>
.api-error-meta { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.api-error-code { padding: 3px 7px; border-radius: 4px; background: #fee4e2; color: #912018; font-size: 10px; font-weight: 750; }
.api-error-meta button { display: inline-flex; min-width: 0; max-width: 100%; min-height: 30px; align-items: center; gap: 6px; padding: 4px 7px; border: 1px solid #fecdca; border-radius: 4px; background: #fff; color: #7a271a; cursor: pointer; }
.api-error-meta button:hover { background: #fff5f4; }
.api-error-meta button span { flex: 0 0 auto; font-size: 10px; font-weight: 700; }
.api-error-meta code { min-width: 0; overflow: hidden; color: #b42318; font-family: "Cascadia Code", Consolas, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.api-error-meta svg { flex: 0 0 auto; }
</style>