wangzhibo
10 天以前 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<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>