仰望星辰工作室

miaopanel

miaopanel/ web/src/components/docker/ContainerLogsModal.vue 1.7 KB · 62 行 原始文件
1<script setup lang="ts">
2import { inject, onMounted, ref } from 'vue'
3import { api } from '../../api'
4import type { DockerContainer } from '../../types'
5
6const props = defineProps<{ container: DockerContainer }>()
7const emit = defineEmits<{ (e: 'close'): void }>()
8const notify = inject<(text: string, kind?: 'ok' | 'error') => void>('notify')!
9
10const logs = ref('')
11const loading = ref(false)
12
13async function load() {
14 loading.value = true
15 try {
16 const res = await api.get<{ logs: string }>(
17 `api/v1/docker/containers/${encodeURIComponent(props.container.id)}/logs?tail=300`,
18 )
19 logs.value = res.logs || '(暂无日志)'
20 } catch (e) {
21 notify((e as Error).message, 'error')
22 } finally {
23 loading.value = false
24 }
25}
26
27onMounted(load)
28</script>
29
30<template>
31 <div class="overlay" @click.self="emit('close')">
32 <div class="modal" style="width: min(900px, 100%)">
33 <div class="modal-head">
34 <h3>容器日志 · {{ container.name }}</h3>
35 <button class="icon-btn" title="关闭" @click="emit('close')">×</button>
36 </div>
37 <div class="row" style="margin-bottom: 10px">
38 <span class="hint mono">{{ container.image }}</span>
39 <div class="spacer"></div>
40 <button class="btn btn-ghost btn-sm" :disabled="loading" @click="load">
41 <span v-if="loading" class="spin"></span>
42 刷新
43 </button>
44 </div>
45 <pre class="log-box mono">{{ loading ? '正在读取…' : logs }}</pre>
46 </div>
47 </div>
48</template>
49
50<style scoped>
51.log-box {
52 margin: 0;
53 padding: 12px 14px;
54 height: 420px;
55 overflow: auto;
56 border-radius: 10px;
57 border: 1px solid var(--line);
58 background: #f7fcfb;
59 font-size: 12.5px;
60 white-space: pre-wrap;
61}
62</style>