This commit is contained in:
2026-03-11 00:42:46 +08:00
parent a125b5922f
commit a12cb5e75a
23 changed files with 1593 additions and 101 deletions

View File

@@ -139,3 +139,16 @@ export function removeFavorite(agentId) {
params: { agentId }
})
}
/**
* 获取收藏的智能体列表
* 直接从 getAgentList 结果中过滤 isFavorite 为 true 的项
*/
export async function getFavoriteList() {
const res = await getAgentList()
if (res.code === 0 && res.data) {
const favorites = res.data.filter(item => item.isFavorite)
return { code: 0, data: favorites }
}
return res
}

View File

@@ -0,0 +1,86 @@
/**
* Dify API
*/
import { fetchEventSource } from '@microsoft/fetch-event-source'
import tokenManager from '@gold/utils/token-manager'
import { API_BASE } from '@gold/config/api'
const BASE_URL = `${API_BASE.APP_TIK}`
/**
* 对标分析流式 API
* @param {Object} options - 请求配置
* @param {string} options.content - 合并后的文案内容
* @param {number} options.videoCount - 视频数量
* @param {AbortController} [options.ctrl] - 取消控制器
* @param {Function} options.onMessage - 消息回调
* @param {Function} [options.onError] - 错误回调
* @param {Function} [options.onComplete] - 完成回调
*/
export async function benchmarkAnalyzeStream(options) {
const {
content,
videoCount,
ctrl,
onMessage,
onError,
onComplete
} = options || {}
const token = tokenManager.getAccessToken()
let fullText = ''
let conversationId = ''
return fetchEventSource(`${BASE_URL}/dify/benchmark/analyze`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
'tenant-id': import.meta.env?.VITE_TENANT_ID
},
openWhenHidden: true,
body: JSON.stringify({
content,
videoCount
}),
onmessage: (event) => {
if (typeof onMessage === 'function') {
try {
const data = JSON.parse(event.data)
// 解析 CommonResult 包装
const result = data.code === 0 ? data.data : data
// 处理消息内容
if (result.event === 'message' || result.event === 'agent_message') {
fullText += result.content || ''
onMessage(fullText, result.content)
}
// 处理完成事件
else if (result.event === 'done') {
conversationId = result.conversationId
}
// 处理错误事件
else if (result.event === 'error') {
if (typeof onError === 'function') {
onError(new Error(result.content || '分析失败'))
}
}
} catch (e) {
console.error('解析 SSE 数据失败:', e)
}
}
},
onerror: (err) => {
if (typeof onError === 'function') {
onError(err)
}
throw err // 不重试
},
onclose: () => {
if (typeof onComplete === 'function') {
onComplete(fullText, conversationId)
}
},
signal: ctrl ? ctrl.signal : undefined
})
}

View File

