提示词保存

This commit is contained in:
2025-11-13 01:06:28 +08:00
parent fc7d2ccea5
commit c652d0ddf3
49 changed files with 4072 additions and 2452 deletions

View File

@@ -0,0 +1,242 @@
<script setup>
import { ref, watch } from 'vue'
import { EditOutlined, CopyOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import ChatMessageRenderer from '@/components/ChatMessageRenderer.vue'
import { ChatMessageApi } from '@/api/chat'
import { streamChat } from '@/utils/streamChat'
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
mergedText: {
type: String,
default: '',
},
textCount: {
type: Number,
default: 0,
},
})
const emit = defineEmits(['update:visible', 'copy', 'save', 'use'])
const batchPrompt = ref('')
const batchPromptEditMode = ref(false)
const batchPromptGenerating = ref(false)
const hasGenerated = ref(false)
watch(() => props.visible, (newVal) => {
if (newVal && props.mergedText && !hasGenerated.value) {
generateBatchPrompt()
} else if (!newVal) {
batchPrompt.value = ''
batchPromptEditMode.value = false
batchPromptGenerating.value = false
hasGenerated.value = false
}
})
watch(() => props.mergedText, (newVal) => {
if (props.visible && newVal && !hasGenerated.value) {
generateBatchPrompt()
}
})
async function generateBatchPrompt() {
if (!props.mergedText || hasGenerated.value) return
hasGenerated.value = true
try {
batchPromptGenerating.value = true
const createPayload = { roleId: 20 }
console.debug('createChatConversationMy payload(batch):', createPayload)
const conversationResp = await ChatMessageApi.createChatConversationMy(createPayload)
let conversationId = null
if (conversationResp?.data) {
conversationId = typeof conversationResp.data === 'object' ? conversationResp.data.id : conversationResp.data
}
if (!conversationId) {
throw new Error('创建对话失败:未获取到 conversationId')
}
const aiContent = await streamChat({
conversationId,
content: props.mergedText,
onUpdate: (fullText) => {
batchPrompt.value = fullText
},
enableTypewriter: true,
typewriterSpeed: 10,
typewriterBatchSize: 2
})
if (aiContent && aiContent !== batchPrompt.value) {
batchPrompt.value = aiContent
}
message.success(`批量分析完成:已基于 ${props.textCount} 个视频的文案生成综合提示词`)
} catch (aiError) {
console.error('AI生成失败:', aiError)
message.error('AI生成失败请稍后重试')
} finally {
batchPromptGenerating.value = false
}
}
function handleClose() {
emit('update:visible', false)
}
function handleCopy() {
emit('copy', batchPrompt.value)
}
function handleSave() {
emit('save', batchPrompt.value)
}
function handleUse() {
emit('use', batchPrompt.value)
}
</script>
<template>
<a-modal
:open="visible"
title="综合分析结果"
:width="800"
:maskClosable="false"
:keyboard="false"
@cancel="handleClose">
<div class="batch-prompt-modal">
<div v-if="!batchPromptEditMode" class="batch-prompt-display">
<ChatMessageRenderer
:content="batchPrompt"
:is-streaming="batchPromptGenerating"
/>
</div>
<a-textarea
v-else
v-model:value="batchPrompt"
:rows="15"
placeholder="内容将在这里显示..." />
</div>
<template #footer>
<a-space>
<a-button size="small" :title="batchPromptEditMode ? '取消编辑' : '编辑'" @click="batchPromptEditMode = !batchPromptEditMode">
<template #icon>
<EditOutlined />
</template>
</a-button>
<a-button size="small" title="复制" @click="handleCopy">
<template #icon>
<CopyOutlined />
</template>
</a-button>
<a-button size="small" title="保存提示词" @click="handleSave" :disabled="!batchPrompt.trim()">
保存提示词
</a-button>
<a-button @click="handleClose">取消</a-button>
<a-button
type="primary"
:disabled="batchPromptGenerating || !batchPrompt.trim()"
@click="handleUse">去创作</a-button>
</a-space>
</template>
</a-modal>
</template>
<style scoped>
.batch-prompt-modal {
min-height: 200px;
}
.batch-prompt-display {
min-height: 300px;
max-height: 500px;
overflow-y: auto;
padding: 12px;
background: #0d0d0d;
border: 1px solid var(--color-border);
border-radius: 6px;
line-height: 1.6;
}
.batch-prompt-display :deep(h1) {
font-size: 18px;
font-weight: 600;
margin: 12px 0;
color: var(--color-text);
}
.batch-prompt-display :deep(h2) {
font-size: 16px;
font-weight: 600;
margin: 16px 0 8px 0;
color: var(--color-text);
}
.batch-prompt-display :deep(h3) {
font-size: 14px;
font-weight: 600;
margin: 12px 0 6px 0;
color: var(--color-text-secondary);
}
.batch-prompt-display :deep(p) {
margin: 8px 0;
color: var(--color-text-secondary);
}
.batch-prompt-display :deep(ul),
.batch-prompt-display :deep(ol) {
margin: 8px 0;
padding-left: 20px;
}
.batch-prompt-display :deep(li) {
margin: 4px 0;
color: var(--color-text-secondary);
}
.batch-prompt-display :deep(strong) {
font-weight: 600;
color: var(--color-text);
}
.batch-prompt-display :deep(code) {
background: #1a1a1a;
padding: 2px 6px;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 12px;
color: #e11d48;
}
.batch-prompt-display :deep(pre) {
background: #1a1a1a;
padding: 12px;
border-radius: 6px;
overflow-x: auto;
margin: 8px 0;
}
.batch-prompt-display :deep(pre code) {
background: transparent;
padding: 0;
}
.batch-prompt-display :deep(blockquote) {
border-left: 3px solid var(--color-primary);
padding-left: 12px;
margin: 8px 0;
color: var(--color-text-secondary);
}
</style>

