CodexUserAttachedFileCard.vue
4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<div
class="file-generated-card codex-user-attached-card"
role="button"
tabindex="0"
@click="onOpen"
@keydown.enter.prevent="onOpen"
>
<div class="file-card-content">
<div class="file-card-icon">
<img :src="iconSrc" :alt="extension" @error="onImgError" />
</div>
<div class="file-card-info">
<div class="file-card-name">{{ name }}</div>
<div class="file-card-time">{{ kindLabel }}</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
getAttachmentKindLabel,
getFileTypeFromNameForOpen,
} from "@/utils/attachmentFileMeta";
import { openWorkspaceAttachment } from "@/utils/openWorkspaceAttachment";
const props = defineProps<{
id: number;
name: string;
filePath?: string;
/** 后端或拖拽带来的类型提示,打开时仍以文件名为准推断 */
type?: string;
}>();
const router = useRouter();
const route = useRoute();
const extension = computed(
() => props.name.split(".").pop()?.toLowerCase() || "",
);
const iconSrc = computed(() => {
const ext = extension.value;
const iconMap: Record<string, string> = {
md: "/md_icon.svg",
pdf: "/pdf_icon.svg",
doc: "/word_icon.svg",
docx: "/word_icon.svg",
xls: "/excel_icon.svg",
xlsx: "/excel_icon.svg",
ppt: "/PPT_icon.svg",
pptx: "/PPT_icon.svg",
txt: "/TXT_icon.svg",
jpg: "/jpg_icon.svg",
jpeg: "/jpg_icon.svg",
png: "/png_icon.svg",
gif: "/gif_icon.svg",
};
return iconMap[ext] || "/TXT_icon.svg";
});
const kindLabel = computed(() => getAttachmentKindLabel(props.name));
function onImgError(e: Event) {
(e.target as HTMLImageElement).src = "/TXT_icon.svg";
}
async function onOpen() {
await openWorkspaceAttachment(router, route, {
fileName: props.name,
filePath: props.filePath,
fileType: getFileTypeFromNameForOpen(props.name),
knowledgeFileId: props.filePath ? undefined : props.id,
});
}
</script>
<style scoped>
/* 对齐 MarkdownPreview 中 .file-generated-card 的视觉 */
.file-generated-card {
margin: 0 0 8px 0;
max-width: 320px;
padding: 12px 16px;
background: var(--color-card, #2a2a2a);
border: 1px solid var(--color-border, #444);
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
display: block;
}
/* 悬停时保持与默认相同的卡片底色,避免 --color-card-hover 在部分主题下异常变黑 */
.file-generated-card.codex-user-attached-card:hover {
background: var(--color-card, #2a2a2a);
border-color: var(--color-primary, #409eff);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(64, 158, 255, 0.15);
}
.file-card-content {
display: flex;
align-items: center;
gap: 12px;
}
.file-card-icon {
flex-shrink: 0;
width: 48px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.05);
border-radius: 6px;
}
.file-card-icon img {
width: 32px;
height: 32px;
object-fit: contain;
}
.file-card-info {
flex: 1;
min-width: 0;
}
.file-card-name {
font-size: 14px;
font-weight: 500;
color: var(--color-text, #fff);
margin-bottom: 4px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-card-time {
font-size: 12px;
color: var(--color-text-secondary, #999);
}
html.light .file-generated-card,
:global(html.light) .file-generated-card {
background: var(--color-card, #ffffff);
border-color: var(--color-border, #e0e0e0);
}
html.light .file-generated-card.codex-user-attached-card:hover,
:global(html.light) .file-generated-card.codex-user-attached-card:hover {
background: var(--color-card, #ffffff);
border-color: var(--color-primary, #1e70ff);
}
html.light .file-card-icon,
:global(html.light) .file-card-icon {
background: rgba(0, 0, 0, 0.05);
}
html.light .file-card-name,
:global(html.light) .file-card-name {
color: var(--color-text, #24292e);
}
html.light .file-card-time,
:global(html.light) .file-card-time {
color: var(--color-text-secondary, #666);
}
</style>