update:优化最近对话时间

This commit is contained in:
hrz
2025-05-07 22:56:51 +08:00
parent d07feb837d
commit 571080c1d6
4 changed files with 38 additions and 13 deletions
+20 -1
View File
@@ -31,7 +31,7 @@
</div>
</div>
<div class="version-info">
<div>最近对话{{ device.lastConnectedAt }}</div>
<div>最近对话{{ formattedLastConnectedTime }}</div>
</div>
</div>
</template>
@@ -45,6 +45,25 @@ export default {
data() {
return { switchValue: false }
},
computed: {
formattedLastConnectedTime() {
if (!this.device.lastConnectedAt) return '暂未对话';
const lastTime = new Date(this.device.lastConnectedAt);
const now = new Date();
const diffMinutes = Math.floor((now - lastTime) / (1000 * 60));
if (diffMinutes < 60) {
return `${diffMinutes}分钟前`;
} else if (diffMinutes < 24 * 60) {
const hours = Math.floor(diffMinutes / 60);
const minutes = diffMinutes % 60;
return `${hours}小时${minutes > 0 ? minutes + '分钟' : ''}`;
} else {
return this.device.lastConnectedAt;
}
}
},
methods: {
handleDelete() {
this.$emit('delete', this.device.agentId)