feat: 完善发布运维前端体验
This commit is contained in:
+106
-26
@@ -3,10 +3,10 @@
|
||||
* 发布中心负责创建发布单、展示真实 Gitea ref 摘要并同步 Jenkins 状态。
|
||||
*/
|
||||
import { CircleClose, Promotion, RefreshRight, VideoPause } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import BpmnStatusViewer from '../components/BpmnStatusViewer.vue'
|
||||
import PipelineStatusViewer from '../components/PipelineStatusViewer.vue'
|
||||
import RunExecutionDetails from '../components/RunExecutionDetails.vue'
|
||||
import StatusPill from '../components/StatusPill.vue'
|
||||
import { isDevopsApiError } from '../services/http'
|
||||
@@ -333,8 +333,16 @@ const preflightSummary = computed(() => {
|
||||
return '关键检查均已通过'
|
||||
})
|
||||
|
||||
const contextRuns = computed(() => {
|
||||
return platform.runs.filter((run) => matchesReleaseContext(run))
|
||||
})
|
||||
|
||||
const shownRun = computed(() => {
|
||||
return activeRun.value || platform.runs[0]
|
||||
if (activeRun.value && matchesReleaseContext(activeRun.value)) {
|
||||
return activeRun.value
|
||||
}
|
||||
|
||||
return contextRuns.value[0]
|
||||
})
|
||||
|
||||
const canSyncJenkins = computed(() => {
|
||||
@@ -357,6 +365,20 @@ const canRetryShownRun = computed(
|
||||
)
|
||||
|
||||
async function triggerRelease() {
|
||||
if (!canTrigger.value) {
|
||||
ElMessage.warning(triggerDisabledReason.value || '发布参数不完整')
|
||||
return
|
||||
}
|
||||
|
||||
const confirmed = await confirmReleaseAction(
|
||||
form.environment === 'production' ? '确认触发生产发布' : '确认触发发布',
|
||||
`即将发布 ${selectedProject.value?.name || form.projectKey} / ${form.environment} / ${form.ref}。提交后会创建后端发布单并进入 Jenkins 执行链路。`,
|
||||
)
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const run = await platform.createDeployRun({
|
||||
@@ -444,12 +466,22 @@ async function cancelRelease() {
|
||||
return
|
||||
}
|
||||
|
||||
const run = shownRun.value
|
||||
const confirmed = await confirmReleaseAction(
|
||||
'确认取消发布单',
|
||||
`将取消 ${run.projectName} / ${run.environment} 的发布单 ${run.id}。该操作会写入审计日志。`,
|
||||
)
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
const runId = shownRun.value.id
|
||||
const runId = run.id
|
||||
try {
|
||||
const run = await platform.cancelDeployRun(shownRun.value)
|
||||
activeRun.value = run
|
||||
localStatus.value = run.status
|
||||
const canceled = await platform.cancelDeployRun(run)
|
||||
activeRun.value = canceled
|
||||
localStatus.value = canceled.status
|
||||
ElMessage.success('发布单已取消')
|
||||
} catch (error) {
|
||||
await handleReleaseActionError(error, '发布单取消失败', runId)
|
||||
@@ -463,12 +495,22 @@ async function retryRelease() {
|
||||
return
|
||||
}
|
||||
|
||||
const run = shownRun.value
|
||||
const confirmed = await confirmReleaseAction(
|
||||
'确认重试发布单',
|
||||
`将基于 ${run.projectName} / ${run.environment} 的发布单 ${run.id} 发起重试。`,
|
||||
)
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
const runId = shownRun.value.id
|
||||
const runId = run.id
|
||||
try {
|
||||
const run = await platform.retryDeployRun(shownRun.value)
|
||||
activeRun.value = run
|
||||
localStatus.value = run.status
|
||||
const retried = await platform.retryDeployRun(run)
|
||||
activeRun.value = retried
|
||||
localStatus.value = retried.status
|
||||
ElMessage.success('已提交重试发布单')
|
||||
} catch (error) {
|
||||
await handleReleaseActionError(error, '发布单重试失败', runId)
|
||||
@@ -482,12 +524,22 @@ async function syncJenkinsRun() {
|
||||
return
|
||||
}
|
||||
|
||||
const run = shownRun.value
|
||||
const confirmed = await confirmReleaseAction(
|
||||
'确认同步 Jenkins 状态',
|
||||
`将从后端同步发布单 ${run.id} 的 Jenkins queue/build 状态。`,
|
||||
)
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
const runId = shownRun.value.id
|
||||
const runId = run.id
|
||||
try {
|
||||
const run = await platform.syncJenkinsRun(shownRun.value)
|
||||
activeRun.value = run
|
||||
localStatus.value = run.status
|
||||
const synced = await platform.syncJenkinsRun(run)
|
||||
activeRun.value = synced
|
||||
localStatus.value = synced.status
|
||||
ElMessage.success('已同步 Jenkins 状态')
|
||||
} catch (error) {
|
||||
await handleReleaseActionError(error, 'Jenkins 状态同步失败', runId)
|
||||
@@ -527,6 +579,24 @@ function queryProjectKey(): string {
|
||||
return typeof route.query.projectKey === 'string' ? route.query.projectKey : ''
|
||||
}
|
||||
|
||||
function matchesReleaseContext(run: ReleaseRun): boolean {
|
||||
return run.projectKey === form.projectKey && run.environment === form.environment
|
||||
}
|
||||
|
||||
async function confirmReleaseAction(title: string, message: string): Promise<boolean> {
|
||||
try {
|
||||
await ElMessageBox.confirm(message, title, {
|
||||
confirmButtonText: '确认执行',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
autofocus: false,
|
||||
})
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleReleaseActionError(
|
||||
error: unknown,
|
||||
fallbackMessage: string,
|
||||
@@ -536,7 +606,7 @@ async function handleReleaseActionError(
|
||||
const refreshedRuns = await platform.refreshRuns()
|
||||
const refreshedRun = runId
|
||||
? refreshedRuns.find((run) => run.id === runId)
|
||||
: refreshedRuns[0]
|
||||
: refreshedRuns.find((run) => matchesReleaseContext(run))
|
||||
|
||||
if (refreshedRun) {
|
||||
activeRun.value = refreshedRun
|
||||
@@ -805,20 +875,23 @@ watch(
|
||||
<div class="panel-body" v-if="shownRun">
|
||||
<RunExecutionDetails :run="shownRun" />
|
||||
</div>
|
||||
<div v-else class="panel-body release-empty-state">
|
||||
<ElEmpty description="当前项目和环境暂无发布单" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel bpmn-status-panel">
|
||||
<section class="panel pipeline-status-panel">
|
||||
<div class="panel-header">
|
||||
<h2>BPMN 流程状态</h2>
|
||||
<span>step.bpmnNodeId 与 BPMN XML 节点 id 对齐后高亮</span>
|
||||
<h2>发布步骤轨迹</h2>
|
||||
<span>以后端 run steps 为准展示节点状态、输出和 Jenkins 日志</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<BpmnStatusViewer
|
||||
v-if="platform.releaseProcessXml && shownRun"
|
||||
:xml="platform.releaseProcessXml"
|
||||
<PipelineStatusViewer
|
||||
v-if="shownRun"
|
||||
:run="shownRun"
|
||||
:steps="shownRun.steps"
|
||||
/>
|
||||
<ElEmpty v-else description="暂无可查看的发布步骤" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -835,11 +908,11 @@ watch(
|
||||
|
||||
.release-params-panel,
|
||||
.current-run-panel,
|
||||
.bpmn-status-panel {
|
||||
.pipeline-status-panel {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.bpmn-status-panel {
|
||||
.pipeline-status-panel {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@@ -858,10 +931,17 @@ watch(
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.bpmn-status-panel .panel-body {
|
||||
.pipeline-status-panel .panel-body {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.release-empty-state {
|
||||
display: flex;
|
||||
min-height: 180px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.current-run-panel :deep(.run-execution-details) {
|
||||
gap: 12px;
|
||||
}
|
||||
@@ -1152,7 +1232,7 @@ watch(
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.bpmn-status-panel {
|
||||
.pipeline-status-panel {
|
||||
grid-column: auto;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user