2026-03-11 00:42:46 +08:00
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, computed, watch } from 'vue'
|
2026-03-16 02:41:26 +08:00
|
|
|
|
import { toast } from 'vue-sonner'
|
|
|
|
|
|
import { Icon } from '@iconify/vue'
|
2026-03-11 00:42:46 +08:00
|
|
|
|
import { UserPromptApi } from '@/api/userPrompt'
|
|
|
|
|
|
|
2026-03-16 02:41:26 +08:00
|
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
|
|
import {
|
|
|
|
|
|
AlertDialog,
|
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
|
AlertDialogTrigger
|
|
|
|
|
|
} from '@/components/ui/alert-dialog'
|
|
|
|
|
|
|
2026-03-11 00:42:46 +08:00
|
|
|
|
// Props
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
visible: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Emits
|
2026-03-23 11:56:44 +08:00
|
|
|
|
const emit = defineEmits(['update:visible', 'refresh', 'chat'])
|
2026-03-11 00:42:46 +08:00
|
|
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const promptList = ref([])
|
|
|
|
|
|
const searchKeyword = ref('')
|
|
|
|
|
|
|
2026-03-23 11:56:44 +08:00
|
|
|
|
// Computed - 只搜索名称
|
2026-03-11 00:42:46 +08:00
|
|
|
|
const filteredList = computed(() => {
|
|
|
|
|
|
if (!searchKeyword.value.trim()) return promptList.value
|
|
|
|
|
|
const keyword = searchKeyword.value.trim().toLowerCase()
|
|
|
|
|
|
return promptList.value.filter(item =>
|
2026-03-23 11:56:44 +08:00
|
|
|
|
item.name.toLowerCase().includes(keyword)
|
2026-03-11 00:42:46 +08:00
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Watch
|
|
|
|
|
|
watch(() => props.visible, (newVal) => {
|
|
|
|
|
|
if (newVal) {
|
|
|
|
|
|
loadList()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
|
|
async function loadList() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await UserPromptApi.getUserPromptList()
|
|
|
|
|
|
if (res.code === 0 && res.data) {
|
|
|
|
|
|
promptList.value = res.data.map(item => ({
|
|
|
|
|
|
id: item.id,
|
|
|
|
|
|
name: item.name,
|
2026-04-11 16:22:11 +08:00
|
|
|
|
content: item.content,
|
2026-03-11 00:42:46 +08:00
|
|
|
|
category: item.category,
|
|
|
|
|
|
useCount: item.useCount || 0
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('加载风格列表失败:', error)
|
2026-03-16 02:41:26 +08:00
|
|
|
|
toast.error('加载风格列表失败')
|
2026-03-11 00:42:46 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleClose() {
|
|
|
|
|
|
emit('update:visible', false)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handleDelete(id) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await UserPromptApi.deleteUserPrompt(id)
|
|
|
|
|
|
const index = promptList.value.findIndex(p => p.id === id)
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
|
promptList.value.splice(index, 1)
|
|
|
|
|
|
}
|
2026-03-16 02:41:26 +08:00
|
|
|
|
toast.success('删除成功')
|
2026-03-11 00:42:46 +08:00
|
|
|
|
emit('refresh')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('删除失败:', error)
|
2026-03-16 02:41:26 +08:00
|
|
|
|
toast.error('删除失败')
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-23 11:56:44 +08:00
|
|
|
|
function handleUse(item) {
|
|
|
|
|
|
emit('chat', {
|
|
|
|
|
|
id: item.id,
|
|
|
|
|
|
name: item.name,
|
2026-04-11 16:22:11 +08:00
|
|
|
|
categoryName: item.category || '我的风格',
|
|
|
|
|
|
customSystemPrompt: item.content
|
2026-03-23 11:56:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
handleClose()
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<Dialog :open="visible" @update:open="$emit('update:visible', $event)">
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<DialogContent class="sm:max-w-[500px]">
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<DialogHeader>
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<DialogTitle>我创建的风格</DialogTitle>
|
2026-03-16 02:41:26 +08:00
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 操作栏 -->
|
|
|
|
|
|
<div class="flex gap-3 mb-4">
|
|
|
|
|
|
<Button variant="outline" @click="loadList" :disabled="loading">
|
|
|
|
|
|
<Icon v-if="loading" icon="lucide:loader-2" class="size-4 animate-spin" />
|
|
|
|
|
|
<Icon v-else icon="lucide:refresh-cw" class="size-4" />
|
|
|
|
|
|
刷新
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 搜索框 -->
|
|
|
|
|
|
<div class="mb-4">
|
|
|
|
|
|
<Input
|
|
|
|
|
|
v-model="searchKeyword"
|
2026-03-23 11:56:44 +08:00
|
|
|
|
placeholder="搜索风格名称..."
|
2026-03-16 02:41:26 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 加载状态 -->
|
|
|
|
|
|
<div v-if="loading" class="flex items-center justify-center py-12">
|
|
|
|
|
|
<Icon icon="lucide:loader-2" class="size-8 animate-spin text-primary" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 列表 -->
|
|
|
|
|
|
<div class="prompt-list" v-else-if="filteredList.length > 0">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="item in filteredList"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
class="prompt-card"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="card-header">
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<div class="card-info">
|
|
|
|
|
|
<span class="card-name">{{ item.name }}</span>
|
|
|
|
|
|
<span class="card-category" v-if="item.category">{{ item.category }}</span>
|
|
|
|
|
|
</div>
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<div class="flex gap-2">
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<Button variant="default" size="sm" @click="handleUse(item)">
|
|
|
|
|
|
<Icon icon="lucide:message-circle" class="size-4" />
|
|
|
|
|
|
使用
|
2026-03-16 02:41:26 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
<AlertDialog>
|
|
|
|
|
|
<AlertDialogTrigger as-child>
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<Button variant="ghost" size="sm" class="text-muted-foreground hover:text-destructive">
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<Icon icon="lucide:trash-2" class="size-4" />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</AlertDialogTrigger>
|
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
|
<AlertDialogTitle>确认删除</AlertDialogTitle>
|
|
|
|
|
|
<AlertDialogDescription>
|
2026-03-23 11:56:44 +08:00
|
|
|
|
确定要删除"{{ item.name }}"吗?此操作无法撤销。
|
2026-03-16 02:41:26 +08:00
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
|
|
|
|
|
<AlertDialogAction @click="handleDelete(item.id)">确认删除</AlertDialogAction>
|
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="card-footer">
|
|
|
|
|
|
<span class="text-xs text-muted-foreground">使用 {{ item.useCount || 0 }} 次</span>
|
2026-03-11 00:42:46 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<!-- 空状态 -->
|
|
|
|
|
|
<div class="empty-state" v-else>
|
2026-03-23 11:56:44 +08:00
|
|
|
|
<Icon icon="lucide:sparkles" class="empty-icon" />
|
|
|
|
|
|
<p class="empty-title">暂无创建的风格</p>
|
|
|
|
|
|
<p class="empty-desc">在对话中可保存生成的内容为风格</p>
|
2026-03-16 02:41:26 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</DialogContent>
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
</template>
|
2026-03-11 00:42:46 +08:00
|
|
|
|
|
2026-03-16 02:41:26 +08:00
|
|
|
|
<style scoped lang="less">
|
2026-03-11 00:42:46 +08:00
|
|
|
|
.prompt-list {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
gap: 10px;
|
2026-03-11 00:42:46 +08:00
|
|
|
|
max-height: 400px;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.prompt-card {
|
2026-03-23 11:56:44 +08:00
|
|
|
|
padding: 14px 16px;
|
|
|
|
|
|
border: 1px solid var(--border);
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
background: var(--card);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2026-03-23 11:56:44 +08:00
|
|
|
|
border-color: var(--primary);
|
|
|
|
|
|
box-shadow: 0 2px 8px oklch(0.55 0.14 270 / 0.1);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-info {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 0;
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-name {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
font-size: 14px;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
color: var(--foreground);
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-23 11:56:44 +08:00
|
|
|
|
.card-category {
|
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
|
padding: 2px 8px;
|
|
|
|
|
|
background: var(--muted);
|
|
|
|
|
|
color: var(--muted-foreground);
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
flex-shrink: 0;
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-footer {
|
|
|
|
|
|
display: flex;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
justify-content: flex-end;
|
2026-03-11 00:42:46 +08:00
|
|
|
|
align-items: center;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
margin-top: 8px;
|
|
|
|
|
|
padding-top: 8px;
|
|
|
|
|
|
border-top: 1px solid var(--border);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.empty-state {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
padding: 48px 24px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.empty-icon {
|
2026-03-23 11:56:44 +08:00
|
|
|
|
font-size: 40px;
|
|
|
|
|
|
color: var(--primary);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.empty-title {
|
|
|
|
|
|
font-size: 15px;
|
|
|
|
|
|
font-weight: 500;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
color: var(--foreground);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.empty-desc {
|
|
|
|
|
|
font-size: 13px;
|
2026-03-23 11:56:44 +08:00
|
|
|
|
color: var(--muted-foreground);
|
2026-03-11 00:42:46 +08:00
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|