better-staridc-MNBT
1<template>
2 <div class="dk-compose">
3 <t-card>
4 <template #header>
5 <div class="dk-card-hd">
6 <h3>Compose 模板</h3>
7 <t-button theme="default" variant="outline" size="small" @click="load">
8 <i class="mdi mdi-refresh"></i> 刷新
9 </t-button>
10 </div>
11 </template>
12
13 <t-table
14 row-key="name"
15 :data="templates"
16 :columns="tplColumns"
17 :loading="loading"
18 table-layout="auto"
19 stripe
20 bordered
21 >
22 <template #empty>
23 <div class="dk-empty">
24 <i class="mdi mdi-file-document"></i>
25 <p>暂无 Compose 模板</p>
26 </div>
27 </template>
28 </t-table>
29 </t-card>
30
31 <t-card style="margin-top: 16px">
32 <template #header>
33 <div class="dk-card-hd">
34 <h3>Docker 项目</h3>
35 </div>
36 </template>
37
38 <t-table
39 row-key="name"
40 :data="projects"
41 :columns="projColumns"
42 :loading="loading"
43 table-layout="auto"
44 stripe
45 bordered
46 >
47 <template #empty>
48 <div class="dk-empty">
49 <i class="mdi mdi-docker"></i>
50 <p>暂无 Docker 项目</p>
51 </div>
52 </template>
53 </t-table>
54 </t-card>
55 </div>
56</template>
57
58<script setup>
59import { ref, onMounted } from 'vue'
60import { listCompose } from '@/docker/api/docker'
61
62const loading = ref(false)
63const templates = ref([])
64const projects = ref([])
65
66const tplColumns = [
67 { colKey: 'name', title: '模板名称', minWidth: 160 },
68 { colKey: 'desc', title: '描述', minWidth: 260, ellipsis: true },
69 { colKey: 'category', title: '分类', width: 120 },
70]
71
72const projColumns = [
73 { colKey: 'name', title: '项目名', minWidth: 180 },
74 { colKey: 'status', title: '状态', width: 110 },
75 { colKey: 'count', title: '容器数', width: 90, align: 'center' },
76 { colKey: 'updated', title: '更新时间', minWidth: 180 },
77]
78
79function mapRows(list) {
80 if (!Array.isArray(list)) return []
81 return list.map((t) => ({
82 name: t.name || t.title || '-',
83 desc: t.desc || t.description || '-',
84 category: t.category || t.type || '-',
85 }))
86}
87
88async function load() {
89 loading.value = true
90 const r = await listCompose()
91 loading.value = false
92 if (r.ok && r.data) {
93 const btTpl = r.data.templates
94 const tplList = btTpl && btTpl.data ? btTpl.data : btTpl || []
95 templates.value = mapRows(tplList)
96
97 const btProj = r.data.projects
98 const projList = btProj && btProj.data ? btProj.data : btProj || []
99 projects.value = Array.isArray(projList) ? projList.map((p) => ({
100 name: p.name || '-',
101 status: p.status || '-',
102 count: p.container_count ?? p.count ?? '-',
103 updated: p.updated_at || p.time || '-',
104 })) : []
105 }
106}
107
108onMounted(load)
109</script>
110
111<style scoped>
112.dk-card-hd {
113 display: flex;
114 align-items: center;
115 justify-content: space-between;
116 width: 100%;
117}
118.dk-card-hd h3 {
119 margin: 0;
120 font-size: 16px;
121 font-weight: 600;
122}
123.dk-empty {
124 text-align: center;
125 padding: 40px 20px;
126 color: var(--td-text-color-secondary, #6b7280);
127}
128.dk-empty i {
129 font-size: 36px;
130 opacity: 0.5;
131 display: block;
132 margin-bottom: 8px;
133}
134.dk-empty p {
135 margin: 0;
136 font-size: 13px;
137}
138
139/* ========== 移动端 ========== */
140@media (max-width: 768px) {
141 .dk-card-hd { flex-direction: column; gap: 10px; align-items: flex-start; }
142 .dk-compose :deep(.t-table) { font-size: 12px; }
143}
144</style>