Skip to content

Commit 8e36376

Browse files
authored
Merge pull request #52 from aice030/fix/36
Fix/36(View&Controller): 修改了服务详情页面,改成了新样式
2 parents 39b66f7 + bcc7694 commit 8e36376

File tree

2 files changed

+175
-51
lines changed

2 files changed

+175
-51
lines changed

client/src/mock/services.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface DeploymentPlan {
206206
id: string
207207
service: string
208208
version: string
209-
status: 'InDeployment' | 'rollbacked' | 'completed'
209+
status: 'Schedule' | 'InDeployment' | 'Finished'
210210
scheduleTime?: string
211211
finishTime?: string
212212
isPaused?: boolean
@@ -240,7 +240,8 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
240240
id: "1003",
241241
service: "s3",
242242
version: "v1.0.3",
243-
status: "completed",
243+
status: "Finished",
244+
scheduleTime: "2024-01-14T09:00:00Z",
244245
finishTime: "2024-01-14T18:00:00Z"
245246
}
246247
]
@@ -267,14 +268,7 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
267268
id: "2003",
268269
service: "stg",
269270
version: "v1.0.3",
270-
status: "completed",
271-
finishTime: "2024-01-03T05:00:00Z"
272-
},
273-
{
274-
id: "2004",
275-
service: "stg",
276-
version: "v1.0.3",
277-
status: "rollbacked",
271+
status: "Finished",
278272
finishTime: "2024-01-03T05:00:00Z"
279273
}
280274
]
@@ -292,7 +286,7 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
292286
id: "3002",
293287
service: "meta",
294288
version: "v1.0.5",
295-
status: "completed",
289+
status: "Finished",
296290
finishTime: "2024-01-16T15:30:00Z"
297291
}
298292
]
@@ -310,7 +304,7 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
310304
id: "4002",
311305
service: "mq",
312306
version: "v1.0.3",
313-
status: "rollbacked",
307+
status: "Finished",
314308
finishTime: "2024-01-17T20:00:00Z"
315309
}
316310
]
@@ -328,7 +322,7 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
328322
id: "5002",
329323
service: "worker",
330324
version: "v1.0.3",
331-
status: "completed",
325+
status: "Finished",
332326
finishTime: "2024-01-18T16:00:00Z"
333327
},
334328
{
@@ -353,7 +347,7 @@ export const mockDeploymentPlans: Record<string, DeploymentPlansResponse> = {
353347
id: "6002",
354348
service: "mongodb",
355349
version: "v1.0.3",
356-
status: "completed",
350+
status: "Finished",
357351
finishTime: "2024-01-19T11:00:00Z"
358352
}
359353
]

client/src/views/HomeView.vue

Lines changed: 167 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@
173173
</el-tag>
174174
</template>
175175
</el-table-column>
176+
<el-table-column width="120">
177+
<template #default="{ row }">
178+
<div class="table-actions">
179+
<span
180+
:class="['action-link', row.isPaused ? 'continue' : 'pause']"
181+
@click="togglePauseResumeForVersion(row)"
182+
>
183+
{{ row.isPaused ? '继续' : '暂停' }}
184+
</span>
185+
<span
186+
class="action-link rollback"
187+
@click="rollbackVersion(row)"
188+
>
189+
回滚
190+
</span>
191+
</div>
192+
</template>
193+
</el-table-column>
176194
<template #empty>
177195
<div class="no-data">暂无数据</div>
178196
</template>
@@ -224,38 +242,27 @@
224242
<div>{{ plan.time }}</div>
225243
<div>状态:
226244
<el-tag
227-
:type="plan.originalStatus === 'completed' ? 'success' :
228-
plan.originalStatus === 'rollbacked' ? 'danger' : 'warning'"
245+
:type="plan.originalStatus === 'Finished' ? 'success' :
246+
plan.originalStatus === 'Schedule' ? 'info' : 'warning'"
229247
size="small"
230248
>
231249
{{ plan.status }}
232250
</el-tag>
233251
</div>
234252
</div>
235253
</div>
236-
<!-- 未开始的发布计划:编辑、取消 -->
237-
<div class="plan-actions" v-if="plan.originalStatus !== 'completed' && plan.originalStatus !== 'rollbacked' && (!plan.scheduleTime || plan.scheduleTime === '')">
238-
<div class="action-column">
239-
<el-button size="small" @click="editRelease(plan)">编辑</el-button>
240-
<el-button size="small" type="danger" @click="confirmCancel(plan)">取消</el-button>
241-
</div>
242-
</div>
243-
244-
<!-- 部署中的发布计划:暂停/继续、回滚、取消 -->
245-
<div class="plan-actions" v-else-if="plan.originalStatus === 'InDeployment' && !plan.isPaused">
254+
<!-- 待发布和发布中的计划:编辑、取消 -->
255+
<div class="plan-actions" v-if="plan.originalStatus === 'Schedule' || plan.originalStatus === 'InDeployment'">
246256
<div class="action-column">
247-
<el-button size="small" type="warning" @click="togglePauseResume(plan)">暂停</el-button>
248-
<el-button size="small" type="info" @click="rollbackRelease(plan)">回滚</el-button>
249-
<el-button size="small" type="danger" @click="confirmCancel(plan)">取消</el-button>
257+
<span class="action-link edit" @click="editRelease(plan)">编辑</span>
258+
<span class="action-link cancel" @click="confirmCancel(plan)">取消</span>
250259
</div>
251260
</div>
252261