@@ -10,10 +10,11 @@ const BASE_URL = `${API_BASE.APP_TIK}`
/**
* 流式文案改写SSE
* @param {Object} options - 请求配置
* @param {number} options.agentId - 智能体ID
* @param {number} [options.agentId] - 智能体ID(使用用户风格时可不传)
* @param {string} options.userText - 用户输入文案
* @param {number} [options.level] - 改写级别/强度
* @param {string} [options.modelType] - 模型类型forecast_standard/forecast_pro
* @param {string} [options.customSystemPrompt] - 自定义系统提示词(使用用户风格时传入)
* @param {AbortController} [options.ctrl] - 取消控制器
* @param {Function} options.onMessage - 消息回调
* @param {Function} [options.onError] - 错误回调
@@ -25,6 +26,7 @@ export async function rewriteStream(options) {
userText,
level = 50,
modelType = 'forecast_standard',
customSystemPrompt,
ctrl,
onMessage,
onError,
@@ -45,7 +47,8 @@ export async function rewriteStream(options) {
agentId,
userText,
level,
modelType
modelType,
customSystemPrompt
}),
onmessage: (event) => {
if (typeof onMessage === 'function') {

View File

@@ -40,6 +40,14 @@ export const UserPromptApi = {
return await http.get(`${SERVER_BASE_AI}/user-prompt/page`, { params })
},
/**
* 获取用户提示词列表(简化版,不分页)
* @returns {Promise} 响应数据
*/
getUserPromptList: async () => {
return await http.get(`${SERVER_BASE_AI}/user-prompt/list`)
},
/**
* 获取单个用户提示词
* @param {Number} id - 提示词ID

View File

@@ -0,0 +1,306 @@
<template>
<a-modal
:open="visible"
title="我创建的"
:width="700"
:footer="null"
@cancel="handleClose"
>
<div class="favorites-content">
<!-- 操作栏 -->
<div class="action-bar">
<a-button type="primary" @click="handleCreate">
<template #icon><PlusOutlined /></template>
新建风格
</a-button>
<a-button @click="loadList" :loading="loading">
<template #icon><ReloadOutlined /></template>
刷新
</a-button>
</div>
<!-- 列表 -->
<div class="favorites-list" v-if="!loading && list.length > 0">
<div
v-for="item in list"
:key="item.id"
class="favorite-card"
>
<div class="card-header">
<span class="card-name">{{ item.name }}</span>
<div class="card-actions">
<a-button type="link" size="small" @click="handleEdit(item)">编辑</a-button>
<a-popconfirm
title="确定删除此风格?"
@confirm="handleDelete(item.id)"
>
<a-button type="link" size="small" danger>删除</a-button>
</a-popconfirm>
</div>
</div>
<div class="card-content">{{ item.content }}</div>
<div class="card-footer">
<span class="card-category" v-if="item.category">{{ item.category }}</span>
<span class="card-use-count">使用 {{ item.useCount || 0 }} </span>
</div>
</div>
</div>
<!-- 空状态 -->
<div class="empty-state" v-if="!loading && list.length === 0">
<p>暂无收藏的风格</p>
<a-button type="primary" @click="handleCreate">立即创建</a-button>
</div>
<!-- 加载状态 -->
<div class="loading-state" v-if="loading">
<a-spin />
<span>加载中...</span>
</div>
</div>
<!-- 编辑弹窗 -->
<a-modal
v-model:open="editVisible"
:title="editingItem ? '编辑风格' : '新建风格'"
:width="500"
@ok="handleSave"
:confirmLoading="saving"
>
<a-form layout="vertical">
<a-form-item label="风格名称" required>
<a-input v-model:value="editForm.name" placeholder="请输入风格名称" />
</a-form-item>
<a-form-item label="风格内容" required>
<a-textarea
v-model:value="editForm.content"
:rows="6"
placeholder="请输入风格提示词内容"
/>
</a-form-item>
<a-form-item label="分类">
<a-input v-model:value="editForm.category" placeholder="可选,用于分类管理" />
</a-form-item>
</a-form>
</a-modal>
</a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { PlusOutlined, ReloadOutlined } from '@ant-design/icons-vue'
import { UserPromptApi } from '@/api/userPrompt'
const props = defineProps({
visible: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:visible', 'refresh'])
const loading = ref(false)
const list = ref([])
const editVisible = ref(false)
const editingItem = ref(null)
const saving = ref(false)
const editForm = ref({
name: '',
content: '',
category: ''
})
// 加载列表
async function loadList() {
loading.value = true
try {
const res = await UserPromptApi.getUserPromptList()
if (res.code === 0) {
list.value = res.data || []
}
} catch (error) {
console.error('加载列表失败:', error)
} finally {
loading.value = false
}
}
// 创建新风格
function handleCreate() {
editingItem.value = null
editForm.value = {
name: '',
content: '',
category: ''
}
editVisible.value = true
}
// 编辑风格
function handleEdit(item) {
editingItem.value = item
editForm.value = {
name: item.name,
content: item.content,
category: item.category || ''
}
editVisible.value = true
}
// 保存风格
async function handleSave() {
if (!editForm.value.name.trim()) {
message.warning('请输入风格名称')
return
}
if (!editForm.value.content.trim()) {
message.warning('请输入风格内容')
return
}
saving.value = true
try {
const data = {
name: editForm.value.name.trim(),
content: editForm.value.content.trim(),
category: editForm.value.category.trim() || null,
status: 1
}
if (editingItem.value) {
// 更新
await UserPromptApi.updateUserPrompt({
id: editingItem.value.id,
...data
})
message.success('更新成功')
} else {
// 创建
await UserPromptApi.createUserPrompt(data)
message.success('创建成功')
}
editVisible.value = false
loadList()
emit('refresh')
} catch (error) {
console.error('保存失败:', error)
message.error('保存失败')
} finally {
saving.value = false
}
}
// 删除风格
async function handleDelete(id) {
try {
await UserPromptApi.deleteUserPrompt(id)
message.success('删除成功')
loadList()
emit('refresh')
} catch (error) {
console.error('删除失败:', error)
message.error('删除失败')
}
}
// 关闭弹窗
function handleClose() {
emit('update:visible', false)
}
// 监听 visible 变化
watch(() => props.visible, (newVal) => {
if (newVal) {
loadList()
}
})
</script>
<style scoped lang="less">
.favorites-content {
min-height: 300px;
}
.action-bar {
display: flex;
gap: 12px;
margin-bottom: 16px;
}
.favorites-list {
display: grid;
gap: 12px;
}
.favorite-card {
padding: 16px;
border: 1px solid var(--color-border);
border-radius: 8px;
background: var(--color-surface);
transition: all 0.2s;
&:hover {
border-color: var(--color-primary);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.card-name {
font-weight: 600;
font-size: 15px;
color: var(--color-text);
}
.card-actions {
display: flex;
gap: 4px;
}
.card-content {
color: var(--color-text-secondary);
font-size: 13px;
line-height: 1.6;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
margin-bottom: 12px;
}
.card-footer {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
color: var(--color-text-tertiary);
}
.card-category {
padding: 2px 8px;
background: rgba(24, 144, 255, 0.1);
color: #1890ff;
border-radius: 10px;
}
.empty-state,
.loading-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 20px;
color: var(--color-text-secondary);
gap: 16px;
}
</style>

View File

@@ -0,0 +1,283 @@
<template>
<a-select
v-model:value="selectedId"
:placeholder="placeholder"
:loading="loading"
style="width: 100%"
show-search
:filter-option="filterOption"
@change="handleChange"
>
<!-- 用户风格分组 -->
<a-select-opt-group v-if="userPrompts.length > 0">
<template #label>
<span class="group-label">用户风格</span>
</template>
<a-select-option
v-for="item in userPrompts"
:key="`prompt-${item.id}`"
:value="`prompt-${item.id}`"
>
<div class="option-content">
<span class="option-name">{{ item.name }}</span>
<span class="option-tag style-tag">风格</span>
</div>
</a-select-option>
</a-select-opt-group>
<!-- 收藏的智能体分组 -->
<a-select-opt-group v-if="favoriteAgents.length > 0">
<template #label>
<span class="group-label">收藏的智能体</span>
</template>
<a-select-option
v-for="item in favoriteAgents"
:key="`agent-${item.id}`"
:value="`agent-${item.id}`"
>
<div class="option-content">
<img v-if="item.avatar" :src="item.avatar" class="option-avatar" />
<span class="option-name">{{ item.name }}</span>
<span class="option-tag agent-tag">{{ item.categoryName || '智能体' }}</span>
</div>
</a-select-option>
</a-select-opt-group>
<!-- 空状态 -->
<template v-if="!loading && userPrompts.length === 0 && favoriteAgents.length === 0">
<a-select-option disabled value="__empty__">
<span class="empty-text">暂无可选项</span>
</a-select-option>
</template>
</a-select>
</template>
<script setup>
import { ref, computed, watch, onMounted } from 'vue'
import { usePromptStore } from '@/stores/prompt'
import { getAgentList } from '@/api/agent'
import { getJSON, setJSON } from '@/utils/storage'
const props = defineProps({
modelValue: {
type: [String, Number],
default: null
},
placeholder: {
type: String,
default: '选择文案风格'
},
storageKey: {
type: String,
default: 'style_selector'
}
})
const emit = defineEmits(['update:modelValue', 'change'])
const promptStore = usePromptStore()
const loading = ref(false)
const selectedId = ref(null)
const agentList = ref([])
// 用户风格列表
const userPrompts = computed(() => promptStore.promptList || [])
// 收藏的智能体列表
const favoriteAgents = computed(() => {
return agentList.value.filter(agent => agent.isFavorite)
})
// 过滤选项
function filterOption(input, option) {
const key = option.value
const name = option.label || ''
// 根据 key 查找对应的项目名称
if (key.startsWith('prompt-')) {
const id = parseInt(key.replace('prompt-', ''))
const prompt = userPrompts.value.find(p => p.id === id)
return prompt?.name?.toLowerCase().includes(input.toLowerCase())
} else if (key.startsWith('agent-')) {
const id = parseInt(key.replace('agent-', ''))
const agent = agentList.value.find(a => a.id === id)
return agent?.name?.toLowerCase().includes(input.toLowerCase())
}
return false
}
// 处理选择变化
function handleChange(value) {
if (!value || value === '__empty__') {
emit('update:modelValue', null)
emit('change', null)
return
}
const [type, idStr] = value.split('-')
const id = parseInt(idStr)
let item = null
if (type === 'prompt') {
item = userPrompts.value.find(p => p.id === id)
emit('change', { id, type: 'prompt', item })
} else if (type === 'agent') {
item = agentList.value.find(a => a.id === id)
emit('change', { id, type: 'agent', item })
}
emit('update:modelValue', id)
// 保存选中状态到本地
saveSelectedValue(value)
}
// 加载智能体列表
async function loadAgentList() {
try {
const res = await getAgentList()
if (res.code === 0 && res.data) {
agentList.value = res.data.map(item => ({
id: item.id,
agentId: item.agentId,
name: item.agentName,
description: item.description,
systemPrompt: item.systemPrompt,
avatar: item.icon,
categoryName: item.categoryName || '其他',
isFavorite: item.isFavorite || false
}))
}
} catch (error) {
console.error('加载智能体列表失败:', error)
}
}
// 加载用户风格列表
async function loadUserPrompts() {
try {
await promptStore.loadPromptList()
} catch (error) {
console.error('加载用户风格列表失败:', error)
}
}
// 保存选中状态
async function saveSelectedValue(value) {
try {
await setJSON(`${props.storageKey}_selected`, value)
} catch (error) {
console.error('保存选择状态失败:', error)
}
}
// 恢复选中状态
async function restoreSelectedValue() {
try {
const savedValue = await getJSON(`${props.storageKey}_selected`, null)
if (savedValue) {
// 验证保存的值是否有效
const [type, idStr] = savedValue.split('-')
const id = parseInt(idStr)
if (type === 'prompt') {
const exists = userPrompts.value.some(p => p.id === id)
if (exists) {
selectedId.value = savedValue
emit('update:modelValue', id)
const item = userPrompts.value.find(p => p.id === id)
emit('change', { id, type: 'prompt', item })
}
} else if (type === 'agent') {
const exists = agentList.value.some(a => a.id === id)
if (exists) {
selectedId.value = savedValue
emit('update:modelValue', id)
const item = agentList.value.find(a => a.id === id)
emit('change', { id, type: 'agent', item })
}
}
}
} catch (error) {
console.error('恢复选择状态失败:', error)
}
}
// 初始化加载
async function init() {
loading.value = true
try {
await Promise.all([loadUserPrompts(), loadAgentList()])
await restoreSelectedValue()
} finally {
loading.value = false
}
}
// 监听 modelValue 变化
watch(() => props.modelValue, (newValue) => {
if (newValue === null) {
selectedId.value = null
}
})
onMounted(() => {
init()
})
// 暴露刷新方法
defineExpose({
refresh: init
})
</script>
<style scoped lang="less">
.group-label {
font-weight: 600;
color: var(--color-text);
font-size: 13px;
}
.option-content {
display: flex;
align-items: center;
gap: 8px;
}
.option-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
}
.option-name {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.option-tag {
font-size: 11px;
padding: 1px 6px;
border-radius: 10px;
flex-shrink: 0;
}
.style-tag {
background: rgba(24, 144, 255, 0.1);
color: #1890ff;
}
.agent-tag {
background: rgba(82, 196, 26, 0.1);
color: #52c41a;
}
.empty-text {
color: var(--color-text-secondary);
font-style: italic;
}
</style>

View File

@@ -0,0 +1,303 @@
<script setup>
import { ref, computed, watch } from 'vue'
import { message } from 'ant-design-vue'
import {
StarFilled,
CloseOutlined,
EditOutlined,
DeleteOutlined,
PlusOutlined
} from '@ant-design/icons-vue'
import { UserPromptApi } from '@/api/userPrompt'
import SavePromptModal from '@/views/content-style/components/SavePromptModal.vue'
// Props
const props = defineProps({
visible: {
type: Boolean,
default: false
}
})
// Emits
const emit = defineEmits(['update:visible', 'refresh'])
// State
const loading = ref(false)
const promptList = ref([])
const searchKeyword = ref('')
const showSaveModal = ref(false)
const editingPrompt = ref(null)
// Computed
const filteredList = computed(() => {
if (!searchKeyword.value.trim()) return promptList.value
const keyword = searchKeyword.value.trim().toLowerCase()
return promptList.value.filter(item =>
item.name.toLowerCase().includes(keyword) ||
(item.content && item.content.toLowerCase().includes(keyword))
)
})
// 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,
content: item.content,
category: item.category,
useCount: item.useCount || 0
}))
}
} catch (error) {
console.error('加载风格列表失败:', error)
message.error('加载风格列表失败')
} finally {
loading.value = false
}
}
function handleClose() {
emit('update:visible', false)
}
function handleCreate() {
editingPrompt.value = null
showSaveModal.value = true
}
function handleEdit(item) {
editingPrompt.value = { ...item }
showSaveModal.value = true
}
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)
}
message.success('删除成功')
emit('refresh')
} catch (error) {
console.error('删除失败:', error)
message.error('删除失败')
}
}
function handleSaveSuccess() {
showSaveModal.value = false
loadList()
emit('refresh')
}
</script>
<template>
<a-modal
:open="visible"
title="我创建的"
:width="700"
:footer="null"
@cancel="handleClose"
>
<!-- 操作栏 -->
<div class="action-bar">
<a-button type="primary" @click="handleCreate">
<template #icon><PlusOutlined /></template>
新建风格
</a-button>
<a-button @click="loadList" :loading="loading">
刷新
</a-button>
</div>
<!-- 搜索框 -->
<div class="search-bar">
<a-input
v-model:value="searchKeyword"
placeholder="搜索风格..."
allow-clear
/>
</div>
<!-- 列表 -->
<div class="prompt-list" v-if="!loading && filteredList.length > 0">
<div
v-for="item in filteredList"
:key="item.id"
class="prompt-card"
>
<div class="card-header">
<span class="card-name">{{ item.name }}</span>
<div class="card-actions">
<a-button type="link" size="small" @click="handleEdit(item)">
<EditOutlined /> 编辑
</a-button>
<a-popconfirm
title="确定删除此风格?"
@confirm="handleDelete(item.id)"
>
<a-button type="link" size="small" danger>
<DeleteOutlined /> 删除
</a-button>
</a-popconfirm>
</div>
</div>
<div class="card-content">{{ item.content }}</div>
<div class="card-footer">
<span class="card-category" v-if="item.category">{{ item.category }}</span>
<span class="card-use-count">使用 {{ item.useCount || 0 }} </span>
</div>
</div>
</div>
<!-- 空状态 -->
<div class="empty-state" v-else-if="!loading">
<StarFilled class="empty-icon" />
<p class="empty-title">暂无收藏的风格</p>
<p class="empty-desc">点击"新建风格"创建您的第一个风格</p>
</div>
<!-- 加载状态 -->
<div class="loading-state" v-if="loading">
<a-spin />
</div>
<!-- 保存弹窗 -->
<SavePromptModal
v-model:visible="showSaveModal"
:prompt="editingPrompt"
@success="handleSaveSuccess"
/>
</a-modal>
</template>
<style scoped lang="less">
.action-bar {
display: flex;
gap: 12px;
margin-bottom: 16px;
}
.search-bar {
margin-bottom: 16px;
}
.prompt-list {
display: flex;
flex-direction: column;
gap: 12px;
max-height: 400px;
overflow-y: auto;
}
.prompt-card {
padding: 16px;
border: 1px solid var(--color-border);
border-radius: 8px;
background: var(--color-surface);
transition: all 0.2s ease;
&:hover {
border-color: var(--color-primary);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.card-name {
font-weight: 600;
font-size: 14px;
color: var(--color-text);
}
.card-actions {
display: flex;
gap: 8px;
}
.card-content {
font-size: 13px;
color: var(--color-text-secondary);
line-height: 1.5;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
margin-bottom: 8px;
}
.card-footer {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
}
.card-category {
padding: 2px 8px;
background: rgba(24, 144, 255, 0.1);
color: #1890ff;
border-radius: 10px;
}
.card-use-count {
color: var(--color-text-tertiary);
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 48px 24px;
text-align: center;
}
.empty-icon {
font-size: 48px;
color: #f59e0b;
margin-bottom: 16px;
opacity: 0.5;
}
.empty-title {
font-size: 15px;
font-weight: 500;
color: var(--color-text);
margin: 0 0 8px 0;
}
.empty-desc {
font-size: 13px;
color: var(--color-text-secondary);
margin: 0;
}
.loading-state {
display: flex;
align-items: center;
justify-content: center;
padding: 48px;
}
</style>

View File

@@ -26,6 +26,12 @@
</button>
</transition>
</div>
<!-- 我创建的 -->
<button class="favorites-btn" @click="showFavoritesModal = true">
<StarFilled class="favorites-btn-icon" />
<span class="favorites-btn-text">我创建的</span>
</button>
</div>
<!-- 精简分类筛选 -->
@@ -183,6 +189,12 @@
:agent-id="historyAgentId"
@close="closeHistoryPanel"
/>
<MyFavoritesModal
v-model:visible="showFavoritesModal"
@chat="handleChat"
@remove="handleFavoriteRemoved"
/>
</FullWidthLayout>
</template>
@@ -202,6 +214,7 @@ import { message } from 'ant-design-vue'
import FullWidthLayout from '@/layouts/components/FullWidthLayout.vue'
import ChatDrawer from '@/components/agents/ChatDrawer.vue'
import HistoryPanel from '@/components/agents/HistoryPanel.vue'
import MyFavoritesModal from '@/components/agents/MyFavoritesModal.vue'
import { getAgentList, addFavorite, removeFavorite } from '@/api/agent'
// 状态管理
@@ -216,6 +229,7 @@ const showCategoryPanel = ref(false)
const panelTop = ref(0)
const historyPanelVisible = ref(false)
const historyAgentId = ref(null)
const showFavoritesModal = ref(false)
// 面板样式
const panelStyle = computed(() => ({
@@ -385,6 +399,15 @@ const handleFavorite = async (agent) => {
}
}
// 收藏被移除的回调
const handleFavoriteRemoved = (agent) => {
// 同步更新列表中的收藏状态
const target = agentList.value.find(a => a.id === agent.id)
if (target) {
target.isFavorite = false
}
}
// 初始化
onMounted(() => {
fetchAgentList()
@@ -459,14 +482,18 @@ onMounted(() => {
// 搜索区域 - 核心焦点
// ============================================
.search-hero {
max-width: 480px;
max-width: 560px;
margin: 0 auto 28px;
display: flex;
align-items: center;
gap: 12px;
}
.search-input-group {
position: relative;
display: flex;
align-items: center;
flex: 1;
}
.search-icon {
@@ -532,6 +559,46 @@ onMounted(() => {
}
}
// ============================================
// 收藏按钮
// ============================================
.favorites-btn {
flex-shrink: 0;
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0 16px;
height: 52px;
border: 1px solid var(--color-gray-300);
border-radius: var(--radius-lg);
background: var(--color-bg-card);
cursor: pointer;
transition: all var(--duration-fast);
box-shadow: var(--shadow-sm);
&:hover {
border-color: #f59e0b;
background: #fffbeb;
box-shadow: var(--shadow-md);
}
&:active {
transform: scale(0.98);
}
}
.favorites-btn-icon {
font-size: 18px;
color: #f59e0b;
}
.favorites-btn-text {
font-size: 14px;
font-weight: 500;
color: var(--color-gray-700);
white-space: nowrap;
}
// ============================================
// 分类筛选 - 精简胶囊
// ============================================

View File

@@ -429,8 +429,6 @@ async function handleSmsLogin() {
</script>
<style scoped lang="less">
/* ========== 导入字体 ========== */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=DM+Sans:wght@400;500;600&display=swap');
/* ========== CSS变量 ========== */
@primary-gold: #D4A853;

