更新首页dashboard组件
This commit is contained in:
parent
8c69ea9ba9
commit
2638c1e435
@ -57,11 +57,25 @@
|
||||
"Are you sure you want to delete the selected agents? This action cannot be undone.": "确定要删除选中的智能体吗?此操作无法撤销。",
|
||||
"Delete": "删除",
|
||||
"Cancel": "取消",
|
||||
"Clear All": "清空全部",
|
||||
"Confirm Clear All": "确认清空全部",
|
||||
"Are you sure you want to delete this activity?": "确定要删除此活动吗?",
|
||||
"Are you sure you want to delete all recent activities? This action cannot be undone.": "确定要删除所有最近活动吗?此操作无法撤销。",
|
||||
"Activity deleted successfully": "活动删除成功",
|
||||
"Failed to delete activity": "删除活动失败",
|
||||
"All activities deleted successfully": "所有活动删除成功",
|
||||
"Failed to delete activities": "删除活动失败",
|
||||
"No activities to delete": "没有活动可删除",
|
||||
"Unknown error": "未知错误",
|
||||
"Network error": "网络错误",
|
||||
|
||||
"Local Ai Agent": "本地智能体",
|
||||
"Local Ai Node": "本地节点",
|
||||
"Knowledge Base": "知识库",
|
||||
"Note": "笔记",
|
||||
"Event": "事件",
|
||||
"ToDo": "待办事项",
|
||||
"File": "文件",
|
||||
"AI Agents": "AI智能体",
|
||||
"Manage and configure your AI agents workflows": "管理和配置您的AI智能体工作流",
|
||||
"Create Agent": "创建智能体",
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
<!-- 统计卡片 -->
|
||||
<n-grid :cols="4" :x-gap="16" :y-gap="16" :responsive="'screen'" :item-responsive="true" class="stats-grid">
|
||||
<!-- 原来的4个统计 -->
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('Total Agents')" :value="stats.agents" />
|
||||
@ -26,65 +27,72 @@
|
||||
<n-statistic :label="t('Scheduled Tasks')" :value="stats.scheduledTasks" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
|
||||
<!-- 新增的5个统计 -->
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('Knowledge Base')" :value="stats.knowledgeBase" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('Note')" :value="stats.note" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('Event')" :value="stats.event" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('ToDo')" :value="stats.todo" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
<n-grid-item>
|
||||
<n-card>
|
||||
<n-statistic :label="t('File')" :value="stats.file" />
|
||||
</n-card>
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
|
||||
|
||||
<!-- 最近活动 -->
|
||||
<n-card :title="t('Recent Activities')" class="recent-activities">
|
||||
<n-list>
|
||||
<n-list-item v-for="activity in recentActivities" :key="activity.id">
|
||||
<n-thing>
|
||||
<template #header>
|
||||
{{ activity.title }}
|
||||
</template>
|
||||
<template #description>
|
||||
{{ activity.description }}
|
||||
<br>
|
||||
<small style="color: #999;">{{ activity.user }}</small>
|
||||
</template>
|
||||
<template #footer>
|
||||
{{ activity.time }}
|
||||
</template>
|
||||
</n-thing>
|
||||
</n-list-item>
|
||||
</n-list>
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { reactive, onMounted } from 'vue'
|
||||
import {
|
||||
NGrid,
|
||||
NGridItem,
|
||||
NCard,
|
||||
NStatistic,
|
||||
NList,
|
||||
NListItem,
|
||||
NThing
|
||||
NStatistic
|
||||
} from 'naive-ui'
|
||||
import { t } from '../shared/i18n'
|
||||
import { getRecords, getCount, getLocalJobCount } from '../shared/api/common'
|
||||
import { getCount, getLocalJobCount } from '../shared/api/common'
|
||||
|
||||
const stats = reactive({
|
||||
agents: 0,
|
||||
nodes: 0,
|
||||
taskQueue: 0,
|
||||
scheduledTasks: 0
|
||||
scheduledTasks: 0,
|
||||
knowledgeBase: 0,
|
||||
note: 0,
|
||||
event: 0,
|
||||
todo: 0,
|
||||
file: 0
|
||||
})
|
||||
|
||||
// 加载统计数据
|
||||
const loadStats = async () => {
|
||||
try {
|
||||
console.log('开始加载统计数据...')
|
||||
|
||||
// 第一行:原来的4个统计
|
||||
// 获取智能体总数
|
||||
const agentsResult = await getCount('Local Ai Agent')
|
||||
if (agentsResult.success) {
|
||||
stats.agents = agentsResult.count || 0
|
||||
}
|
||||
|
||||
// 获取节点总数 - 使用Local Ai Node
|
||||
// 获取节点总数
|
||||
const nodesResult = await getCount('Local Ai Node')
|
||||
if (nodesResult.success) {
|
||||
stats.nodes = nodesResult.count || 0
|
||||
@ -96,86 +104,51 @@ const loadStats = async () => {
|
||||
stats.taskQueue = taskQueueResult.count || 0
|
||||
}
|
||||
|
||||
// 获取定时任务数量 - 使用Local Scheduled Job
|
||||
// 获取定时任务数量
|
||||
const scheduledTasksResult = await getCount('Local Scheduled Job')
|
||||
if (scheduledTasksResult.success) {
|
||||
stats.scheduledTasks = scheduledTasksResult.count || 0
|
||||
}
|
||||
|
||||
console.log('更新后的统计数据:', {
|
||||
agents: stats.agents,
|
||||
nodes: stats.nodes,
|
||||
taskQueue: stats.taskQueue,
|
||||
scheduledTasks: stats.scheduledTasks
|
||||
})
|
||||
// 第二行:新增的5个统计
|
||||
// 获取知识库总数
|
||||
const knowledgeBaseResult = await getCount('Knowledge Base')
|
||||
if (knowledgeBaseResult.success) {
|
||||
stats.knowledgeBase = knowledgeBaseResult.count || 0
|
||||
}
|
||||
|
||||
// 获取笔记总数
|
||||
const noteResult = await getCount('Note')
|
||||
if (noteResult.success) {
|
||||
stats.note = noteResult.count || 0
|
||||
}
|
||||
|
||||
// 获取事件总数
|
||||
const eventResult = await getCount('Event')
|
||||
if (eventResult.success) {
|
||||
stats.event = eventResult.count || 0
|
||||
}
|
||||
|
||||
// 获取待办事项总数
|
||||
const todoResult = await getCount('ToDo')
|
||||
if (todoResult.success) {
|
||||
stats.todo = todoResult.count || 0
|
||||
}
|
||||
|
||||
// 获取文件总数
|
||||
const fileResult = await getCount('File')
|
||||
if (fileResult.success) {
|
||||
stats.file = fileResult.count || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
interface ActivityItem {
|
||||
id: string
|
||||
title: string
|
||||
description: string
|
||||
time: string
|
||||
user: string
|
||||
status: string
|
||||
}
|
||||
|
||||
const recentActivities = ref<ActivityItem[]>([])
|
||||
|
||||
// 加载最近活动数据
|
||||
const loadRecentActivities = async () => {
|
||||
try {
|
||||
const result = await getRecords(
|
||||
'Activity Log',
|
||||
[], // 无过滤条件
|
||||
['subject', 'content', 'communication_date', 'full_name', 'operation', 'status'], // 需要的字段
|
||||
'communication_date desc', // 按时间倒序
|
||||
0, // 起始位置
|
||||
10 // 限制10条记录
|
||||
)
|
||||
|
||||
if (result.success && result.data) {
|
||||
recentActivities.value = result.data.map((activity: any) => ({
|
||||
id: activity.name,
|
||||
title: activity.subject || '活动',
|
||||
description: activity.content || activity.operation || '无描述',
|
||||
time: formatTimeAgo(activity.communication_date),
|
||||
user: activity.full_name || '未知用户',
|
||||
status: activity.status || 'Success'
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载最近活动失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化时间为相对时间
|
||||
const formatTimeAgo = (dateString: string) => {
|
||||
if (!dateString) return '未知时间'
|
||||
|
||||
const date = new Date(dateString)
|
||||
const now = new Date()
|
||||
const diffMs = now.getTime() - date.getTime()
|
||||
const diffMins = Math.floor(diffMs / (1000 * 60))
|
||||
const diffHours = Math.floor(diffMs / (1000 * 60 * 60))
|
||||
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24))
|
||||
|
||||
if (diffMins < 1) return '刚刚'
|
||||
if (diffMins < 60) return `${diffMins}分钟前`
|
||||
if (diffHours < 24) return `${diffHours}小时前`
|
||||
if (diffDays < 7) return `${diffDays}天前`
|
||||
|
||||
return date.toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 加载统计数据
|
||||
loadStats()
|
||||
|
||||
// 加载最近活动
|
||||
loadRecentActivities()
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -207,6 +180,12 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 1200px) {
|
||||
.stats-grid {
|
||||
--n-grid-cols: 3;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-page {
|
||||
padding: 0 12px;
|
||||
@ -214,11 +193,7 @@ onMounted(() => {
|
||||
|
||||
.stats-grid {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
|
||||
.recent-activities {
|
||||
margin-bottom: 16px;
|
||||
--n-grid-cols: 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,10 +205,9 @@ onMounted(() => {
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.recent-activities {
|
||||
margin-bottom: 24px;
|
||||
|
||||
.stats-grid {
|
||||
--n-grid-cols: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user