<route lang="jsonc" type="page">
|
{
|
"layout": "default",
|
"style": {
|
"navigationBarTitleText": "执行记录",
|
"navigationStyle": "custom"
|
}
|
}
|
</route>
|
|
<script lang="ts" setup>
|
import type { ParentHistoryItem } from '@/api/parent'
|
import { onLoad, onShow } from '@dcloudio/uni-app'
|
import { ref } from 'vue'
|
import { getParentHistory } from '@/api/parent'
|
import { t } from '@/i18n'
|
import { durationMsOf, formatDuration, formatStartedAt, sourceLabel, statusLabel } from './historyText'
|
|
defineOptions({
|
name: 'ParentHistoryList',
|
})
|
|
const agentId = ref('')
|
const macAddress = ref('')
|
const items = ref<ParentHistoryItem[]>([])
|
const loading = ref(false)
|
|
function goBack() {
|
uni.navigateBack()
|
}
|
|
async function loadHistory() {
|
if (!agentId.value || !macAddress.value) {
|
items.value = []
|
return
|
}
|
loading.value = true
|
try {
|
const result = await getParentHistory(macAddress.value, agentId.value, 50)
|
items.value = result?.list || []
|
}
|
catch (error) {
|
console.error('load parent history failed', error)
|
items.value = []
|
}
|
finally {
|
loading.value = false
|
}
|
}
|
|
function goDetail(item: ParentHistoryItem) {
|
uni.navigateTo({
|
url: `/pages/parent-task/history-detail?id=${encodeURIComponent(item.id)}&agentId=${encodeURIComponent(agentId.value)}&macAddress=${encodeURIComponent(macAddress.value)}`,
|
})
|
}
|
|
function itemMeta(item: ParentHistoryItem) {
|
const bits = [
|
formatStartedAt(item.startedAt),
|
formatDuration(durationMsOf(item), t),
|
sourceLabel(item.source, t),
|
item.kind === 'shadowing' && item.turnCount > 0 ? t('parentHistory.turns', { n: item.turnCount }) : '',
|
].filter(Boolean)
|
return bits.join(' · ')
|
}
|
|
onLoad((options) => {
|
if (options?.agentId)
|
agentId.value = String(options.agentId)
|
if (options?.macAddress)
|
macAddress.value = decodeURIComponent(String(options.macAddress))
|
})
|
|
onShow(() => {
|
loadHistory()
|
})
|
</script>
|
|
<template>
|
<view class="history-page">
|
<wd-navbar :title="t('parentHistory.pageTitle')" safe-area-inset-top>
|
<template #left>
|
<wd-icon name="arrow-left" size="18" @click="goBack" />
|
</template>
|
</wd-navbar>
|
|
<view v-if="loading && items.length === 0" class="flex flex-col items-center py-[80rpx]">
|
<wd-loading color="#336cff" />
|
<text class="mt-[16rpx] text-[28rpx] text-[#666]">
|
{{ t('common.loading') }}
|
</text>
|
</view>
|
|
<view v-else-if="items.length === 0" class="px-[40rpx] py-[80rpx] text-center">
|
<text class="text-[30rpx] text-[#666]">
|
{{ t('parentHistory.empty') }}
|
</text>
|
</view>
|
|
<view v-else class="px-[20rpx] py-[16rpx]">
|
<view
|
v-for="item in items"
|
:key="item.id"
|
class="mb-[16rpx] rounded-[20rpx] border-[1rpx] border-[#eeeeee] bg-white p-[28rpx]"
|
@click="goDetail(item)"
|
>
|
<view class="mb-[8rpx] flex items-center justify-between">
|
<text class="text-[32rpx] text-[#232338] font-semibold">
|
{{ item.sceneName || item.scene }}
|
</text>
|
<text
|
class="rounded-[8rpx] px-[12rpx] py-[4rpx] text-[22rpx] text-white"
|
:class="item.status === 'completed' ? 'bg-[#2ba471]' : item.status === 'running' ? 'bg-[#336cff]' : 'bg-[#9d9ea3]'"
|
>
|
{{ statusLabel(item, t) }}
|
</text>
|
</view>
|
<text class="text-[26rpx] text-[#65686f]">
|
{{ itemMeta(item) }}
|
</text>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<style scoped>
|
.history-page {
|
min-height: 100%;
|
background: #f5f7fb;
|
}
|
</style>
|