FlowManagement.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template>
  2. <div class="management-container">
  3. <div class="page-header">
  4. <div class="header-copy">
  5. <h1>智能体管理</h1>
  6. </div>
  7. </div>
  8. <div class="stats-grid">
  9. <div class="stat-card">
  10. <div class="stat-icon coral">
  11. <SvgIcon name="platForm" size="20" />
  12. </div>
  13. <div>
  14. <div class="stat-value">{{ pageData.totalCount }}</div>
  15. <div class="stat-label">智能体总数</div>
  16. </div>
  17. </div>
  18. <div class="stat-card">
  19. <div class="stat-icon blue">
  20. <SvgIcon name="workflow" size="20" />
  21. </div>
  22. <div>
  23. <div class="stat-value">{{ agents.length }}</div>
  24. <div class="stat-label">当前页数量</div>
  25. </div>
  26. </div>
  27. <div class="stat-card">
  28. <div class="stat-icon green">
  29. <SvgIcon name="service" size="20" />
  30. </div>
  31. <div>
  32. <div class="stat-value">{{ totalConversationVariables }}</div>
  33. <div class="stat-label">会话变量数</div>
  34. </div>
  35. </div>
  36. <div class="stat-card">
  37. <div class="stat-icon orange">
  38. <SvgIcon name="setting" size="20" />
  39. </div>
  40. <div>
  41. <div class="stat-value">{{ totalEnvVariables }}</div>
  42. <div class="stat-label">环境变量数</div>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="panel">
  47. <div class="toolbar">
  48. <el-input
  49. v-model="keyword"
  50. placeholder="搜索当前页的智能体名称或 ID"
  51. clearable
  52. class="search-input"
  53. >
  54. <template #prefix>
  55. <el-icon><Search /></el-icon>
  56. </template>
  57. </el-input>
  58. <div class="toolbar-meta">
  59. <el-button type="primary" link :loading="loading" @click="loadAgents(pageIndex)">
  60. <el-icon><RefreshRight /></el-icon>
  61. </el-button>
  62. <span class="meta-pill"
  63. >第 {{ pageData.currentPage || 1 }} / {{ pageData.totalPages || 1 }} 页</span
  64. >
  65. <span class="meta-pill">{{ pageData.pageSize }} 条/页</span>
  66. </div>
  67. </div>
  68. <div v-loading="loading" class="card-grid">
  69. <div
  70. v-for="row in filteredAgents"
  71. :key="row.id"
  72. class="agent-card"
  73. @click="handleRowClick(row)"
  74. >
  75. <div class="cover">
  76. <img
  77. v-if="row.profilePhoto"
  78. :src="row.profilePhoto"
  79. :alt="row.name"
  80. class="cover-image"
  81. />
  82. <div v-else class="cover-fallback">
  83. <div class="fallback-monogram">{{ row.name?.slice(0, 1) || 'A' }}</div>
  84. </div>
  85. <div class="cover-gradient"></div>
  86. <div class="cover-top">
  87. <span class="cover-badge">智能体</span>
  88. <span class="cover-badge subtle">{{ row.env_variables.length }} 个环境变量</span>
  89. </div>
  90. </div>
  91. <div class="cover-bottom">
  92. <el-avatar :size="56" :src="row.profilePhoto || undefined" class="cover-avatar">
  93. {{ row.name?.slice(0, 1) || 'A' }}
  94. </el-avatar>
  95. </div>
  96. <div class="card-body">
  97. <div class="card-head">
  98. <div class="card-title-wrap">
  99. <div class="agent-name" :title="row.name || fallbackText.unnamed">
  100. {{ row.name || fallbackText.unnamed }}
  101. </div>
  102. <div class="agent-id" :title="row.id">{{ row.id }}</div>
  103. </div>
  104. </div>
  105. <div class="card-footer">
  106. <el-button type="primary" @click.stop="openAgent(row.id)">打开</el-button>
  107. </div>
  108. </div>
  109. </div>
  110. <el-empty
  111. v-if="!filteredAgents.length && !loading"
  112. :description="keyword ? emptyText.filtered : emptyText.default"
  113. class="empty-state"
  114. />
  115. </div>
  116. <div class="pagination">
  117. <el-pagination
  118. background
  119. layout="prev, pager, next, total"
  120. :current-page="pageIndex"
  121. :page-size="pageData.pageSize || 10"
  122. :total="pageData.totalCount"
  123. @current-change="handlePageChange"
  124. />
  125. </div>
  126. </div>
  127. </div>
  128. </template>
  129. <script setup lang="ts">
  130. import { computed, onMounted, ref } from 'vue'
  131. import { useRouter } from 'vue-router'
  132. import { ElMessage } from 'element-plus'
  133. import { RefreshRight, Search } from '@element-plus/icons-vue'
  134. import { agent } from '@repo/api-service'
  135. import SvgIcon from '@/components/SvgIcon/index.vue'
  136. type AgentListResponse = Awaited<ReturnType<typeof agent.postAgentGetAgentList>>
  137. type AgentListResult = NonNullable<AgentListResponse['result']>
  138. type AgentListItem = AgentListResult['model'][number]
  139. const createEmptyPageData = (): AgentListResult => ({
  140. currentPage: 1,
  141. hasNextPage: false,
  142. hasPreviousPage: false,
  143. model: [],
  144. pageSize: 10,
  145. totalCount: 0,
  146. totalPages: 0
  147. })
  148. const fallbackText = {
  149. unnamed: '未命名智能体',
  150. notConfiguredConversation: '未配置会话变量',
  151. notConfiguredEnv: '未配置环境变量'
  152. } as const
  153. const emptyText = {
  154. default: '暂无智能体数据',
  155. filtered: '当前筛选条件下暂无数据'
  156. } as const
  157. const separator = '、'
  158. const router = useRouter()
  159. const loading = ref(false)
  160. const keyword = ref('')
  161. const pageIndex = ref(1)
  162. const pageData = ref<AgentListResult>(createEmptyPageData())
  163. const agents = computed(() => pageData.value.model)
  164. const filteredAgents = computed(() => {
  165. const searchValue = keyword.value.trim().toLowerCase()
  166. if (!searchValue) {
  167. return agents.value
  168. }
  169. return agents.value.filter((item) => {
  170. const name = item.name.toLowerCase()
  171. const id = item.id.toLowerCase()
  172. return name.includes(searchValue) || id.includes(searchValue)
  173. })
  174. })
  175. const totalConversationVariables = computed(() =>
  176. agents.value.reduce((total, item) => total + item.conversation_variables.length, 0)
  177. )
  178. const totalEnvVariables = computed(() =>
  179. agents.value.reduce((total, item) => total + item.env_variables.length, 0)
  180. )
  181. const formatConversationVariables = (variables: AgentListItem['conversation_variables']) => {
  182. if (!variables.length) {
  183. return fallbackText.notConfiguredConversation
  184. }
  185. return variables.slice(0, 4).join(separator) + (variables.length > 4 ? '...' : '')
  186. }
  187. const formatEnvVariables = (variables: AgentListItem['env_variables']) => {
  188. if (!variables.length) {
  189. return fallbackText.notConfiguredEnv
  190. }
  191. const labels = variables.slice(0, 3).map((item) => item.name || item.type)
  192. return labels.join(separator) + (variables.length > 3 ? '...' : '')
  193. }
  194. const openAgent = (id: string) => {
  195. router.push(`/workflow/${id}`)
  196. }
  197. const handleRowClick = (row: AgentListItem) => {
  198. openAgent(row.id)
  199. }
  200. const loadAgents = async (targetPage = 1) => {
  201. loading.value = true
  202. try {
  203. const response = await agent.postAgentGetAgentList({
  204. pageIndex: targetPage
  205. })
  206. if (!response.isSuccess || !response.result) {
  207. throw new Error('获取智能体列表失败')
  208. }
  209. pageData.value = response.result
  210. pageIndex.value = response.result.currentPage || targetPage
  211. } catch (error) {
  212. console.error('loadAgents error', error)
  213. ElMessage.error('加载智能体列表失败')
  214. pageData.value = createEmptyPageData()
  215. } finally {
  216. loading.value = false
  217. }
  218. }
  219. const handlePageChange = (nextPage: number) => {
  220. pageIndex.value = nextPage
  221. loadAgents(nextPage)
  222. }
  223. onMounted(() => {
  224. loadAgents(pageIndex.value)
  225. })
  226. </script>
  227. <style lang="less" scoped>
  228. .management-container {
  229. max-width: 1320px;
  230. margin: 0 auto;
  231. padding: 28px 24px 32px;
  232. }
  233. .page-header {
  234. display: flex;
  235. align-items: flex-end;
  236. justify-content: space-between;
  237. gap: 20px;
  238. margin-bottom: 24px;
  239. }
  240. .header-copy {
  241. h1 {
  242. margin: 6px 0 8px;
  243. font-size: 30px;
  244. line-height: 1.1;
  245. color: var(--text-primary);
  246. }
  247. p {
  248. margin: 0;
  249. max-width: 720px;
  250. font-size: 14px;
  251. line-height: 1.7;
  252. color: var(--text-secondary);
  253. }
  254. }
  255. .eyebrow {
  256. display: inline-flex;
  257. align-items: center;
  258. padding: 6px 10px;
  259. border-radius: 999px;
  260. background: rgba(255, 107, 107, 0.1);
  261. color: var(--el-color-primary);
  262. font-size: 12px;
  263. font-weight: 700;
  264. letter-spacing: 0.08em;
  265. text-transform: uppercase;
  266. }
  267. .stats-grid {
  268. display: grid;
  269. grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  270. gap: 16px;
  271. margin-bottom: 22px;
  272. }
  273. .stat-card {
  274. display: flex;
  275. align-items: center;
  276. gap: 14px;
  277. padding: 18px;
  278. border: 1px solid var(--border-light);
  279. border-radius: 18px;
  280. background:
  281. linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 247, 250, 0.8)), var(--bg-base);
  282. box-shadow: 0 14px 32px rgba(15, 23, 42, 0.05);
  283. }
  284. .stat-icon {
  285. width: 46px;
  286. height: 46px;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. border-radius: 14px;
  291. &.coral {
  292. background: #fff1f0;
  293. color: #ff6b6b;
  294. }
  295. &.blue {
  296. background: #eef4ff;
  297. color: #3b82f6;
  298. }
  299. &.green {
  300. background: #ecfdf3;
  301. color: #10b981;
  302. }
  303. &.orange {
  304. background: #fff7ed;
  305. color: #f97316;
  306. }
  307. }
  308. .stat-value {
  309. font-size: 24px;
  310. font-weight: 700;
  311. color: var(--text-primary);
  312. }
  313. .stat-label {
  314. margin-top: 2px;
  315. font-size: 13px;
  316. color: var(--text-secondary);
  317. }
  318. .panel {
  319. padding: 22px;
  320. border: 1px solid var(--border-light);
  321. border-radius: 22px;
  322. background: var(--bg-base);
  323. box-shadow: 0 18px 42px rgba(15, 23, 42, 0.06);
  324. }
  325. .toolbar {
  326. display: flex;
  327. align-items: center;
  328. justify-content: space-between;
  329. gap: 16px;
  330. margin-bottom: 20px;
  331. }
  332. .search-input {
  333. max-width: 340px;
  334. }
  335. .toolbar-meta {
  336. display: flex;
  337. align-items: center;
  338. flex-wrap: wrap;
  339. gap: 10px;
  340. }
  341. .meta-pill {
  342. display: inline-flex;
  343. align-items: center;
  344. padding: 8px 12px;
  345. border: 1px solid var(--border-light);
  346. border-radius: 999px;
  347. background: var(--bg-container);
  348. font-size: 12px;
  349. color: var(--text-secondary);
  350. }
  351. .card-grid {
  352. display: grid;
  353. grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  354. gap: 20px;
  355. min-height: 240px;
  356. }
  357. .agent-card {
  358. display: flex;
  359. flex-direction: column;
  360. min-height: 100%;
  361. overflow: hidden;
  362. border: 1px solid var(--border-light);
  363. border-radius: 22px;
  364. background: var(--bg-base);
  365. box-shadow: 0 14px 32px rgba(15, 23, 42, 0.06);
  366. cursor: pointer;
  367. position: relative;
  368. transition:
  369. transform 0.18s ease,
  370. box-shadow 0.18s ease,
  371. border-color 0.18s ease;
  372. &:hover {
  373. transform: translateY(-6px);
  374. border-color: rgba(255, 107, 107, 0.24);
  375. box-shadow: 0 20px 46px rgba(15, 23, 42, 0.1);
  376. }
  377. }
  378. .cover {
  379. position: relative;
  380. height: 188px;
  381. overflow: hidden;
  382. background:
  383. radial-gradient(circle at top left, rgba(255, 107, 107, 0.28), transparent 38%),
  384. radial-gradient(circle at right bottom, rgba(59, 130, 246, 0.24), transparent 34%),
  385. linear-gradient(135deg, #f8fafc, #eef2ff);
  386. }
  387. .cover-image,
  388. .cover-fallback {
  389. width: 100%;
  390. height: 100%;
  391. }
  392. .cover-image {
  393. display: block;
  394. object-fit: cover;
  395. }
  396. .cover-fallback {
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. }
  401. .fallback-monogram {
  402. width: 84px;
  403. height: 84px;
  404. display: flex;
  405. align-items: center;
  406. justify-content: center;
  407. border-radius: 24px;
  408. background: rgba(255, 255, 255, 0.7);
  409. backdrop-filter: blur(10px);
  410. font-size: 38px;
  411. font-weight: 800;
  412. color: #ff6b6b;
  413. }
  414. .cover-gradient {
  415. position: absolute;
  416. inset: 0;
  417. background: linear-gradient(180deg, rgba(10, 10, 10, 0.02), rgba(10, 10, 10, 0.5));
  418. }
  419. .cover-top {
  420. position: absolute;
  421. top: 14px;
  422. left: 14px;
  423. right: 14px;
  424. display: flex;
  425. justify-content: space-between;
  426. gap: 8px;
  427. }
  428. .cover-badge {
  429. display: inline-flex;
  430. align-items: center;
  431. padding: 6px 10px;
  432. border-radius: 999px;
  433. background: rgba(255, 255, 255, 0.92);
  434. color: #1f2937;
  435. font-size: 12px;
  436. font-weight: 600;
  437. backdrop-filter: blur(10px);
  438. &.subtle {
  439. background: rgba(15, 23, 42, 0.58);
  440. color: #fff;
  441. }
  442. }
  443. .cover-bottom {
  444. position: absolute;
  445. left: 18px;
  446. top: 160px;
  447. }
  448. .cover-avatar {
  449. border: 4px solid var(--bg-base);
  450. box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  451. }
  452. .card-body {
  453. display: flex;
  454. flex: 1;
  455. flex-direction: column;
  456. padding: 40px 18px 18px;
  457. }
  458. .card-head {
  459. display: flex;
  460. align-items: flex-start;
  461. justify-content: space-between;
  462. gap: 12px;
  463. }
  464. .card-title-wrap {
  465. min-width: 0;
  466. }
  467. .agent-name {
  468. overflow: hidden;
  469. font-size: 18px;
  470. font-weight: 700;
  471. line-height: 1.3;
  472. color: var(--text-primary);
  473. text-overflow: ellipsis;
  474. white-space: nowrap;
  475. }
  476. .agent-id {
  477. margin-top: 6px;
  478. overflow: hidden;
  479. font-size: 12px;
  480. color: var(--text-secondary);
  481. text-overflow: ellipsis;
  482. white-space: nowrap;
  483. }
  484. .enter-link {
  485. padding-right: 0;
  486. padding-left: 0;
  487. }
  488. .metric-row {
  489. display: grid;
  490. grid-template-columns: repeat(2, minmax(0, 1fr));
  491. gap: 10px;
  492. margin-top: 18px;
  493. }
  494. .metric-card {
  495. padding: 12px 14px;
  496. border: 1px solid var(--border-light);
  497. border-radius: 16px;
  498. background: var(--bg-container);
  499. }
  500. .metric-label {
  501. font-size: 12px;
  502. color: var(--text-tertiary);
  503. }
  504. .metric-value {
  505. margin-top: 6px;
  506. font-size: 20px;
  507. font-weight: 700;
  508. line-height: 1;
  509. color: var(--text-primary);
  510. }
  511. .detail-panel {
  512. display: grid;
  513. gap: 12px;
  514. margin-top: 16px;
  515. padding: 14px;
  516. border-radius: 18px;
  517. background: linear-gradient(180deg, var(--bg-container), rgba(245, 247, 250, 0.4));
  518. }
  519. .detail-item {
  520. padding-bottom: 12px;
  521. border-bottom: 1px solid var(--border-light);
  522. &:last-child {
  523. padding-bottom: 0;
  524. border-bottom: 0;
  525. }
  526. }
  527. .detail-label {
  528. font-size: 12px;
  529. color: var(--text-tertiary);
  530. }
  531. .detail-value {
  532. margin-top: 6px;
  533. font-size: 13px;
  534. line-height: 1.65;
  535. color: var(--text-secondary);
  536. word-break: break-word;
  537. }
  538. .card-footer {
  539. display: flex;
  540. justify-content: flex-end;
  541. margin-top: auto;
  542. padding-top: 18px;
  543. }
  544. .empty-state {
  545. grid-column: 1 / -1;
  546. padding: 30px 0 18px;
  547. }
  548. .pagination {
  549. display: flex;
  550. justify-content: flex-end;
  551. margin-top: 20px;
  552. }
  553. @media (max-width: 960px) {
  554. .page-header,
  555. .toolbar {
  556. flex-direction: column;
  557. align-items: stretch;
  558. }
  559. .search-input {
  560. max-width: none;
  561. }
  562. .toolbar-meta,
  563. .pagination {
  564. justify-content: flex-start;
  565. }
  566. }
  567. @media (max-width: 640px) {
  568. .management-container {
  569. padding: 18px 14px 24px;
  570. }
  571. .panel {
  572. padding: 16px;
  573. border-radius: 18px;
  574. }
  575. .card-grid {
  576. grid-template-columns: 1fr;
  577. }
  578. .cover {
  579. height: 172px;
  580. }
  581. .card-head {
  582. flex-direction: column;
  583. }
  584. .enter-link,
  585. .card-footer :deep(.el-button) {
  586. width: 100%;
  587. }
  588. }
  589. </style>