View File

@@ -0,0 +1,126 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({
modelValue: {
type: Object,
required: true,
},
loading: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['update:modelValue', 'analyze', 'reset'])
const form = ref({ ...props.modelValue })
function handleAnalyze() {
emit('update:modelValue', { ...form.value })
emit('analyze')
}
function handleReset() {
form.value = { platform: '抖音', url: '', count: 20, sort_type: 0 }
emit('update:modelValue', { ...form.value })
emit('reset')
}
</script>
<template>
<section class="card">
<a-form :model="form" layout="vertical">
<a-form-item label="平台">
<a-radio-group v-model:value="form.platform" button-style="solid">
<a-radio-button value="抖音">抖音</a-radio-button>
</a-radio-group>
</a-form-item>
<a-form-item label="主页/视频链接">
<a-input
v-model:value="form.url"
placeholder="粘贴抖音主页或视频链接,或点击下方示例试一试"
allow-clear
size="large"
/>
</a-form-item>
<a-form-item label="最大数量建议保持默认值20">
<div class="slider-row">
<a-slider v-model:value="form.count" :min="1" :max="100" :tooltip-open="true" style="flex:1" />
<a-input-number v-model:value="form.count" :min="1" :max="100" style="width:96px; margin-left:12px;" />
</div>
<div class="form-hint">数量越大越全面但分析时间更长建议 2030</div>
</a-form-item>
<a-space>
<a-button type="primary" :loading="loading" @click="handleAnalyze">
{{ loading ? '分析中' : '开始分析' }}
</a-button>
<a-button @click="handleReset">清空</a-button>
</a-space>
</a-form>
</section>
</template>
<style scoped>
.card {
background: var(--color-surface);
border-radius: 8px;
padding: 16px;
box-shadow: var(--shadow-inset-card);
border: 1px solid var(--color-border);
}
.slider-row {
display: flex;
align-items: center;
}
.form-hint {
margin-top: 6px;
font-size: 12px;
color: var(--color-text-secondary);
}
:deep(.ant-input), :deep(.ant-input-affix-wrapper), :deep(textarea) {
background: #0f0f0f;
border-color: var(--color-border);
}
:deep(.ant-input:hover), :deep(.ant-input-affix-wrapper:hover), :deep(textarea:hover) {
border-color: color-mix(in oklab, var(--color-primary) 60%, var(--color-border));
}
:deep(.ant-input:focus), :deep(.ant-input-affix-wrapper-focused), :deep(textarea:focus) {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px color-mix(in oklab, var(--color-primary) 25%, transparent);
}
:deep(.ant-slider) {
padding: 10px 0;
}
:deep(.ant-slider-rail) {
background-color: #252525;
height: 4px;
}
:deep(.ant-slider-track) {
background-color: var(--color-primary);
height: 4px;
}
:deep(.ant-slider:hover .ant-slider-track) {
background-color: var(--color-primary);
}
:deep(.ant-slider-handle::after) {
box-shadow: 0 0 0 2px var(--color-primary);
}
:deep(.ant-slider-handle:focus-visible::after),
:deep(.ant-slider-handle:hover::after),
:deep(.ant-slider-handle:active::after) {
box-shadow: 0 0 0 3px var(--color-primary);
}
</style>

View File

@@ -0,0 +1,232 @@
<script setup>
import { reactive, h } from 'vue'
import { DownloadOutlined } from '@ant-design/icons-vue'
import { formatTime } from '../utils/benchmarkUtils'
import ExpandedRowContent from './ExpandedRowContent.vue'
const props = defineProps({
data: {
type: Array,
required: true,
},
selectedRowKeys: {
type: Array,
required: true,
},
expandedRowKeys: {
type: Array,
required: true,
},
loading: {
type: Boolean,
default: false,
},
})
const emit = defineEmits([
'update:selectedRowKeys',
'update:expandedRowKeys',
'analyze',
'export',
'batchAnalyze',
'copy',
'saveToServer',
'createContent',
])
const defaultColumns = [
{ title: '封面', key: 'cover', dataIndex: 'cover', width: 120, resizable: true },
{ title: '描述', key: 'desc', dataIndex: 'desc', width: 280, resizable: true, ellipsis: true },
{ title: '点赞', key: 'digg_count', dataIndex: 'digg_count', width: 90, resizable: true,
sorter: (a, b) => (a.digg_count || 0) - (b.digg_count || 0), defaultSortOrder: 'descend' },
{ title: '评论', key: 'comment_count', dataIndex: 'comment_count', width: 90, resizable: true,
sorter: (a, b) => (a.comment_count || 0) - (b.comment_count || 0) },
{ title: '分享', key: 'share_count', dataIndex: 'share_count', width: 90, resizable: true,
sorter: (a, b) => (a.share_count || 0) - (b.share_count || 0) },
{ title: '收藏', key: 'collect_count', dataIndex: 'collect_count', width: 90, resizable: true,
sorter: (a, b) => (a.collect_count || 0) - (b.collect_count || 0) },
{ title: '时长(s)', key: 'duration_s', dataIndex: 'duration_s', width: 90, resizable: true,
sorter: (a, b) => (a.duration_s || 0) - (b.duration_s || 0) },
{ title: '置顶', key: 'is_top', dataIndex: 'is_top', width: 70, resizable: true },
{ title: '创建时间', key: 'create_time', dataIndex: 'create_time', width: 160, resizable: true,
sorter: (a, b) => (a.create_time || 0) - (b.create_time || 0) },
{ title: '链接', key: 'share_url', dataIndex: 'share_url', width: 80, resizable: true,
customRender: ({ record }) => record.share_url ? h('a', { href: record.share_url, target: '_blank' }, '打开') : null },
{ title: '操作', key: 'action', width: 100, resizable: true, fixed: 'right' },
]
const columns = reactive([...defaultColumns])
function onSelectChange(selectedKeys) {
emit('update:selectedRowKeys', selectedKeys)
}
function onExpandedRowKeysChange(keys) {
emit('update:expandedRowKeys', keys)
}
</script>
<template>
<section class="card results-card" v-if="data.length > 0">
<div class="section-header">
<div class="section-title">分析结果</div>
<a-space align="center">
<a-button
size="small"
type="default"
@click="$emit('export')"
:disabled="data.length === 0 || selectedRowKeys.length === 0 || selectedRowKeys.length > 10">
<template #icon>
<DownloadOutlined />
</template>
导出Excel ({{ selectedRowKeys.length }}/10)
</a-button>
<a-button size="small" type="primary" class="batch-btn" @click="$emit('batchAnalyze')">
批量分析 ({{ selectedRowKeys.length }})
</a-button>
</a-space>
</div>
<a-table
:dataSource="data"
:columns="columns"
:pagination="false"
:row-selection="{ selectedRowKeys, onChange: onSelectChange, hideSelectAll: true }"
:expandedRowKeys="expandedRowKeys"
@expandedRowsChange="onExpandedRowKeysChange"
:expandable="{
expandRowByClick: false
}"
:rowKey="(record) => String(record.id)"
:loading="loading"
class="benchmark-table">
<template #expandedRowRender="{ record }">
<ExpandedRowContent
:record="record"
@analyze="(row) => $emit('analyze', row)"
@copy="(row) => $emit('copy', row)"
@save-to-server="(row) => $emit('saveToServer', row)"
@create-content="(row) => $emit('createContent', row)"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'cover'">
<img v-if="record.cover" :src="record.cover" alt="cover" loading="lazy"
style="width:120px;height:68px;object-fit:cover;border-radius:6px;border:1px solid #eee;" />
<span v-else style="color:#999;font-size:12px;">无封面</span>
</template>
<template v-else-if="column.key === 'desc'">
<span :title="record.desc">{{ record.desc || '-' }}</span>
</template>
<template v-else-if="column.key === 'play_count'">
{{ record.play_count ? (record.play_count / 10000).toFixed(1) + 'w' : '0' }}
</template>
<template v-else-if="column.key === 'digg_count'">
{{ record.digg_count ? record.digg_count.toLocaleString('zh-CN') : '0' }}
</template>
<template v-else-if="column.key === 'comment_count'">
{{ record.comment_count ? record.comment_count.toLocaleString('zh-CN') : '0' }}
</template>
<template v-else-if="column.key === 'share_count'">
{{ record.share_count ? record.share_count.toLocaleString('zh-CN') : '0' }}
</template>
<template v-else-if="column.key === 'collect_count'">
{{ record.collect_count ? record.collect_count.toLocaleString('zh-CN') : '0' }}
</template>
<template v-else-if="column.key === 'is_top'">
<a-tag v-if="record.is_top" color="red">置顶</a-tag>
<span v-else>-</span>
</template>
<template v-else-if="column.key === 'create_time'">
{{ formatTime(record.create_time) }}
</template>
<template v-else-if="column.key === 'share_url'">
<a v-if="record.share_url" :href="record.share_url" target="_blank" class="link-btn">打开</a>
<span v-else>-</span>
</template>
<template v-else-if="column.key === 'action'">
<a-space>
<a-button size="small" type="primary" :loading="record._analyzing" :disabled="record._analyzing" @click="$emit('analyze', record)">
{{ record._analyzing ? '分析中…' : '分析' }}
</a-button>
</a-space>
</template>
</template>
</a-table>
</section>
</template>
<style scoped>
.card {
background: var(--color-surface);
border-radius: 8px;
padding: 16px;
box-shadow: var(--shadow-inset-card);
border: 1px solid var(--color-border);
}
.results-card {
min-height: 420px;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.section-header .ant-space {
display: flex;
align-items: center;
}
.section-header .ant-btn {
display: inline-flex;
align-items: center;
justify-content: center;
}
.section-title {
font-size: 12px;
color: var(--color-text-secondary);
margin-bottom: 12px;
}
.batch-btn {
font-weight: 600;
}
.batch-btn:hover {
box-shadow: var(--glow-primary);
filter: brightness(1.03);
}
.link-btn {
color: #1677ff;
text-decoration: none;
transition: opacity 0.2s;
}
.link-btn:hover {
opacity: 0.8;
text-decoration: underline;
}
.benchmark-table :deep(.ant-table-expand-icon-th),
.benchmark-table :deep(.ant-table-row-expand-icon-cell) {
width: 48px;
min-width: 48px;
text-align: center;
}
.benchmark-table :deep(.ant-table-row-expand-icon) {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
cursor: pointer;
user-select: none;
}
</style>

View File

@@ -0,0 +1,195 @@
<script setup>
import { CopyOutlined, SaveOutlined } from '@ant-design/icons-vue'
import ChatMessageRenderer from '@/components/ChatMessageRenderer.vue'
const props = defineProps({
record: {
type: Object,
required: true,
},
})
const emit = defineEmits(['analyze', 'copy', 'saveToServer', 'createContent'])
function handleCopy() {
emit('copy', props.record)
}
function handleSaveToServer() {
emit('saveToServer', props.record)
}
function handleCreateContent() {
emit('createContent', props.record)
}
</script>
<template>
<div class="expanded-content">
<!-- 未分析的行显示提示 -->
<div v-if="!record.transcriptions && !record.prompt" class="no-analysis-tip">
<a-empty description="该视频尚未分析">
<template #image>
<svg width="120" height="120" viewBox="0 0 120 120" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="30" width="80" height="60" rx="4" stroke="currentColor" stroke-width="2" fill="none" opacity="0.3"/>
<circle cx="40" cy="50" r="8" fill="currentColor" opacity="0.4"/>
<rect x="54" y="47" width="40" height="6" rx="3" fill="currentColor" opacity="0.4"/>
<rect x="54" y="60" width="32" height="6" rx="3" fill="currentColor" opacity="0.4"/>
</svg>
</template>
<a-button type="primary" @click="$emit('analyze', record)" :loading="record._analyzing">
{{ record._analyzing ? '分析中…' : '开始分析' }}
</a-button>
</a-empty>
</div>
<!-- 已分析的行显示内容 -->
<div v-else class="two-col">
<!-- 左侧原配音内容 -->
<section class="col left-col">
<div class="sub-title">原配音</div>
<div class="transcript-box" v-if="record.transcriptions">
<div class="transcript-content">{{ record.transcriptions }}</div>
</div>
<div v-else class="no-transcript">暂无转写文本请先点击"分析"获取</div>
</section>
<!-- 右侧提示词 -->
<section class="col right-col">
<div class="sub-title">提示词</div>
<div class="prompt-display-wrapper">
<ChatMessageRenderer
:content="record.prompt || ''"
:is-streaming="record._analyzing || false"
/>
<div v-if="!record.prompt" class="no-prompt">暂无提示词</div>
</div>
<div class="right-actions">
<a-space>
<a-button
size="small"
type="text"
class="copy-btn"
:title="'复制'"
@click="handleCopy">
<template #icon>
<CopyOutlined />
</template>
</a-button>
<a-button
v-if="record.prompt"
size="small"
type="text"
class="save-server-btn"
:title="'保存'"
@click="handleSaveToServer">
<template #icon>
<SaveOutlined />
</template>
保存
</a-button>
<a-button
type="dashed"
:disabled="!record.prompt || record._analyzing"
@click="handleCreateContent">基于提示词去创作</a-button>
</a-space>
</div>
</section>
</div>
</div>
</template>
<style scoped>
.expanded-content {
padding: 16px;
background: #161616;
border-radius: 6px;
margin: 8px 0;
}
.two-col {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
.col {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: 6px;
padding: 12px;
}
.left-col .transcript-content {
white-space: pre-wrap;
line-height: 1.6;
color: var(--color-text-secondary);
background: #0d0d0d;
border: 1px dashed var(--color-border);
border-radius: 6px;
padding: 10px;
}
.sub-title {
font-size: 14px;
font-weight: 600;
color: var(--color-text);
margin-bottom: 8px;
}
.no-transcript {
font-size: 12px;
color: var(--color-text-secondary);
}
.prompt-display-wrapper {
min-height: 200px;
max-height: 500px;
overflow-y: auto;
background: #0d0d0d;
border: 1px dashed var(--color-border);
border-radius: 6px;
padding: 12px;
margin-bottom: 8px;
}
.no-prompt {
padding: 16px;
text-align: center;
color: var(--color-text-secondary);
}
.right-actions {
margin-top: 8px;
}
.copy-btn {
display: inline-flex;
align-items: center;
gap: 4px;
color: var(--color-primary);
cursor: pointer;
}
.copy-btn:hover {
opacity: 0.8;
}
.no-analysis-tip {
padding: 40px 20px;
text-align: center;
}
.no-analysis-tip :deep(.ant-empty) {
margin: 0;
}
.no-analysis-tip :deep(.ant-empty-description) {
color: var(--color-text-secondary);
margin-bottom: 16px;
}
</style>

View File

@@ -0,0 +1,138 @@
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { UserPromptApi } from '@/api/userPrompt'
import { useUserStore } from '@/stores/user'
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
promptContent: {
type: String,
default: '',
},
})
const emit = defineEmits(['update:visible', 'success'])
const userStore = useUserStore()
const savingPrompt = ref(false)
const savePromptForm = ref({
name: '',
category: '',
content: '',
})
watch(() => props.visible, (newVal) => {
if (newVal) {
savePromptForm.value = {
name: '',
category: '',
content: props.promptContent,
}
}
})
async function handleSave() {
if (!savePromptForm.value.name.trim()) {
message.warning('请输入提示词名称')
return
}
if (!savePromptForm.value.content.trim()) {
message.warning('提示词内容不能为空')
return
}
const userId = Number(userStore.userId)
if (!userId) {
message.error('无法获取用户ID请先登录')
return
}
savingPrompt.value = true
try {
const payload = {
userId: userId,
name: savePromptForm.value.name.trim(),
content: savePromptForm.value.content.trim(),
category: savePromptForm.value.category.trim() || null,
isPublic: false,
sort: 0,
useCount: 0,
status: 1,
}
const response = await UserPromptApi.createUserPrompt(payload)
if (response && (response.code === 0 || response.code === 200)) {
message.success('提示词保存成功')
emit('update:visible', false)
emit('success')
// 重置表单
savePromptForm.value = {
name: '',
category: '',
content: '',
}
} else {
throw new Error(response?.msg || response?.message || '保存失败')
}
} catch (error) {
console.error('保存提示词失败:', error)
message.error(error?.message || '保存失败,请稍后重试')
} finally {
savingPrompt.value = false
}
}
function handleCancel() {
emit('update:visible', false)
}
</script>
<template>
<a-modal
:open="visible"
title="保存提示词"
:width="600"
:maskClosable="false"
@cancel="handleCancel">
<a-form :model="savePromptForm" layout="vertical">
<a-form-item label="提示词名称" required>
<a-input
v-model:value="savePromptForm.name"
placeholder="请输入提示词名称"
:maxlength="50"
show-count />
</a-form-item>
<a-form-item label="分类/标签">
<a-input
v-model:value="savePromptForm.category"
placeholder="可选:输入分类或标签"
:maxlength="20" />
</a-form-item>
<a-form-item label="提示词内容">
<a-textarea
v-model:value="savePromptForm.content"
:rows="8"
:readonly="true"
placeholder="提示词内容" />
</a-form-item>
</a-form>
<template #footer>
<a-space>
<a-button @click="handleCancel">取消</a-button>
<a-button
type="primary"
:loading="savingPrompt"
:disabled="!savePromptForm.name.trim()"
@click="handleSave">保存</a-button>
</a-space>
</template>
</a-modal>
</template>