feat: 实现 PinnedProject 组件与父组件的双向交互

添加 PinnedProject 组件引用和 pin-changed 事件处理
在 Dashboard 和 Dashboard-AI 中同步 pin 状态
暴露 loadPinnedBids 方法供父组件调用
This commit is contained in:
dmy
2026-01-13 21:16:23 +08:00
parent feb18c01bb
commit f050d38140
3 changed files with 72 additions and 3 deletions

View File

@@ -7,7 +7,7 @@
获取 AI 推荐
</el-button>
</div>
<PinnedProject />
<PinnedProject ref="pinnedProjectRef" @pin-changed="handlePinChanged" />
<el-row :gutter="20">
<el-col :span="24">
<el-card class="box-card" shadow="hover">
@@ -328,6 +328,18 @@ const getConfidenceType = (confidence: number) => {
return 'info'
}
// PinnedProject 组件引用
const pinnedProjectRef = ref<any>(null)
// 处理 PinnedProject 组件的 pin 状态改变事件
const handlePinChanged = async (title: string) => {
// 更新对应推荐项目的 pin 状态
const rec = aiRecommendations.value.find(r => r.title === title)
if (rec) {
rec.pin = false
}
}
// 切换 AI 推荐项目的 Pin 状态
const togglePin = async (item: AIRecommendation) => {
try {
@@ -335,6 +347,10 @@ const togglePin = async (item: AIRecommendation) => {
await axios.patch(`/api/bids/${encodeURIComponent(item.title)}/pin`, { pin: newPinStatus })
item.pin = newPinStatus
ElMessage.success(newPinStatus ? '已置顶' : '已取消置顶')
// 刷新 PinnedProject 组件的数据
if (pinnedProjectRef.value) {
pinnedProjectRef.value.loadPinnedBids()
}
} catch (error) {
ElMessage.error('操作失败')
}