547 lines
16 KiB
Vue
547 lines
16 KiB
Vue
/**
|
|
* features/workspace/pages/HomePage.vue
|
|
* 用途:AI 工作台的应用管理和最近更新。收藏应用、快捷问题、嵌入 Agent、公告和应用列表。
|
|
* 依赖:workspace.context、AnnouncementCardCarousel、element-plus、element-theme.css。
|
|
* 逻辑:路由按 workspaceFocus 决定展示哪些分区。分区顺序和折叠仍由工作台状态管理。
|
|
* 应用卡片保持原有点击进入对话。快捷问题的新增和编辑用 Element 表单。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { inject } from 'vue';
|
|
import {
|
|
ArrowDown,
|
|
ArrowUp,
|
|
Bell,
|
|
Delete,
|
|
Edit,
|
|
Grid,
|
|
Monitor,
|
|
Plus,
|
|
Rank,
|
|
Star,
|
|
StarFilled,
|
|
TopRight,
|
|
} from '@element-plus/icons-vue';
|
|
import {
|
|
ElButton,
|
|
ElCard,
|
|
ElEmpty,
|
|
ElForm,
|
|
ElFormItem,
|
|
ElIcon,
|
|
ElInput,
|
|
ElOption,
|
|
ElRadioButton,
|
|
ElRadioGroup,
|
|
ElSelect,
|
|
ElTag,
|
|
} from 'element-plus';
|
|
import 'element-plus/dist/index.css';
|
|
import 'element-plus/theme-chalk/dark/css-vars.css';
|
|
import '@/shared/styles/element-theme.css';
|
|
import AnnouncementCardCarousel from '@/shared/components/AnnouncementCardCarousel.vue';
|
|
import { WORKSPACE_KEY } from '../composables/workspace.context';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
const { t } = useI18n();
|
|
const ws = inject(WORKSPACE_KEY)! as any;
|
|
|
|
/**
|
|
* 应用分类单选。「全部」在 Element 里用空字符串,写回状态时仍是 null。
|
|
* @param value - 被选中的分类
|
|
*/
|
|
function onCategoryChange(value: string | number | boolean | undefined): void {
|
|
ws.selectedCategory = value ? String(value) : null;
|
|
}
|
|
|
|
/**
|
|
* 快捷问题的目标应用。未选择时下拉值为 undefined,保存仍写 null。
|
|
* @param value - 应用主键
|
|
*/
|
|
function onQuestionAgentChange(value: string | number | boolean | undefined): void {
|
|
ws.newQuestion.agent_id = value == null || value === '' ? null : Number(value);
|
|
}
|
|
|
|
/**
|
|
* 分区标题图标。公告、收藏、嵌入和其余列表各用一个 Element 图标。
|
|
* @param sectionId - 分区 id
|
|
* @returns 图标组件
|
|
*/
|
|
function sectionIcon(sectionId: string) {
|
|
if (sectionId === 'announcements') return Bell;
|
|
if (sectionId === 'favorites') return StarFilled;
|
|
if (sectionId === 'embedded') return Monitor;
|
|
return Grid;
|
|
}
|
|
|
|
/**
|
|
* 公告和收藏没有内容时,把提示放在标题旁边,避免空状态插图把分区撑高。
|
|
* @param section - 当前分区
|
|
* @returns 提示文案;有内容或已折叠时为空
|
|
*/
|
|
function sectionEmptyHint(section: { id: string; collapsed?: boolean }): string {
|
|
if (section.collapsed) return '';
|
|
if (section.id === 'announcements' && ws.announcements.length === 0) return t('workspace.announcements.noData');
|
|
if (section.id === 'favorites' && ws.favoriteAgents.length === 0) return t('workspace.noFavorites');
|
|
return '';
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="ws.wecomEntryHint" class="workspace-hint">
|
|
{{ ws.wecomEntryHint }}
|
|
</div>
|
|
|
|
<ElCard
|
|
v-for="(section, index) in ws.layoutSections"
|
|
:id="`workspace-section-${section.id}`"
|
|
:key="section.id"
|
|
shadow="never"
|
|
class="workspace-section"
|
|
:class="{
|
|
'workspace-section--dragging': ws.draggedSectionIndex === index,
|
|
'workspace-section--compact': sectionEmptyHint(section),
|
|
}"
|
|
draggable="true"
|
|
@dragstart="ws.onDragStart(index)"
|
|
@dragover="ws.onDragOver"
|
|
@drop="ws.onDrop(index)"
|
|
>
|
|
<div
|
|
class="workspace-section__head"
|
|
:class="{ 'workspace-section__head--compact': sectionEmptyHint(section) }"
|
|
>
|
|
<div class="workspace-section__lead">
|
|
<ElButton text class="workspace-section__title" @click="ws.toggleSectionCollapse(section)">
|
|
<ElIcon class="workspace-section__icon"><component :is="sectionIcon(section.id)" /></ElIcon>
|
|
<span class="section-title">{{ t(ws.getSectionTitleKey(section.id)) }}</span>
|
|
<ElIcon><component :is="section.collapsed ? ArrowDown : ArrowUp" /></ElIcon>
|
|
</ElButton>
|
|
<span v-if="sectionEmptyHint(section)" class="workspace-empty">{{ sectionEmptyHint(section) }}</span>
|
|
</div>
|
|
<ElButton
|
|
v-if="section.id === 'quick_questions' && !ws.isAddingQuestion && !section.collapsed"
|
|
link
|
|
type="primary"
|
|
:icon="Plus"
|
|
@click="ws.openAddQuestionForm"
|
|
>
|
|
{{ t('workspace.quickQuestions.add') }}
|
|
</ElButton>
|
|
<ElIcon class="workspace-section__grip">
|
|
<Rank />
|
|
</ElIcon>
|
|
</div>
|
|
|
|
<div v-show="!section.collapsed">
|
|
<div v-if="section.id === 'announcements' && ws.announcements.length > 0" class="workspace-announcements">
|
|
<AnnouncementCardCarousel
|
|
:announcements="ws.announcements"
|
|
variant="workspace"
|
|
:auto-play="ws.announcements.length > 1"
|
|
:auto-play-interval="8000"
|
|
@select="ws.openAnnouncement"
|
|
/>
|
|
</div>
|
|
|
|
<div v-if="section.id === 'favorites' && ws.favoriteAgents.length > 0" class="workspace-card-grid">
|
|
<article
|
|
v-for="agent in ws.favoriteAgents"
|
|
:key="agent.id"
|
|
class="workspace-app-card"
|
|
@click="ws.navigateToChat(agent.id)"
|
|
>
|
|
<div class="workspace-app-card__icon">
|
|
<img v-if="agent.icon_url" :src="agent.icon_url" alt="" />
|
|
<ElIcon v-else><Monitor /></ElIcon>
|
|
</div>
|
|
<h3 class="workspace-app-card__name">{{ agent.name }}</h3>
|
|
<p class="workspace-app-card__desc">{{ agent.description }}</p>
|
|
<ElButton
|
|
class="workspace-app-card__star"
|
|
link
|
|
:icon="StarFilled"
|
|
:title="t('workspace.favorites')"
|
|
@click.stop="ws.toggleFavorite(agent.id)"
|
|
/>
|
|
</article>
|
|
</div>
|
|
|
|
<div v-if="section.id === 'quick_questions'">
|
|
<ElCard v-if="ws.isAddingQuestion" shadow="never" class="workspace-question-form">
|
|
<h3 class="section-title">
|
|
{{ ws.editingQuestionId ? t('workspace.quickQuestions.edit') : t('workspace.quickQuestions.addNew') }}
|
|
</h3>
|
|
<ElForm label-position="top">
|
|
<div class="workspace-question-form__grid">
|
|
<ElFormItem :label="t('workspace.quickQuestions.fields.title')">
|
|
<ElInput v-model="ws.newQuestion.title" :placeholder="t('workspace.quickQuestions.fields.titlePlaceholder')" />
|
|
</ElFormItem>
|
|
<ElFormItem :label="t('workspace.quickQuestions.fields.targetAgent')">
|
|
<ElSelect
|
|
class="workspace-question-form__select"
|
|
:model-value="ws.newQuestion.agent_id ?? undefined"
|
|
:disabled="ws.agents.length === 0"
|
|
:placeholder="ws.agents.length === 0 ? t('workspace.noAgents') : t('workspace.quickQuestions.fields.selectAgent')"
|
|
@update:model-value="onQuestionAgentChange"
|
|
>
|
|
<ElOption v-for="agent in ws.agents" :key="agent.id" :label="agent.name" :value="agent.id" />
|
|
</ElSelect>
|
|
</ElFormItem>
|
|
<ElFormItem class="workspace-question-form__wide" :label="t('workspace.quickQuestions.fields.content')">
|
|
<ElInput
|
|
v-model="ws.newQuestion.question"
|
|
type="textarea"
|
|
:rows="3"
|
|
:placeholder="t('workspace.quickQuestions.fields.contentPlaceholder')"
|
|
/>
|
|
</ElFormItem>
|
|
</div>
|
|
<div class="workspace-question-form__actions">
|
|
<ElButton @click="ws.cancelAddQuestion">{{ t('workspace.cancel') }}</ElButton>
|
|
<ElButton type="primary" @click="ws.saveQuickQuestion">{{ t('workspace.save') }}</ElButton>
|
|
</div>
|
|
</ElForm>
|
|
</ElCard>
|
|
<ElEmpty
|
|
v-if="ws.filteredQuickQuestions.length === 0 && !ws.isAddingQuestion"
|
|
:description="t('workspace.quickQuestions.noDefined')"
|
|
/>
|
|
<div v-else class="workspace-question-grid">
|
|
<article
|
|
v-for="qq in ws.filteredQuickQuestions"
|
|
:key="qq.id"
|
|
class="workspace-question-card"
|
|
@click="ws.navigateWithQuickQuestion(qq.agent_id, qq.question)"
|
|
>
|
|
<div class="workspace-question-card__head">
|
|
<h4>{{ qq.title }}</h4>
|
|
<ElTag effect="light">{{ ws.getAgentName(qq.agent_id) }}</ElTag>
|
|
</div>
|
|
<p>{{ qq.question }}</p>
|
|
<div class="workspace-question-card__actions">
|
|
<ElButton link type="primary" :icon="Edit" :title="t('workspace.quickQuestions.edit')" @click.stop="ws.editQuickQuestion(qq)" />
|
|
<ElButton link type="danger" :icon="Delete" :title="t('workspace.quickQuestions.deleteDialog.title')" @click.stop="ws.removeQuickQuestion(qq.id)" />
|
|
</div>
|
|
</article>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="section.id === 'embedded'">
|
|
<ElEmpty v-if="ws.embeddedAgents.length === 0" :description="t('workspace.embedded.noData')" />
|
|
<div v-else class="workspace-embed-grid">
|
|
<article v-for="agent in ws.embeddedAgents" :key="agent.id" class="workspace-embed">
|
|
<div class="workspace-embed__bar">
|
|
<span>{{ agent.name }}</span>
|
|
<a class="workspace-embed__open" :href="`/chat/${agent.id}`" target="_blank" rel="noopener">
|
|
<ElIcon><TopRight /></ElIcon>
|
|
</a>
|
|
</div>
|
|
<iframe v-if="agent.iframe_url" :src="agent.iframe_url" class="workspace-embed__frame" />
|
|
<ElEmpty v-else :description="t('workspace.embedded.noUrl')" />
|
|
</article>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="section.id === 'all_agents'" class="workspace-agents">
|
|
<ElRadioGroup
|
|
class="workspace-categories"
|
|
:model-value="ws.selectedCategory || ''"
|
|
@update:model-value="onCategoryChange"
|
|
>
|
|
<ElRadioButton value="">{{ t('workspace.agentCategory.all') }}</ElRadioButton>
|
|
<ElRadioButton v-for="category in ws.agentCategories" :key="category" :value="category">
|
|
{{ category }}
|
|
</ElRadioButton>
|
|
</ElRadioGroup>
|
|
<ElInput
|
|
v-model="ws.searchQuery"
|
|
class="workspace-search"
|
|
clearable
|
|
:placeholder="t('workspace.search')"
|
|
/>
|
|
<div class="workspace-card-grid">
|
|
<article
|
|
v-for="agent in ws.otherAgents"
|
|
:key="agent.id"
|
|
class="workspace-app-card"
|
|
@click="ws.navigateToChat(agent.id)"
|
|
>
|
|
<div class="workspace-app-card__top">
|
|
<div class="workspace-app-card__icon">
|
|
<img v-if="agent.icon_url" :src="agent.icon_url" alt="" />
|
|
<ElIcon v-else><Monitor /></ElIcon>
|
|
</div>
|
|
<ElButton
|
|
link
|
|
:icon="ws.favoriteAgentIds.includes(agent.id) ? StarFilled : Star"
|
|
:title="t('workspace.favorites')"
|
|
:class="{ 'workspace-app-card__star--on': ws.favoriteAgentIds.includes(agent.id) }"
|
|
@click.stop="ws.toggleFavorite(agent.id)"
|
|
/>
|
|
</div>
|
|
<h3 class="workspace-app-card__name">{{ agent.name }}</h3>
|
|
<p class="workspace-app-card__desc">{{ agent.description }}</p>
|
|
</article>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</ElCard>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.workspace-hint {
|
|
margin-bottom: 16px;
|
|
padding: 12px 16px;
|
|
border: 1px solid var(--el-color-primary-light-7);
|
|
border-radius: var(--el-border-radius-base);
|
|
background: var(--el-color-primary-light-9);
|
|
color: var(--el-color-primary);
|
|
}
|
|
|
|
.workspace-section {
|
|
width: 100%;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.workspace-section--compact :deep(.el-card__body) {
|
|
padding-top: 8px;
|
|
padding-bottom: 8px;
|
|
}
|
|
|
|
.workspace-section__head {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 12px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.workspace-section__head--compact {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.workspace-section__lead {
|
|
display: flex;
|
|
min-width: 0;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.workspace-empty {
|
|
color: var(--el-text-color-secondary);
|
|
font-size: var(--el-font-size-small);
|
|
}
|
|
|
|
.workspace-section__title {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
border: 0;
|
|
background: transparent;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.workspace-section__icon {
|
|
color: var(--el-color-primary);
|
|
}
|
|
|
|
.workspace-section__grip {
|
|
color: var(--el-text-color-secondary);
|
|
cursor: grab;
|
|
}
|
|
|
|
.workspace-card-grid,
|
|
.workspace-question-grid,
|
|
.workspace-embed-grid {
|
|
display: grid;
|
|
gap: 16px;
|
|
}
|
|
|
|
.workspace-card-grid {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
|
|
.workspace-question-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.workspace-embed-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.workspace-app-card,
|
|
.workspace-question-card {
|
|
position: relative;
|
|
padding: 16px;
|
|
border: 1px solid var(--el-border-color-lighter);
|
|
border-radius: var(--el-border-radius-base);
|
|
background: var(--el-bg-color);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.workspace-app-card__top,
|
|
.workspace-question-card__head,
|
|
.workspace-embed__bar,
|
|
.workspace-question-form__actions {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
}
|
|
|
|
.workspace-app-card__icon {
|
|
display: flex;
|
|
width: 40px;
|
|
height: 40px;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border-radius: 8px;
|
|
background: var(--el-color-primary-light-9);
|
|
color: var(--el-color-primary);
|
|
}
|
|
|
|
.workspace-app-card__icon img {
|
|
width: 24px;
|
|
height: 24px;
|
|
}
|
|
|
|
.workspace-app-card__name,
|
|
.workspace-question-card h4 {
|
|
margin: 8px 0 4px;
|
|
color: var(--el-text-color-primary);
|
|
font-size: var(--el-font-size-base);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.workspace-app-card__desc,
|
|
.workspace-question-card p {
|
|
display: -webkit-box;
|
|
overflow: hidden;
|
|
margin: 0;
|
|
color: var(--el-text-color-secondary);
|
|
font-size: var(--el-font-size-small);
|
|
-webkit-box-orient: vertical;
|
|
-webkit-line-clamp: 2;
|
|
}
|
|
|
|
.workspace-app-card__star {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
}
|
|
|
|
.workspace-app-card__star--on {
|
|
color: var(--el-color-warning);
|
|
}
|
|
|
|
.workspace-question-card__actions {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
display: none;
|
|
}
|
|
|
|
.workspace-question-card:hover .workspace-question-card__actions {
|
|
display: flex;
|
|
}
|
|
|
|
.workspace-question-form {
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.workspace-question-form__grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr;
|
|
gap: 0 16px;
|
|
}
|
|
|
|
.workspace-question-form__select {
|
|
width: 100%;
|
|
}
|
|
|
|
.workspace-question-form__actions {
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.workspace-agents {
|
|
display: flex;
|
|
width: 100%;
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.workspace-categories {
|
|
display: flex;
|
|
width: fit-content;
|
|
max-width: 100%;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.workspace-search {
|
|
display: flex;
|
|
width: min(100%, 24rem);
|
|
margin-top: 12px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.workspace-announcements {
|
|
max-width: 42rem;
|
|
}
|
|
|
|
.workspace-embed {
|
|
display: flex;
|
|
height: 500px;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
border: 1px solid var(--el-border-color-lighter);
|
|
border-radius: var(--el-border-radius-base);
|
|
}
|
|
|
|
.workspace-embed__bar {
|
|
padding: 8px 12px;
|
|
border-bottom: 1px solid var(--el-border-color-lighter);
|
|
background: var(--el-fill-color-light);
|
|
}
|
|
|
|
.workspace-embed__open {
|
|
display: inline-flex;
|
|
color: var(--el-color-primary);
|
|
}
|
|
|
|
.workspace-embed__frame {
|
|
width: 100%;
|
|
flex: 1;
|
|
border: 0;
|
|
}
|
|
|
|
@media (min-width: 768px) {
|
|
.workspace-card-grid {
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
}
|
|
|
|
.workspace-question-grid,
|
|
.workspace-question-form__grid {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
|
|
.workspace-question-form__wide {
|
|
grid-column: 1 / -1;
|
|
}
|
|
}
|
|
|
|
@media (min-width: 1024px) {
|
|
.workspace-card-grid,
|
|
.workspace-embed-grid {
|
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
}
|
|
|
|
.workspace-embed-grid {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
|
|
.workspace-question-grid {
|
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
}
|
|
}
|
|
</style>
|