View File

@@ -2,8 +2,7 @@
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import ChatMessageRendererV2 from '@/components/ChatMessageRendererV2.vue'
import { ChatMessageApi } from '@/api/chat'
import { streamChat } from '@/utils/streamChat'
import { benchmarkAnalyzeStream } from '@/api/dify'
const props = withDefaults(defineProps<{
visible: boolean
@@ -52,35 +51,29 @@ async function generateBatchPrompt() {
if (!props.mergedText || hasGenerated.value) return
hasGenerated.value = true
const ctrl = new AbortController()
try {
batchPromptGenerating.value = true
const conversationId = await createConversation()
const aiContent = await streamChat({
conversationId,
await benchmarkAnalyzeStream({
content: props.mergedText,
onUpdate: (fullText: string) => {
videoCount: props.textCount,
ctrl,
onMessage: (fullText: string) => {
batchPrompt.value = fullText
},
enableTypewriter: true,
typewriterSpeed: 10,
typewriterBatchSize: 2,
onComplete: () => {},
onError: (error: Error) => {
console.error('流式聊天错误:', error)
console.error('对标分析错误:', error)
message.error('AI生成失败请稍后重试')
},
enableContext: false,
enableWebSearch: false,
timeout: 180000,
attachmentUrls: []
onComplete: (fullText: string) => {
if (fullText && fullText !== batchPrompt.value) {
batchPrompt.value = fullText
}
message.success(`批量分析完成:已基于 ${props.textCount} 个视频的文案生成综合提示词`)
}
})
if (aiContent && aiContent !== batchPrompt.value) {
batchPrompt.value = aiContent
}
message.success(`批量分析完成:已基于 ${props.textCount} 个视频的文案生成综合提示词`)
} catch (error) {
console.error('AI生成失败:', error)
message.error('AI生成失败请稍后重试')
@@ -90,21 +83,6 @@ async function generateBatchPrompt() {
}
}
async function createConversation() {
const createPayload = { roleId: 20 }
const conversationResp = await ChatMessageApi.createChatConversationMy(createPayload)
const conversationId = conversationResp?.data
? (typeof conversationResp.data === 'object' ? conversationResp.data.id : conversationResp.data)
: null
if (!conversationId) {
throw new Error('创建对话失败:未获取到 conversationId')
}
return conversationId
}
function handleClose() {
emit('update:visible', false)
}

View File

@@ -195,7 +195,6 @@
<!-- 音色选择 -->
<div class="input-section">
<label class="input-label">选择音色</label>
<VoiceSelector
:synth-text="store.text"
:speech-rate="store.speechRate"

View File

@@ -4,11 +4,11 @@ import { message } from 'ant-design-vue'
import TikhubService, { InterfaceType, MethodType, ParamType } from '@/api/tikhub'
import { rewriteStream } from '@/api/forecast'
import { getAgentList } from '@/api/agent'
import { useUserStore } from '@/stores/user'
import { usePointsConfigStore } from '@/stores/pointsConfig'
import { getVoiceText } from '@/hooks/web/useVoiceText'
import { copyToClipboard } from '@/utils/clipboard'
import StyleSelector from '@/components/StyleSelector.vue'
defineOptions({ name: 'ForecastView' })
@@ -47,22 +47,12 @@ const topicDetails = reactive({
// 智能体列表
const agentList = ref([])
const loadingAgents = ref(false)
const agentSearchKeyword = ref('')
// 当前选中的智能体
const selectedAgent = ref(null)
// 过滤后的智能体列表
const filteredAgentList = computed(() => {
if (!agentSearchKeyword.value.trim()) {
return agentList.value
}
const keyword = agentSearchKeyword.value.trim().toLowerCase()
return agentList.value.filter(agent =>
agent.name.toLowerCase().includes(keyword) ||
(agent.description && agent.description.toLowerCase().includes(keyword))
)
})
// 当前选中的风格类型
const selectedStyleType = ref('agent')
// 工具函数
function formatNumber(num) {
@@ -99,7 +89,7 @@ async function copyContent() {
}
}
// 加载智能体列表
// 加载智能体列表(保留用于其他逻辑)
async function loadAgentList() {
loadingAgents.value = true
try {
@@ -112,13 +102,9 @@ async function loadAgentList() {
description: item.description,
systemPrompt: item.systemPrompt,
avatar: item.icon,
categoryName: item.categoryName || '其他'
categoryName: item.categoryName || '其他',
isFavorite: item.isFavorite || false
}))
// 默认选中第一个
if (agentList.value.length > 0 && !topicDetails.selectedAgentId) {
topicDetails.selectedAgentId = agentList.value[0].id
selectedAgent.value = agentList.value[0]
}
}
} catch (error) {
console.error('加载智能体列表失败:', error)
@@ -127,12 +113,28 @@ async function loadAgentList() {
}
}
// 处理智能体选择
function handleAgentChange(agentId) {
const agent = agentList.value.find(a => a.id === agentId)
if (agent) {
selectedAgent.value = agent
topicDetails.selectedAgentId = agentId
// 处理风格选择变化
function handleStyleChange(data) {
if (!data) {
selectedAgent.value = null
selectedStyleType.value = null
return
}
const { id, type, item } = data
selectedStyleType.value = type
topicDetails.selectedAgentId = id
if (type === 'agent') {
// 选择的是智能体
selectedAgent.value = item
} else if (type === 'prompt') {
// 选择的是用户风格
selectedAgent.value = {
id: item.id,
name: item.name,
systemPrompt: item.content
}
}
}
@@ -206,8 +208,8 @@ async function handleGenerate() {
}
}, 180000)
rewriteStream({
agentId: selectedAgent.value.id,
// 构建请求参数
const requestOptions = {
userText: topicDetails.copywriting.trim(),
level: topicDetails.level,
modelType: topicDetails.modelType,
@@ -245,7 +247,18 @@ async function handleGenerate() {
resolve()
}
}
})
}
// 根据风格类型设置参数
if (selectedStyleType.value === 'prompt') {
// 使用用户风格
requestOptions.customSystemPrompt = selectedAgent.value.systemPrompt
} else {
// 使用智能体
requestOptions.agentId = selectedAgent.value.id
}
rewriteStream(requestOptions)
})
generatedContent.value = fullText.trim()
@@ -369,6 +382,7 @@ async function handleSearch() {
// 初始化
onMounted(() => {
// 加载智能体列表用于后续逻辑
loadAgentList()
pointsConfigStore.loadConfig()
})
@@ -537,25 +551,12 @@ onMounted(() => {
<!-- 风格选择 -->
<div class="form-block">
<label>文案风格</label>
<a-select
v-model:value="topicDetails.selectedAgentId"
<StyleSelector
v-model="topicDetails.selectedAgentId"
placeholder="选择风格"
style="width: 100%"
:loading="loadingAgents"
show-search
:filter-option="false"
@change="handleAgentChange"
@search="agentSearchKeyword = $event"
>
<a-select-option
v-for="agent in filteredAgentList"
:key="agent.id"
:value="agent.id"
>
<span>{{ agent.name }}</span>
<span class="agent-category">{{ agent.categoryName }}</span>
</a-select-option>
</a-select>
storage-key="forecast_style"
@change="handleStyleChange"
/>
</div>
<!-- 模式 & 幅度 -->