综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-07-17 18:16:50
  4. * @LastEditors: wrh
  5. * @LastEditTime: 2026-01-19 15:24:42
  6. -->
  7. <template>
  8. <div class="app-container">
  9. <div class="main-content">
  10. <!-- 左侧智能体列表 -->
  11. <div class="left-panel">
  12. <div class="panel-header">
  13. <h3>智能体列表</h3>
  14. <span class="agent-count">{{ agentList.length }} 个智能体</span>
  15. <el-button type="primary" size="small" @click="openAddDialog" icon="el-icon-plus">
  16. 新增智能体
  17. </el-button>
  18. </div>
  19. <!-- 搜索框 -->
  20. <div class="search-box">
  21. <el-input v-model="queryParams.agentName" placeholder="请输入智能体名称" clearable @clear="handleQuery"
  22. @keyup.enter="handleQuery">
  23. <span slot="append">
  24. <el-button @click="handleQuery" icon="el-icon-search">
  25. </el-button>
  26. </span>
  27. </el-input>
  28. </div>
  29. <!-- 智能体列表 -->
  30. <div class="agent-cards" v-loading="loading">
  31. <div v-for="agent in agentList" :key="agent.agentId" class="agent-card"
  32. :class="{ 'active': selectedAgentId === agent.agentId }" @click="selectAgent(agent)">
  33. <div class="card-header">
  34. <div class="card-title">
  35. <i class="el-icon-folder folder-icon"></i>
  36. <span class="title-text">{{ agent.agentName }}</span>
  37. </div>
  38. <div class="card-actions">
  39. <el-dropdown @command="handleCommand" trigger="click">
  40. <el-button type="text" size="small" icon="el-icon-more">
  41. </el-button>
  42. <span slot="dropdown">
  43. <el-dropdown-menu>
  44. <el-dropdown-item :command="{ action: 'edit', agent }">编辑</el-dropdown-item>
  45. <el-dropdown-item :command="{ action: 'delete', agent }" divided>删除</el-dropdown-item>
  46. </el-dropdown-menu>
  47. </span>
  48. </el-dropdown>
  49. </div>
  50. </div>
  51. <div class="card-content">
  52. <p class="description">{{ agent.description || '暂无描述' }}</p>
  53. <div class="meta-info">
  54. <span class="create-time">{{ agent.createTime }}</span>
  55. </div>
  56. </div>
  57. </div>
  58. <!-- 空状态 -->
  59. <div v-if="agentList.length === 0 && !loading" class="empty-state">
  60. <i class="el-icon-folder-opened empty-icon"></i>
  61. <p>暂无智能体</p>
  62. <el-button type="primary" @click="openAddDialog">创建第一个智能体</el-button>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- 右侧详细内容 -->
  67. <div class="agent-detail">
  68. <AgentDetail :agent-id="selectedAgentId" />
  69. </div>
  70. <el-dialog :visible.sync="agentDialogVisible" :title="dialogTitle" width="500px" @close="resetForm">
  71. <el-form ref="ruleForm" :model="form" :rules="rules" label-width="80px">
  72. <el-form-item label="智能体名称" prop="agentName">
  73. <el-input v-model="form.agentName" placeholder="请输入智能体名称" maxlength="20" show-word-limit />
  74. </el-form-item>
  75. <el-form-item label="描述" prop="description">
  76. <el-input v-model="form.description" type="textarea" placeholder="请输入描述" :rows="2" maxlength="200"
  77. show-word-limit />
  78. </el-form-item>
  79. <el-form-item label="角色" prop="role">
  80. <el-input v-model="form.role" placeholder="请输入角色" maxlength="50" show-word-limit />
  81. </el-form-item>
  82. <el-form-item label="初始提示词" prop="initPrompt">
  83. <el-input v-model="form.initPrompt" type="textarea" placeholder="请输入初始提示词" :rows="4" maxlength="1000"
  84. show-word-limit />
  85. </el-form-item>
  86. <el-form-item label="模型" prop="modelName">
  87. <el-select v-model="form.modelName" placeholder="请选择模型" clearable>
  88. <el-option v-for="model in modelList" :key="model.name" :label="model.name" :value="model.name">
  89. </el-option>
  90. </el-select>
  91. </el-form-item>
  92. </el-form>
  93. <span slot="footer" class="dialog-footer">
  94. <el-button @click="closeDialog">取消</el-button>
  95. <el-button type="primary" @click="submitForm">确定</el-button>
  96. </span>
  97. </el-dialog>
  98. </div>
  99. </div>
  100. </template>
  101. <script>
  102. import { Message } from 'element-ui'
  103. import { listAgent, addAgent, updateAgent, delAgent, opening } from '@/api/llm/agent'
  104. import { answer } from '@/api/llm/mcp'
  105. import AgentDetail from './AgentDetail.vue'
  106. export default {
  107. name: 'AgentIndex',
  108. components: {
  109. AgentDetail
  110. },
  111. data() {
  112. return {
  113. // 响应式数据
  114. loading: false,
  115. agentList: [],
  116. total: 0,
  117. selectedAgentId: null,
  118. dialogVisible: false,
  119. form: {
  120. agentName: '',
  121. description: '',
  122. avatar: '',
  123. role: '',
  124. initPrompt: '',
  125. modelName: ''
  126. },
  127. rules: {
  128. agentName: [{ required: true, message: '请输入智能体名称', trigger: 'blur' }],
  129. description: [{ required: true, message: '请输入智能体描述', trigger: 'blur' }]
  130. },
  131. isEdit: false,
  132. editAgentId: null,
  133. open: false,
  134. // 查询参数
  135. queryParams: {
  136. pageNum: 1,
  137. pageSize: 20,
  138. agentName: ''
  139. },
  140. // 新增智能体对话框控制变量
  141. agentDialogVisible: false,
  142. dialogTitle: '',
  143. isModifyAgent: false,
  144. // 模型列表
  145. modelList: [{name: "Qwen2.5-7B-Instruct"}]
  146. }
  147. },
  148. mounted() {
  149. this.getList()
  150. },
  151. methods: {
  152. // 获取智能体列表
  153. getList() {
  154. this.loading = true
  155. listAgent(this.queryParams).then(response => {
  156. this.agentList = response.rows || []
  157. this.total = response.total || 0
  158. }).catch(error => {
  159. console.error('获取智能体列表失败:', error)
  160. this.$message.error('获取智能体列表失败')
  161. }).finally(() => {
  162. this.loading = false
  163. })
  164. },
  165. // 搜索
  166. handleQuery() {
  167. this.queryParams.pageNum = 1
  168. this.getList()
  169. },
  170. // 选择智能体
  171. selectAgent(agent) {
  172. this.selectedAgentId = agent.agentId
  173. },
  174. resetForm() {
  175. this.isEdit = false
  176. this.editAgentId = null
  177. this.form = {
  178. agentName: '',
  179. description: '',
  180. avatar: '',
  181. role: '',
  182. initPrompt: '',
  183. modelName: ''
  184. }
  185. // 如果有表单引用,重置验证
  186. if (this.$refs.ruleForm) {
  187. this.$refs.ruleForm.resetFields()
  188. }
  189. },
  190. // 打开新增智能体对话框
  191. openAddDialog() {
  192. this.agentDialogVisible = true
  193. this.dialogTitle = "添加智能体"
  194. this.isModifyAgent = false
  195. // 重置表单
  196. this.resetForm()
  197. },
  198. // 关闭对话框
  199. closeDialog() {
  200. this.agentDialogVisible = false
  201. this.resetForm()
  202. },
  203. // 提交表单
  204. submitForm() {
  205. this.$refs.ruleForm.validate((valid) => {
  206. if (valid) {
  207. this.loading = true
  208. const agentForm = { ...this.form }
  209. if (this.isModifyAgent) {
  210. updateAgent(agentForm).then(() => {
  211. this.$message.success('修改成功')
  212. this.loading = false
  213. this.agentDialogVisible = false
  214. this.getList()
  215. }).catch(() => {
  216. this.loading = false
  217. this.$message.error('修改失败')
  218. })
  219. } else {
  220. addAgent(agentForm).then(() => {
  221. this.$message.success('新增成功')
  222. this.loading = false
  223. this.agentDialogVisible = false
  224. this.getList()
  225. }).catch(() => {
  226. this.loading = false
  227. this.$message.error('新增失败')
  228. })
  229. }
  230. }
  231. })
  232. },
  233. // 操作菜单处理
  234. handleCommand(command) {
  235. const { action, agent } = command
  236. if (action === 'edit') {
  237. this.isEdit = true
  238. this.editAgentId = agent.agentId
  239. this.form = {
  240. agentName: agent.agentName,
  241. description: agent.description,
  242. avatar: agent.avatar || '',
  243. role: agent.role || '',
  244. initPrompt: agent.initPrompt || '',
  245. modelName: agent.modelName || ''
  246. }
  247. this.dialogVisible = true
  248. } else if (action === 'delete') {
  249. this.$confirm(
  250. `确认删除智能体"${agent.agentName}"吗?`,
  251. '删除确认',
  252. {
  253. confirmButtonText: '确认',
  254. cancelButtonText: '取消',
  255. type: 'warning'
  256. }
  257. ).then(() => {
  258. return delAgent(agent.agentId)
  259. }).then(() => {
  260. this.$message.success('删除成功')
  261. // 如果删除的是当前选中的智能体,清空选中状态
  262. if (this.selectedAgentId === agent.agentId) {
  263. this.selectedAgentId = null
  264. }
  265. this.getList()
  266. }).catch(error => {
  267. if (error !== 'cancel') {
  268. console.error('删除智能体失败:', error)
  269. this.$message.error('删除失败')
  270. }
  271. })
  272. }
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .app-container {
  279. height: 100vh;
  280. display: flex;
  281. flex-direction: column;
  282. background: #f5f7fa;
  283. }
  284. .main-content {
  285. flex: 1;
  286. display: flex;
  287. gap: 16px;
  288. padding: 16px;
  289. overflow: hidden;
  290. }
  291. .left-panel {
  292. width: 400px;
  293. background: white;
  294. border-radius: 8px;
  295. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  296. display: flex;
  297. flex-direction: column;
  298. overflow: hidden;
  299. }
  300. .right-panel {
  301. flex: 1;
  302. background: white;
  303. border-radius: 8px;
  304. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  305. display: flex;
  306. flex-direction: column;
  307. overflow: hidden;
  308. }
  309. .panel-header {
  310. padding: 20px 24px;
  311. border-bottom: 1px solid #e4e7ed;
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. background: #fafbfc;
  316. h3 {
  317. margin: 0;
  318. font-size: 16px;
  319. font-weight: 600;
  320. color: #303133;
  321. }
  322. .agent-count {
  323. font-size: 12px;
  324. color: #909399;
  325. background: #f0f2f5;
  326. padding: 4px 8px;
  327. border-radius: 4px;
  328. }
  329. .search-box {
  330. padding: 16px;
  331. border-bottom: 1px solid #e4e4e4;
  332. }
  333. }
  334. .agent-cards {
  335. flex: 1;
  336. padding: 16px;
  337. overflow-y: auto;
  338. display: flex;
  339. flex-direction: column;
  340. gap: 12px;
  341. }
  342. .agent-card {
  343. background: white;
  344. border: 1px solid #e4e7ed;
  345. border-radius: 8px;
  346. padding: 16px;
  347. cursor: pointer;
  348. transition: all 0.3s ease;
  349. position: relative;
  350. &:hover {
  351. border-color: #409eff;
  352. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.15);
  353. transform: translateY(-2px);
  354. }
  355. &.active {
  356. border-color: #409eff;
  357. background: #f0f9ff;
  358. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
  359. }
  360. .card-header {
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: flex-start;
  364. margin-bottom: 12px;
  365. .card-title {
  366. display: flex;
  367. align-items: center;
  368. gap: 8px;
  369. flex: 1;
  370. .folder-icon {
  371. color: #409eff;
  372. font-size: 18px;
  373. }
  374. .title-text {
  375. font-weight: 600;
  376. color: #303133;
  377. font-size: 14px;
  378. line-height: 1.4;
  379. }
  380. }
  381. .card-actions {
  382. opacity: 0;
  383. transition: opacity 0.3s ease;
  384. }
  385. }
  386. &:hover .card-actions {
  387. opacity: 1;
  388. }
  389. .card-content {
  390. .description {
  391. color: #606266;
  392. font-size: 13px;
  393. line-height: 1.5;
  394. margin: 0 0 12px 0;
  395. display: -webkit-box;
  396. -webkit-line-clamp: 2;
  397. -webkit-box-orient: vertical;
  398. overflow: hidden;
  399. }
  400. .meta-info {
  401. display: flex;
  402. justify-content: space-between;
  403. align-items: center;
  404. font-size: 12px;
  405. color: #909399;
  406. .create-time {
  407. background: #f0f2f5;
  408. padding: 2px 6px;
  409. border-radius: 3px;
  410. }
  411. }
  412. }
  413. }
  414. .empty-state {
  415. display: flex;
  416. flex-direction: column;
  417. align-items: center;
  418. justify-content: center;
  419. padding: 60px 20px;
  420. text-align: center;
  421. color: #909399;
  422. .empty-icon {
  423. font-size: 48px;
  424. margin-bottom: 16px;
  425. opacity: 0.5;
  426. }
  427. p {
  428. margin: 0 0 16px 0;
  429. font-size: 14px;
  430. }
  431. }
  432. .agent-detail {
  433. flex: 1;
  434. background: white;
  435. }
  436. </style>