仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-webpack"></i>一键部署</h3>
6 <p class="td-page-subtitle">选择常用程序,一键部署到您的站点</p>
7 </div>
8 <div class="td-head-actions">
9 <t-button theme="default" variant="outline" @click="load">
10 <i class="mdi mdi-refresh"></i> 刷新
11 </t-button>
12 </div>
13 </div>
14
15 <t-loading :loading="loading" text="加载中…" size="small">
16 <div v-if="rows.length === 0 && !loading" class="td-empty">
17 <i class="mdi mdi-webpack"></i>
18 暂无可部署程序
19 </div>
20
21 <div v-else class="deploy-grid">
22 <div v-for="row in rows" :key="row.id" class="deploy-card">
23 <div class="deploy-card-head">
24 <div class="deploy-thumb" v-if="parseThumb(row.src).length">
25 <img
26 :src="parseThumb(row.src)[0]"
27 :alt="row.name"
28 @error="onImgError"
29 />
30 </div>
31 <div class="deploy-thumb deploy-thumb-empty" v-else>
32 <i class="mdi mdi-package-variant-closed"></i>
33 </div>
34 <div class="deploy-name">
35 <strong>{{ row.name || '-' }}</strong>
36 <span>{{ fmtSize(row.cxdx) }}</span>
37 </div>
38 </div>
39 <div class="deploy-card-body">
40 <p class="deploy-desc">{{ row.jc || row.desc || '暂无介绍' }}</p>
41 <div class="deploy-meta">
42 <span class="td-chip td-chip-info" v-if="row.webkj">
43 <i class="mdi mdi-web"></i> {{ row.webkj }}MB
44 </span>
45 <span class="td-chip td-chip-default" v-if="row.sqlkj">
46 <i class="mdi mdi-database"></i> {{ row.sqlkj }}MB
47 </span>
48 <span class="td-chip td-chip-warning" v-if="row.jg">
49 <i class="mdi mdi-currency-cny"></i> {{ row.jg }}
50 </span>
51 </div>
52 </div>
53 <div class="deploy-card-foot">
54 <t-button
55 theme="primary"
56 :loading="deploying === row.id"
57 :disabled="!!deploying"
58 @click="deploy(row)"
59 >
60 <i class="mdi mdi-rocket-launch"></i> 一键部署
61 </t-button>
62 </div>
63 </div>
64 </div>
65 </t-loading>
66 </div>
67</template>
68
69<script setup>
70import { ref, onMounted } from 'vue'
71import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
72import { listDeployPrograms, deployProgram } from '@/user/api/deploy'
73
74const loading = ref(false)
75const rows = ref([])
76const deploying = ref(null)
77
78function parseThumb(src) {
79 if (!src) return []
80 if (Array.isArray(src)) return src
81 try {
82 const arr = JSON.parse(src)
83 if (Array.isArray(arr)) return arr
84 return [src]
85 } catch {
86 return [src]
87 }
88}
89
90function fmtSize(v) {
91 const n = Number(v) || 0
92 if (n === 0) return ''
93 if (n < 1024) return n + ' MB'
94 return (n / 1024).toFixed(2) + ' GB'
95}
96
97function onImgError(e) {
98 e.target.style.display = 'none'
99}
100
101async function load() {
102 loading.value = true
103 const r = await listDeployPrograms()
104 loading.value = false
105 if (r.ok && r.data) {
106 const d = r.data
107 rows.value = Array.isArray(d) ? d : (d.rows || d.list || d.data || [])
108 } else {
109 rows.value = []
110 }
111}
112
113function deploy(row) {
114 const dlg = DialogPlugin.confirm({
115 header: '一键部署',
116 body: `确定将「${row.name}」部署到当前站点吗?部署会覆盖同名文件。`,
117 confirmBtn: { content: '开始部署', theme: 'primary' },
118 onConfirm: async () => {
119 dlg.destroy()
120 deploying.value = row.id
121 const r = await deployProgram(row.id)
122 deploying.value = null
123 if (r.ok) {
124 const msg = r.message || '部署成功'
125 const alert = row.alerts || row.alert || ''
126 if (alert) {
127 MessagePlugin.success(alert, 5000)
128 } else {
129 MessagePlugin.success(msg)
130 }
131 }
132 },
133 onClose: () => dlg.destroy(),
134 })
135}
136
137onMounted(load)
138</script>
139
140<style scoped>
141.td-head-actions {
142 display: flex;
143 align-items: center;
144 gap: 8px;
145 flex-wrap: wrap;
146}
147.deploy-grid {
148 display: grid;
149 grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
150 gap: 16px;
151}
152.deploy-card {
153 background: var(--td-surface);
154 border: 1px solid var(--td-border);
155 border-radius: var(--td-radius-lg);
156 box-shadow: var(--td-shadow-sm);
157 display: flex;
158 flex-direction: column;
159 overflow: hidden;
160 transition: transform var(--td-dur) var(--td-ease),
161 box-shadow var(--td-dur) var(--td-ease);
162 animation: td-fade-in var(--td-dur-lg) var(--td-ease-out);
163}
164.deploy-card:hover {
165 transform: translateY(-3px);
166 box-shadow: var(--td-shadow-md);
167}
168.deploy-card-head {
169 display: flex;
170 align-items: center;
171 gap: 12px;
172 padding: 14px 16px;
173 border-bottom: 1px solid var(--td-border);
174}
175.deploy-thumb {
176 width: 56px;
177 height: 56px;
178 border-radius: 8px;
179 overflow: hidden;
180 flex-shrink: 0;
181 background: var(--td-bg);
182 display: grid;
183 place-items: center;
184}
185.deploy-thumb img {
186 width: 100%;
187 height: 100%;
188 object-fit: cover;
189}
190.deploy-thumb-empty i {
191 font-size: 28px;
192 color: var(--td-text-placeholder);
193}
194.deploy-name {
195 flex: 1;
196 min-width: 0;
197 display: flex;
198 flex-direction: column;
199}
200.deploy-name strong {
201 font-size: 14px;
202 font-weight: 600;
203 color: var(--td-text);
204 white-space: nowrap;
205 overflow: hidden;
206 text-overflow: ellipsis;
207}
208.deploy-name span {
209 font-size: 11px;
210 color: var(--td-text-placeholder);
211 margin-top: 2px;
212}
213.deploy-card-body {
214 padding: 14px 16px;
215 flex: 1;
216 min-height: 0;
217 display: flex;
218 flex-direction: column;
219 gap: 10px;
220}
221.deploy-desc {
222 margin: 0;
223 font-size: 12px;
224 color: var(--td-text-secondary);
225 line-height: 1.6;
226 display: -webkit-box;
227 -webkit-line-clamp: 3;
228 -webkit-box-orient: vertical;
229 overflow: hidden;
230}
231.deploy-meta {
232 display: flex;
233 flex-wrap: wrap;
234 gap: 6px;
235}
236.deploy-card-foot {
237 padding: 12px 16px;
238 border-top: 1px solid var(--td-border);
239 background: var(--td-bg);
240}
241.deploy-card-foot .t-button {
242 width: 100%;
243}
244
245.td-empty {
246 text-align: center;
247 padding: 48px 16px;
248 color: var(--td-text-placeholder);
249 font-size: 13px;
250}
251.td-empty i {
252 font-size: 36px;
253 display: block;
254 margin-bottom: 8px;
255 color: #cbd5e1;
256}
257</style>