refactor(intelligent-agent): 重构智能体日志与概览页面

- 重写 API 接口,使用 echartsAllData替代 dailyConversations
-优化 overview 组件,添加时间范围选择功能
- 修改 lineEcharts 组件,动态加载数据
- 调整 index 组件布局和样式
- 优化智能体列表展示和跳转逻辑
This commit is contained in:
陈昱达
2025-05-08 14:14:15 +08:00
parent b565c90150
commit fb5bcc16b9
5 changed files with 273 additions and 219 deletions

View File

@@ -17,9 +17,9 @@
style="flex-wrap: wrap"
>
<line-echarts
:key="item.options.title.subtext + index"
v-for="(item, index) in list"
:options="item.options"
:key="item.options.title.subtext + index"
style="width: calc(50% - 10px);height: 300px"
></line-echarts>
</div>
@@ -27,176 +27,14 @@
</template>
<script>
import LineEcharts from '@/views/intelligent-agent/children/Logs&overview/components/lineEcharts.vue'
import { dailyConversations } from './API'
import { echartsAllData } from './API'
import '@/assets/js/business-common'
export default {
name: 'overveiw',
data() {
return {
times: '9',
list: [
{
options: {
title: {
seriesName: '全部会话数', // 系列名称
text: '全部会话数',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: '会话数',
data: [820, 932, 901, 934, 1290, 1330, 1320],
itemStyle: {
color: '#0694A2'
},
areaStyle: {
color: [
{ offset: 0, color: '#0694A2' },
{
offset: 1,
color: '#F3F9FA'
}
]
}
}
]
}
},
{
options: {
title: {
text: '活跃用户数',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: '活跃用户',
data: [820, 932, 901, 934, 1290, 430, 9000],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
options: {
title: {
text: '平均会话互动数',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: '平均会话互动数',
data: [20, 52, 1, 55, 666, 1330, 55],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
options: {
title: {
text: 'Token 输出速度',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: 'Token 输出速度',
data: [300, 555, 444, 22, 11, 333, 1],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
options: {
title: {
text: '用户满意度',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: '用户满意度',
data: [200, 300, 400, 444, 500, 555, 521],
itemStyle: {
color: '#1C64F1'
},
areaStyle: {
color: [
{ offset: 0, color: '#1C64F1' },
{ offset: 1, color: '#E3ECFD' }
]
}
}
]
}
},
{
options: {
title: {
text: '费用消耗',
subtext: '所有时间'
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
series: [
{
name: '费用消耗',
data: [820, 932, 901, 934, 1290, 200, 500],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
}
],
list: [],
options: [
{
label: '今天',
@@ -244,35 +82,80 @@ export default {
},
filters: {},
methods: {
changeTime(value) {
let label = this.findLabel(value)
this.list = this.list.map(item => {
return {
options: {
tooltip: {
trigger: 'axis',
backgroundColor: 'rgba(255,255,255,0.9)',
borderColor: '#ccc',
textStyle: {
color: '#333'
},
/**
* 根据 value 返回对应的时间范围
* @param {string} value - 选项值,如 '2', '3', ..., '8'
* @returns {{startDate: string, endDate: string}}
*/
getDateRangeByValue(value) {
const today = new Date()
formatter: params => {
console.log(params)
return (
`${params[0].axisValue} ${params[0].marker}<br/>` +
params.map(p => `${p.seriesName}${p.value}`).join('<br/>')
)
}
},
...item.options,
title: {
...item.options.title,
subtext: label
}
}
}
})
// 辅助函数:格式化日期为 yyyy-MM-dd
function formatDate(date) {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${d}`
}
let startDate = ''
let endDate = ''
switch (value) {
case '1': // 今天
endDate = startDate = formatDate(today)
break
case '2': // 过去7天
startDate = formatDate(
new Date(today.getTime() - 6 * 24 * 60 * 60 * 1000)
)
endDate = formatDate(today)
break
case '3': // 过去4周28天
startDate = formatDate(
new Date(today.getTime() - 27 * 24 * 60 * 60 * 1000)
)
endDate = formatDate(today)
break
case '4': // 过去3个月约90天
startDate = formatDate(
new Date(today.getTime() - 89 * 24 * 60 * 60 * 1000)
)
endDate = formatDate(today)
break
case '5': // 过去12个月约365天
startDate = formatDate(
new Date(today.getTime() - 364 * 24 * 60 * 60 * 1000)
)
endDate = formatDate(today)
break
case '6': // 本月至今
startDate = formatDate(
new Date(today.getFullYear(), today.getMonth(), 1)
)
endDate = formatDate(today)
break
case '7': // 本季度至今
const quarterStartMonth = Math.floor(today.getMonth() / 3) * 3
startDate = formatDate(
new Date(today.getFullYear(), quarterStartMonth, 1)
)
endDate = formatDate(today)
break
case '8': // 本年至今
startDate = formatDate(new Date(today.getFullYear(), 0, 1))
endDate = formatDate(today)
break
default:
startDate = endDate = formatDate(today)
break
}
return { startDate, endDate }
},
changeTime(value) {
this.getEcharts()
},
// 查找label
findLabel(value) {
@@ -281,10 +164,183 @@ export default {
).label
},
async getEcharts() {
// let dailyConversationsApi = await dailyConversations({
// id: '27f6f211-6c74-4de8-9424-c1ba28d365c2'
// })
// console.log(dailyConversationsApi)
let list = [
{
code: 'conversationCount',
options: {
title: {
seriesName: '全部会话数', // 系列名称
text: '全部会话数',
subtext: '所有时间'
},
xAxis: {
data: []
},
series: [
{
name: '会话数',
data: [],
itemStyle: {
color: '#0694A2'
},
areaStyle: {
color: [
{ offset: 0, color: '#0694A2' },
{
offset: 1,
color: '#F3F9FA'
}
]
}
}
]
}
},
{
code: 'terminalCount',
options: {
title: {
text: '活跃用户数',
subtext: '所有时间'
},
xAxis: {
data: []
},
series: [
{
name: '活跃用户',
data: [],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
code: 'interactions',
options: {
title: {
text: '平均会话互动数',
subtext: '所有时间'
},
xAxis: {
data: []
},
series: [
{
name: '平均会话互动数',
data: [],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
code: 'tps',
options: {
title: {
text: 'Token 输出速度',
subtext: '所有时间'
},
xAxis: {
data: []
},
series: [
{
name: 'Token 输出速度',
data: [],
itemStyle: {
color: '#FF8A4C'
},
areaStyle: {
color: [
{ offset: 0, color: '#FF8A4C' },
{ offset: 1, color: '#FFF6F1' }
]
}
}
]
}
},
{
code: 'interactions',
options: {
title: {
text: '平均每个会话交互次数',
subtext: '所有时间'
},
xAxis: {
data: []
},
series: [
{
name: '平均每个会话交互次数',
data: [],
itemStyle: {
color: '#1C64F1'
},
areaStyle: {
color: [
{ offset: 0, color: '#1C64F1' },
{ offset: 1, color: '#E3ECFD' }
]
}
}
]
}
}
]
let query = {
appId: this.$route.query.appId
}
if (this.times !== '9') {
let times = this.getDateRangeByValue(this.times)
query.startDate = times.startDate
query.endDate = times.endDate
}
let { content } = await echartsAllData(query)
let x = []
let obj = {}
content.content.map(item => {
x.push(item.date)
for (let itemKey in item) {
obj[itemKey] = obj[itemKey] ? obj[itemKey] : []
obj[itemKey].push(item[itemKey])
}
})
let label = this.findLabel(this.times)
list.map(item => {
item.options.xAxis.data = x
for (let keys in obj) {
if (keys === item.code) {
item.options.series[0].data = obj[keys]
}
}
item.options.title = {
...item.options.title,
subtext: label
}
})
this.list = JSON.parse(JSON.stringify(list))
}
},
created() {},