Local Ai Agent列表页操作列增加自定义模板

This commit is contained in:
jingrow 2025-11-01 15:55:39 +08:00
parent d29a27411f
commit ed261da974

View File

@ -0,0 +1,109 @@
<template>
<!-- 默认操作按钮 -->
<button class="action-btn" @click.stop="context.openDetail(context.row.name)" :title="context.t('View')">
<i class="fa fa-eye"></i>
</button>
<button class="action-btn" @click.stop="context.editRecord(context.row)" :title="context.t('Edit')">
<i class="fa fa-edit"></i>
</button>
<!-- 执行按钮 -->
<button
class="action-btn execute-btn"
@click.stop="handleExecute"
:title="context.t('Execute')"
:disabled="executing"
>
<i :class="executing ? 'fa fa-spinner fa-spin' : 'fa fa-play'"></i>
</button>
<button class="action-btn delete-btn" @click.stop="context.deleteRecord(context.row.name)" :title="context.t('Delete')">
<i class="fa fa-trash"></i>
</button>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useMessage } from 'naive-ui'
const props = defineProps<{
context: {
row: any
entity: string
openDetail: (name: string) => void
editRecord: (row: any) => void
deleteRecord: (name: string) => void
router: any
t: (key: string) => string
}
}>()
const message = useMessage()
const executing = ref(false)
async function handleExecute() {
try {
executing.value = true
const agentId = props.context.row.name
const agentName = props.context.row.agent_name || ''
const response = await fetch('/jingrow/agents/execute', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
agent_id: agentId,
agent_name: agentName,
session_cookie: document.cookie.split('; ').find(row => row.startsWith('sid='))?.split('=')[1]
})
})
const result = await response.json()
if (result.success) {
message.success(props.context.t('Agent execution started successfully'))
} else {
message.error(result.message || props.context.t('Execution failed'))
}
} catch (e: any) {
message.error(e?.message || props.context.t('Execution failed'))
} finally {
executing.value = false
}
}
</script>
<style scoped>
/* 继承父组件的样式,只需要覆盖特定样式 */
.action-btn {
width: 28px;
height: 28px;
border: none;
background: #f3f4f6;
color: #6b7280;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.action-btn:hover {
background: #3b82f6;
color: white;
}
.action-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.execute-btn:hover {
background: #10b981;
color: white;
}
.delete-btn:hover {
background: #ef4444;
color: white;
}
</style>