253-
<!-- 暂停中的发布计划:继续、回滚、取消 -->
254-
<div class="plan-actions" v-else-if="plan.originalStatus === 'InDeployment' && plan.isPaused">
262+
<!-- 已完成的计划:只显示状态,无操作按钮 -->
263+
<div class="plan-actions" v-else-if="plan.originalStatus === 'Finished'">
255264
<div class="action-column">
256-
<el-button size="small" type="success" @click="togglePauseResume(plan)">继续</el-button>
257-
<el-button size="small" type="info" @click="rollbackRelease(plan)">回滚</el-button>
258-
<el-button size="small" type="danger" @click="confirmCancel(plan)">取消</el-button>
265+
<span class="completed-text">已完成</span>
259266
</div>
260267
</div>
261268
</div>
@@ -744,9 +751,9 @@ const deploymentPlansForDisplay = computed(() => {
744751
return currentServiceDeploymentPlans.value.items.map(plan => {
745752
// 状态映射
746753
const statusMap = {
754+
'Schedule': '待发布',
747755
'InDeployment': '部署中',
748-
'completed': '已完成',
749-
'rollbacked': '已回滚'
756+
'Finished': '已完成'
750757
}
751758
752759
// 时间格式化
@@ -771,7 +778,7 @@ const deploymentPlansForDisplay = computed(() => {
771778
} else {
772779
return '已开始'
773780
}
774-
case 'completed':
781+
case 'Finished':
775782
// 已完成:显示开始时间 → 结束时间
776783
if (plan.scheduleTime && plan.finishTime) {
777784
return `开始时间: ${formatTime(plan.scheduleTime)} → 结束时间: ${formatTime(plan.finishTime)}`
@@ -780,15 +787,6 @@ const deploymentPlansForDisplay = computed(() => {
780787
} else {
781788
return '已完成'
782789
}
783-
case 'rollbacked':
784-
// 已回滚:显示开始时间 → 回滚时间
785-
if (plan.scheduleTime && plan.finishTime) {
786-
return `开始时间: ${formatTime(plan.scheduleTime)} → 回滚时间: ${formatTime(plan.finishTime)}`
787-
} else if (plan.finishTime) {
788-
return `回滚时间: ${formatTime(plan.finishTime)}`
789-
} else {
790-
return '已回滚'
791-
}
792790
default:
793791
return '未知状态'
794792
}
@@ -967,7 +965,21 @@ const transformMetricsToTableData = (versions: any[], metricsResponse: ServiceMe
967965
}
968966
969967
const getVersionTableData = (versions: any[]) => {
970-
return transformMetricsToTableData(versions, currentServiceMetrics.value)
968+
const tableData = transformMetricsToTableData(versions, currentServiceMetrics.value)
969+
970+
// 为每个版本添加部署状态信息(用于操作按钮)
971+
return tableData.map(version => {
972+
// 检查是否有正在进行的部署
973+
const activeDeployment = currentServiceDeploymentPlans.value?.items?.find((plan: any) =>
974+
plan.version === version.version && plan.status === 'InDeployment'
975+
)
976+
977+
return {
978+
...version,
979+
isPaused: activeDeployment?.isPaused || false,
980+
deployId: activeDeployment?.id || version.version // 如果没有deployId,使用version作为标识
981+
}
982+
})
971983
}
972984
973985
const handleCloseDialog = () => {
@@ -1094,6 +1106,44 @@ const rollbackRelease = async (plan: any) => {
10941106
}
10951107
}
10961108
1109+
// 版本表格中的操作
1110+
const togglePauseResumeForVersion = async (version: any) => {
1111+
try {
1112+
if (version.isPaused) {
1113+
await mockApi.continueDeployment(version.deployId)
1114+
ElMessage.success('继续部署成功')
1115+
// 更新本地状态
1116+
version.isPaused = false
1117+
} else {
1118+
await mockApi.pauseDeployment(version.deployId)
1119+
ElMessage.success('暂停部署成功')
1120+
// 更新本地状态
1121+
version.isPaused = true
1122+
}
1123+
// 刷新服务详情数据
1124+
if (selectedNode.value) {
1125+
await loadServiceDetail(selectedNode.value.name)
1126+
}
1127+
} catch (error) {
1128+
console.error('操作失败:', error)
1129+
ElMessage.error('操作失败')
1130+
}
1131+
}
1132+
1133+
const rollbackVersion = async (version: any) => {
1134+
try {
1135+
await mockApi.rollbackDeployment(version.deployId)
1136+
ElMessage.success('回滚成功')
1137+
// 刷新服务详情数据
1138+
if (selectedNode.value) {
1139+
await loadServiceDetail(selectedNode.value.name)
1140+
}
1141+
} catch (error) {
1142+
console.error('回滚失败:', error)
1143+
ElMessage.error('回滚失败')
1144+
}
1145+
}
1146+
10971147
// 初始化饼图
10981148
let pieChart: echarts.ECharts | null = null
10991149
@@ -1654,16 +1704,96 @@ const disposeMetricsCharts = () => {
16541704
16551705
.plan-actions {
16561706
display: flex;
1657-
justify-content: flex-end;
1707+
justify-content: flex-start;
16581708
align-items: flex-end;
16591709
min-width: 100px;
1710+
padding-left: 10px;
16601711
}
16611712
16621713
.action-column {
16631714
display: flex;
1664-
flex-direction: column;
1665-
gap: 4px;
1666-
align-items: flex-end;
1715+
flex-direction: row;
1716+
gap: 8px;
1717+
align-items: center;
1718+
}
1719+
1720+
/* 表格操作样式 */
1721+
.table-actions {
1722+
display: flex;
1723+
gap: 8px;
1724+
align-items: center;
1725+
justify-content: flex-end;
1726+
padding-right: 10px;
1727+
}
1728+
1729+
.action-link {
1730+
cursor: pointer;
1731+
font-size: 12px;
1732+
text-decoration: none;
1733+
padding: 2px 4px;
1734+
border-radius: 2px;
1735+
transition: all 0.2s;
1736+
}
1737+
1738+
.action-link:hover {
1739+
opacity: 0.8;
1740+
}
1741+
1742+
/* 暂停按钮 - 黄色 */
1743+
.action-link.pause {
1744+
color: #e6a23c;
1745+
}
1746+
1747+
.action-link.pause:hover {
1748+
background-color: #fdf6ec;
1749+
}
1750+
1751+
/* 继续按钮 - 绿色 */
1752+
.action-link.continue {
1753+
color: #67c23a;
1754+
}
1755+
1756+
.action-link.continue:hover {
1757+
background-color: #f0f9ff;
1758+
}
1759+
1760+
/* 编辑按钮 - 黑色 */
1761+
.action-link.edit {
1762+
color: #303133;
1763+
}
1764+
1765+
.action-link.edit:hover {
1766+
background-color: #f5f7fa;
1767+
}
1768+
1769+
/* 取消按钮 - 红色 */
1770+
.action-link.cancel {
1771+
color: #f56c6c;
1772+
}
1773+
1774+
.action-link.cancel:hover {
1775+
background-color: #fef0f0;
1776+
}
1777+
1778+
/* 回滚按钮 - 蓝色(保持原有颜色) */
1779+
.action-link.rollback {
1780+
color: #409eff;
1781+
}
1782+
1783+
.action-link.rollback:hover {
1784+
background-color: #ecf5ff;
1785+
}
1786+
1787+
.action-link:not(:last-child)::after {
1788+
content: '|';
1789+
margin-left: 8px;
1790+
color: #dcdfe6;
1791+
}
1792+
1793+
.completed-text {
1794+
color: #67c23a;
1795+
font-size: 12px;
1796+
font-weight: 500;
16671797
}
16681798
16691799
.no-plans {

0 commit comments

Comments
 (0)