462 行
11 KiB
Vue
462 行
11 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref, watch } from "vue"
|
|
|
|
import type { CharacterProfile } from "../../../../shared/types/profile"
|
|
import {
|
|
formatProfileDate,
|
|
isBrowserImageUrl,
|
|
profileDetailedWorkflowStateLabel,
|
|
profileGenerationKind,
|
|
profileGenerationKindLabel,
|
|
profileGenerationKindTone,
|
|
profileInitial,
|
|
profileMetadataText,
|
|
profileSourceLabel,
|
|
profileStatusLabel,
|
|
} from "./profile-ui"
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
profiles: readonly CharacterProfile[]
|
|
selectedId?: string
|
|
loading?: boolean
|
|
canWrite?: boolean
|
|
}>(),
|
|
{
|
|
selectedId: "",
|
|
loading: false,
|
|
canWrite: false,
|
|
},
|
|
)
|
|
|
|
const emit = defineEmits<{
|
|
select: [id: string]
|
|
create: []
|
|
}>()
|
|
|
|
const query = ref("")
|
|
const generationFilter = ref<"all" | "ungenerated" | "quick" | "profile_card">("all")
|
|
|
|
const generationOptions = computed(() => [
|
|
{ value: "all" as const, label: "全部", count: props.profiles.length },
|
|
{
|
|
value: "ungenerated" as const,
|
|
label: "未生成",
|
|
count: props.profiles.filter((profile) => profileGenerationKind(profile) === "ungenerated").length,
|
|
},
|
|
{
|
|
value: "quick" as const,
|
|
label: "快速角色",
|
|
count: props.profiles.filter((profile) => profileGenerationKind(profile) === "quick").length,
|
|
},
|
|
{
|
|
value: "profile_card" as const,
|
|
label: "档案卡",
|
|
count: props.profiles.filter((profile) => profileGenerationKind(profile) === "profile_card").length,
|
|
},
|
|
])
|
|
|
|
const filteredProfiles = computed(() => {
|
|
const keyword = query.value.trim().toLocaleLowerCase()
|
|
return props.profiles.filter((profile) => {
|
|
if (generationFilter.value !== "all" && profileGenerationKind(profile) !== generationFilter.value) return false
|
|
if (!keyword) return true
|
|
return [
|
|
profile.name,
|
|
profile.description,
|
|
profile.base_prompt,
|
|
profile.appearance_prompt,
|
|
profileMetadataText(profile, "identity"),
|
|
profileMetadataText(profile, "personality"),
|
|
].some((value) => value?.toLocaleLowerCase().includes(keyword))
|
|
})
|
|
})
|
|
|
|
watch(
|
|
() => [
|
|
generationFilter.value,
|
|
query.value,
|
|
props.selectedId,
|
|
props.profiles.map((profile) => `${profile.profile_id}:${profileGenerationKind(profile)}`).join("|"),
|
|
],
|
|
() => {
|
|
if (filteredProfiles.value.some((profile) => profile.profile_id === props.selectedId)) return
|
|
if (filteredProfiles.value.length) {
|
|
emit("select", filteredProfiles.value[0].profile_id)
|
|
return
|
|
}
|
|
emit("select", "")
|
|
},
|
|
)
|
|
</script>
|
|
|
|
<template>
|
|
<aside class="profile-master" aria-label="角色列表">
|
|
<header class="master-toolbar">
|
|
<label class="profile-search">
|
|
<span aria-hidden="true">⌕</span>
|
|
<input v-model="query" type="search" aria-label="搜索角色名称或设定" placeholder="搜索角色名称或设定" />
|
|
</label>
|
|
<div class="generation-filter" role="group" aria-label="角色分类">
|
|
<button
|
|
v-for="option in generationOptions"
|
|
:key="option.value"
|
|
type="button"
|
|
:class="{ active: generationFilter === option.value }"
|
|
:aria-pressed="generationFilter === option.value"
|
|
@click="generationFilter = option.value"
|
|
>
|
|
<span>{{ option.label }}</span>
|
|
<em>{{ option.count }}</em>
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div v-if="loading && !profiles.length" class="list-loading" role="status" aria-label="正在加载角色">
|
|
<span v-for="index in 4" :key="index" />
|
|
</div>
|
|
<div v-else-if="!filteredProfiles.length" class="list-empty" role="status">
|
|
<strong>{{ profiles.length ? "没有匹配角色" : "暂无角色档案" }}</strong>
|
|
<span>{{ profiles.length ? "调整搜索词或角色分类。" : "新建或导入角色后会显示在这里。" }}</span>
|
|
<button v-if="!profiles.length" type="button" :disabled="!canWrite" @click="emit('create')">新建角色</button>
|
|
</div>
|
|
<div v-else class="profile-list">
|
|
<button
|
|
v-for="profile in filteredProfiles"
|
|
:key="profile.profile_id"
|
|
type="button"
|
|
class="profile-list-item"
|
|
:class="[
|
|
`kind-${profileGenerationKind(profile)}`,
|
|
{ active: profile.profile_id === selectedId },
|
|
]"
|
|
:aria-pressed="profile.profile_id === selectedId"
|
|
@click="emit('select', profile.profile_id)"
|
|
>
|
|
<span class="list-avatar" aria-hidden="true">
|
|
<img v-if="isBrowserImageUrl(profile.avatar_image_uri)" :src="profile.avatar_image_uri || ''" alt="" />
|
|
<b v-else>{{ profileInitial(profile) }}</b>
|
|
</span>
|
|
<span class="list-copy">
|
|
<span class="list-title">
|
|
<strong>{{ profile.name }}</strong>
|
|
<em :class="profileGenerationKindTone(profile)">{{ profileGenerationKindLabel(profile) }}</em>
|
|
</span>
|
|
<small>{{ profile.description || profileMetadataText(profile, "identity") || "未填写角色简介" }}</small>
|
|
<small v-if="profileDetailedWorkflowStateLabel(profile)" class="workflow-state">
|
|
{{ profileDetailedWorkflowStateLabel(profile) }}
|
|
</small>
|
|
<span class="list-meta">
|
|
<span>{{ profileStatusLabel(profile.status) }} · {{ profileSourceLabel(profile) }}</span>
|
|
<time :datetime="profile.updated_at">{{ formatProfileDate(profile.updated_at) }}</time>
|
|
</span>
|
|
</span>
|
|
</button>
|
|
</div>
|
|
<footer class="master-footer">
|
|
<span>显示 {{ filteredProfiles.length }} / {{ profiles.length }}</span>
|
|
<span v-if="loading">同步中</span>
|
|
</footer>
|
|
</aside>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.profile-master {
|
|
display: grid;
|
|
grid-template-rows: auto minmax(0, 1fr) auto;
|
|
min-width: 0;
|
|
min-height: 0;
|
|
border-right: 1px solid var(--border);
|
|
background: var(--panel-muted);
|
|
}
|
|
|
|
.master-toolbar {
|
|
display: grid;
|
|
gap: 8px;
|
|
padding: 12px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
.profile-search {
|
|
position: relative;
|
|
min-width: 0;
|
|
}
|
|
|
|
.profile-search > span {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 10px;
|
|
color: var(--text-soft);
|
|
transform: translateY(-50%);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.profile-search input {
|
|
width: 100%;
|
|
height: 38px;
|
|
min-width: 0;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
color: var(--text);
|
|
background: var(--panel);
|
|
outline: none;
|
|
}
|
|
|
|
.profile-search input {
|
|
padding: 0 10px 0 32px;
|
|
}
|
|
|
|
.profile-search input:focus {
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 3px var(--accent-soft);
|
|
}
|
|
|
|
.generation-filter {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
gap: 3px;
|
|
min-width: 0;
|
|
padding-bottom: 2px;
|
|
}
|
|
|
|
.generation-filter button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 5px;
|
|
min-width: 0;
|
|
min-height: 38px;
|
|
border-color: transparent;
|
|
padding: 0 4px;
|
|
color: var(--text-soft);
|
|
background: transparent;
|
|
font-size: 12px;
|
|
font-weight: 750;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.generation-filter button:hover,
|
|
.generation-filter button.active {
|
|
border-color: var(--border);
|
|
color: var(--text);
|
|
background: var(--panel);
|
|
}
|
|
|
|
.generation-filter button.active {
|
|
box-shadow: inset 0 -2px 0 var(--accent);
|
|
}
|
|
|
|
.generation-filter em {
|
|
min-width: 18px;
|
|
border-radius: 999px;
|
|
padding: 1px 5px;
|
|
background: var(--bg-soft);
|
|
font-size: 10px;
|
|
font-style: normal;
|
|
}
|
|
|
|
.profile-list {
|
|
min-height: 0;
|
|
overflow-y: auto;
|
|
padding: 8px;
|
|
}
|
|
|
|
.profile-list-item {
|
|
display: grid;
|
|
grid-template-columns: 44px minmax(0, 1fr);
|
|
gap: 10px;
|
|
width: 100%;
|
|
min-height: 82px;
|
|
margin-bottom: 5px;
|
|
border-color: transparent;
|
|
padding: 10px;
|
|
text-align: left;
|
|
background: transparent;
|
|
border-color: var(--border);
|
|
}
|
|
|
|
.profile-list-item.kind-ungenerated {
|
|
border-color: color-mix(in srgb, var(--neutral, #7b8494) 52%, var(--border));
|
|
}
|
|
|
|
.profile-list-item.kind-quick {
|
|
border-color: color-mix(in srgb, var(--warn, #d5963d) 52%, var(--border));
|
|
}
|
|
|
|
.profile-list-item.kind-profile_card {
|
|
border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
|
|
}
|
|
|
|
.profile-list-item:hover {
|
|
border-color: var(--border);
|
|
background: var(--panel);
|
|
}
|
|
|
|
.profile-list-item.active {
|
|
border-color: var(--accent-strong);
|
|
background: var(--panel);
|
|
outline: 1px solid color-mix(in srgb, var(--accent) 36%, transparent);
|
|
}
|
|
|
|
.list-avatar {
|
|
display: grid;
|
|
place-items: center;
|
|
width: 44px;
|
|
height: 44px;
|
|
overflow: hidden;
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
color: #fff;
|
|
background: var(--primary);
|
|
font-weight: 850;
|
|
}
|
|
|
|
.list-avatar img {
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
|
|
.list-copy {
|
|
display: grid;
|
|
gap: 5px;
|
|
min-width: 0;
|
|
}
|
|
|
|
.list-title,
|
|
.list-meta,
|
|
.master-footer {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
min-width: 0;
|
|
}
|
|
|
|
.list-title strong,
|
|
.list-copy > small,
|
|
.list-meta span,
|
|
.list-meta time {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.list-copy > small.workflow-state {
|
|
color: var(--accent);
|
|
font-weight: 700;
|
|
}
|
|
|
|
.list-title strong {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.list-title em {
|
|
flex: 0 0 auto;
|
|
border-radius: 999px;
|
|
padding: 2px 7px;
|
|
color: var(--text-soft);
|
|
background: var(--bg-soft);
|
|
font-size: 10px;
|
|
font-style: normal;
|
|
font-weight: 800;
|
|
}
|
|
|
|
.list-title em.good {
|
|
color: var(--accent);
|
|
}
|
|
|
|
.list-title em.warn {
|
|
color: var(--warn, #d5963d);
|
|
}
|
|
|
|
.list-title em.bad {
|
|
color: var(--danger, #e26873);
|
|
}
|
|
|
|
.list-copy > small,
|
|
.list-meta,
|
|
.master-footer {
|
|
color: var(--text-soft);
|
|
font-size: 11px;
|
|
}
|
|
|
|
.master-footer {
|
|
min-height: 38px;
|
|
padding: 0 12px;
|
|
border-top: 1px solid var(--border);
|
|
}
|
|
|
|
.list-loading,
|
|
.list-empty {
|
|
align-self: start;
|
|
display: grid;
|
|
gap: 9px;
|
|
padding: 14px;
|
|
}
|
|
|
|
.list-loading span {
|
|
height: 76px;
|
|
border-radius: 6px;
|
|
background: linear-gradient(90deg, var(--panel) 25%, var(--bg-soft) 50%, var(--panel) 75%);
|
|
background-size: 200% 100%;
|
|
animation: profile-loading 1.4s infinite linear;
|
|
}
|
|
|
|
.list-empty {
|
|
place-items: start;
|
|
margin: 10px;
|
|
border: 1px dashed var(--border);
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.list-empty span {
|
|
color: var(--text-soft);
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.list-empty button {
|
|
min-height: 36px;
|
|
padding: 0 12px;
|
|
font-weight: 750;
|
|
}
|
|
|
|
.sr-only {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
overflow: hidden;
|
|
clip: rect(0, 0, 0, 0);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
@keyframes profile-loading {
|
|
to {
|
|
background-position: -200% 0;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 820px) {
|
|
.profile-master {
|
|
max-height: 430px;
|
|
border-right: 0;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
}
|
|
|
|
@media (max-width: 560px) {
|
|
.profile-master {
|
|
max-height: 500px;
|
|
}
|
|
|
|
.generation-filter button {
|
|
min-height: 44px;
|
|
}
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.list-loading span {
|
|
animation: none;
|
|
}
|
|
}
|
|
</style>
|