feat: 完善运维控制台产品化体验

This commit is contained in:
湛兮
2026-06-12 16:36:20 +08:00
parent 0f92eb7b2b
commit 878125fe76
14 changed files with 2957 additions and 129 deletions
+477 -9
View File
@@ -5,21 +5,31 @@
import { CircleClose, Promotion, RefreshRight, VideoPause } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, reactive, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import BpmnStatusViewer from '../components/BpmnStatusViewer.vue'
import RunExecutionDetails from '../components/RunExecutionDetails.vue'
import StatusPill from '../components/StatusPill.vue'
import { isDevopsApiError } from '../services/http'
import { usePlatformStore } from '../stores/platform'
import type { EnvironmentName, ProjectRefItem, ReleaseRun, ReleaseStatus } from '../types/devops'
import { useSessionStore } from '../stores/session'
import type { EnvironmentName, HealthState, ProjectRefItem, ReleaseRun, ReleaseStatus } from '../types/devops'
const platform = usePlatformStore()
const session = useSessionStore()
const route = useRoute()
const form = reactive({
projectKey: '',
projectKey: queryProjectKey(),
environment: 'test' as EnvironmentName,
ref: '',
note: '发布验证',
})
const productionConfirmation = reactive({
reviewed: false,
rollbackPlan: '',
releaseWindow: '',
notifyTarget: '',
})
const localStatus = ref<ReleaseStatus>('idle')
const activeRun = ref<ReleaseRun | null>(null)
@@ -57,6 +67,10 @@ const selectedEnvironment = computed(() => {
return selectedProject.value?.environments.find((environment) => environment.name === form.environment)
})
const notificationIntegration = computed(() => {
return platform.integrations.find((integration) => integration.key === 'notification')
})
const useBranchRefs = computed(() => {
return selectedEnvironment.value?.branchPolicy === 'master'
})
@@ -71,6 +85,8 @@ const refOptions = computed(() => {
return refs?.branches.map((branch) => branch.name) ?? []
})
const hasRefOptions = computed(() => refOptions.value.length > 0)
const refSourceText = computed(() => {
const source = currentRefs.value?.source
@@ -98,6 +114,10 @@ const selectedRefDetail = computed<ProjectRefItem | undefined>(() => {
return candidates.find((item) => item.name === form.ref)
})
const selectedRefExists = computed(() => {
return Boolean(form.ref && refOptions.value.includes(form.ref))
})
const selectedCommitMessage = computed(() => {
return selectedRefDetail.value?.commit?.message?.split('\n')[0] || ''
})
@@ -135,12 +155,182 @@ const selectedPullRequestMeta = computed(() => {
return parts.join(' · ')
})
type PreflightState = Extract<HealthState, 'healthy' | 'warning' | 'error'>
type PreflightItem = {
key: string
title: string
description: string
state: PreflightState
required: boolean
}
const productionConfirmationReady = computed(() => {
if (form.environment !== 'production') {
return true
}
return (
productionConfirmation.reviewed &&
Boolean(productionConfirmation.rollbackPlan.trim()) &&
Boolean(productionConfirmation.releaseWindow.trim()) &&
Boolean(productionConfirmation.notifyTarget.trim())
)
})
const triggerDisabledReason = computed(() => {
if (!form.projectKey) {
return '请选择项目'
}
if (!canBuildSelectedProject.value) {
return '当前账号只有只读权限,发布操作已禁用'
}
if (!hasRefOptions.value) {
return '后端未返回可发布的 ref/tag'
}
if (!selectedRefExists.value) {
return '请选择后端返回的 ref/tag'
}
if (!productionConfirmationReady.value) {
return '请补全生产发布确认'
}
return ''
})
const canTrigger = computed(() => {
if (!canBuildSelectedProject.value || !form.projectKey || !form.environment || !form.ref) {
return false
}
return true
return selectedRefExists.value && productionConfirmationReady.value
})
const preflightItems = computed<PreflightItem[]>(() => {
const refs = currentRefs.value
const refKindText = form.environment === 'production' && !useBranchRefs.value ? 'tag' : 'branch'
const jenkinsState = selectedEnvironment.value?.jenkinsStatus ?? 'warning'
const giteaState = selectedProject.value?.giteaStatus ?? 'warning'
const webhookState = selectedProject.value?.giteaWebhookStatus ?? 'warning'
const notificationState = notificationIntegration.value?.state ?? 'warning'
return [
{
key: 'permission',
title: '操作权限',
description: canBuildSelectedProject.value
? `${session.displayName || session.operator || '当前账号'} 对 ${form.projectKey || '-'} 具备构建权限`
: '当前账号不能触发该项目发布',
state: canBuildSelectedProject.value ? 'healthy' : 'error',
required: true,
},
{
key: 'ref',
title: '发布对象',
description: selectedRefExists.value
? `${form.ref} 来自 ${refSourceText.value},类型为 ${refKindText}`
: hasRefOptions.value
? '请选择后端返回的 ref/tag'
: '后端暂未返回可发布 ref/tag',
state: selectedRefExists.value
? refs?.source === 'gitea'
? 'healthy'
: 'warning'
: 'error',
required: true,
},
{
key: 'commit',
title: '提交摘要',
description: selectedCommitSha.value
? `${shortSha(selectedCommitSha.value)} · ${selectedCommitMessage.value || '无提交说明'}`
: '后端未返回 commit 摘要,建议先检查 Gitea refs 接口',
state: selectedCommitSha.value ? 'healthy' : 'warning',
required: false,
},
{
key: 'jenkins',
title: 'Jenkins Job',
description: selectedEnvironment.value?.jenkinsJob
? `${selectedEnvironment.value.jenkinsJob}${selectedEnvironment.value.jenkinsMessage ? ` · ${selectedEnvironment.value.jenkinsMessage}` : ''}`
: '尚未加载当前环境 Jenkins Job',
state: normalizePreflightState(jenkinsState),
required: false,
},
{
key: 'gitea',
title: 'Gitea 仓库',
description: selectedProject.value?.giteaMessage
? selectedProject.value.giteaMessage
: selectedProject.value?.giteaBranchCount !== undefined || selectedProject.value?.giteaTagCount !== undefined
? `branch ${selectedProject.value.giteaBranchCount ?? '-'} / tag ${selectedProject.value.giteaTagCount ?? '-'}`
: '等待仓库诊断结果',
state: normalizePreflightState(giteaState),
required: false,
},
{
key: 'webhook',
title: 'Webhook / Relay',
description: selectedProject.value?.giteaWebhookMessage || '等待 webhook 诊断结果',
state: normalizePreflightState(webhookState),
required: false,
},
{
key: 'notification',
title: '通知链路',
description:
notificationIntegration.value?.summary ||
'通知未配置时不会阻断发布,但会进入 outbox 供后续排查',
state: normalizePreflightState(notificationState),
required: false,
},
{
key: 'production',
title: '生产确认',
description:
form.environment === 'production'
? productionConfirmationReady.value
? '已补齐回滚方案、业务窗口、通知对象和核对勾选'
: '生产发布必须补齐回滚、窗口、通知对象和核对勾选'
: '测试环境不需要生产确认',
state:
form.environment === 'production' && !productionConfirmationReady.value
? 'error'
: 'healthy',
required: form.environment === 'production',
},
]
})
const preflightOverallState = computed<PreflightState>(() => {
if (preflightItems.value.some((item) => item.state === 'error')) {
return 'error'
}
if (preflightItems.value.some((item) => item.state === 'warning')) {
return 'warning'
}
return 'healthy'
})
const preflightSummary = computed(() => {
const blockers = preflightItems.value.filter((item) => item.state === 'error').length
const warnings = preflightItems.value.filter((item) => item.state === 'warning').length
if (blockers > 0) {
return `${blockers} 项阻断,需处理后才能触发发布`
}
if (warnings > 0) {
return `${warnings} 项提醒,发布前建议复核`
}
return '关键检查均已通过'
})
const shownRun = computed(() => {
@@ -173,7 +363,6 @@ async function triggerRelease() {
projectKey: form.projectKey,
environment: form.environment,
ref: form.ref,
operator: 'ops-admin',
remark: form.note,
idempotencyKey: `${form.projectKey}:${form.environment}:${form.ref}:${Date.now()}`,
productionConfirmation:
@@ -181,7 +370,7 @@ async function triggerRelease() {
? {
confirmed: true,
confirmedAt: new Date().toISOString(),
summary: '已确认 ref、回滚方案、通知对象和业务窗口',
summary: buildProductionConfirmationSummary(),
}
: undefined,
})
@@ -212,6 +401,44 @@ function formatCommitTime(value?: string): string {
}).format(new Date(value))
}
function normalizePreflightState(state: HealthState): PreflightState {
if (state === 'healthy') {
return 'healthy'
}
if (state === 'error' || state === 'offline') {
return 'error'
}
return 'warning'
}
function preflightTagType(state: PreflightState): 'success' | 'warning' | 'danger' {
if (state === 'healthy') {
return 'success'
}
return state === 'warning' ? 'warning' : 'danger'
}
function preflightStateText(state: PreflightState): string {
if (state === 'healthy') {
return '通过'
}
return state === 'warning' ? '提醒' : '阻断'
}
function buildProductionConfirmationSummary(): string {
return [
`操作者=${session.operator || session.displayName || 'unknown'}`,
`ref=${form.ref}`,
`回滚方案=${productionConfirmation.rollbackPlan.trim()}`,
`业务窗口=${productionConfirmation.releaseWindow.trim()}`,
`通知对象=${productionConfirmation.notifyTarget.trim()}`,
].join(';')
}
async function cancelRelease() {
if (!shownRun.value) {
return
@@ -296,6 +523,10 @@ function useFailedRun() {
activeRun.value = failed
}
function queryProjectKey(): string {
return typeof route.query.projectKey === 'string' ? route.query.projectKey : ''
}
async function handleReleaseActionError(
error: unknown,
fallbackMessage: string,
@@ -343,11 +574,32 @@ watch(
{ immediate: true },
)
watch(
() => route.query.projectKey,
() => {
const projectKey = queryProjectKey()
if (projectKey && projectKey !== form.projectKey) {
form.projectKey = projectKey
form.ref = ''
activeRun.value = null
localStatus.value = 'idle'
}
},
)
watch(refOptions, (options) => {
if (options.length > 0 && !options.includes(form.ref)) {
form.ref = options[0]
}
})
watch(
() => [form.projectKey, form.environment, form.ref],
() => {
productionConfirmation.reviewed = false
},
)
</script>
<template>
@@ -395,9 +647,10 @@ watch(refOptions, (options) => {
<ElSelect
v-model="form.ref"
filterable
allow-create
default-first-option
:disabled="!hasRefOptions"
:loading="refsLoading"
no-data-text="后端未返回可选 ref/tag"
>
<ElOption v-for="item in refOptions" :key="item" :label="item" :value="item" />
</ElSelect>
@@ -405,6 +658,9 @@ watch(refOptions, (options) => {
{{ form.environment === 'production' ? selectedProject?.tagPolicy : selectedProject?.defaultBranch }}
· {{ refSourceText }}
</div>
<div v-if="form.ref && !selectedRefExists" class="field-warning">
当前值不在后端返回列表中,请重新选择。
</div>
<div v-if="selectedCommitSha" class="commit-preview">
<div class="commit-main">
<ElTag size="small" effect="plain" class="mono">
@@ -435,13 +691,77 @@ watch(refOptions, (options) => {
<ElInput v-model="form.note" type="textarea" :rows="2" maxlength="120" show-word-limit />
</ElFormItem>
</div>
<div v-if="form.environment === 'production'" class="production-confirmation-card">
<div class="production-confirmation-head">
<div>
<strong>生产发布确认</strong>
<span>提交前必须明确回滚、窗口和通知边界。</span>
</div>
<StatusPill :state="productionConfirmationReady ? 'healthy' : 'warning'" />
</div>
<div class="production-confirmation-grid">
<ElFormItem label="回滚方案">
<ElInput
v-model="productionConfirmation.rollbackPlan"
maxlength="90"
show-word-limit
placeholder="例如:回滚到上一个生产 tag,并复用 prod job"
/>
</ElFormItem>
<ElFormItem label="业务窗口">
<ElInput
v-model="productionConfirmation.releaseWindow"
maxlength="60"
show-word-limit
placeholder="例如:低峰期 22:00-23:00"
/>
</ElFormItem>
<ElFormItem label="通知对象" class="notify-target-field">
<ElInput
v-model="productionConfirmation.notifyTarget"
maxlength="80"
show-word-limit
placeholder="例如:项目负责人、运维值班群、业务验收人"
/>
</ElFormItem>
</div>
<ElCheckbox v-model="productionConfirmation.reviewed">
我已核对目标 tag/commit、Jenkins Job、回滚方案、通知对象和业务窗口
</ElCheckbox>
</div>
<ElAlert
v-if="form.environment === 'production'"
class="danger-note"
title="生产发布将提交确认信息,请确认 tag、回滚方案、通知对象和业务窗口。"
title="生产发布会写入确认摘要和审计日志;确认信息不完整时不能提交。"
type="warning"
:closable="false"
/>
<div class="release-preflight-card">
<div class="release-preflight-head">
<div>
<strong>发布前检查</strong>
<span>{{ preflightSummary }}</span>
</div>
<StatusPill :state="preflightOverallState" />
</div>
<div class="preflight-grid">
<div
v-for="item in preflightItems"
:key="item.key"
class="preflight-item"
:class="`is-${item.state}`"
>
<div class="preflight-item-head">
<strong>{{ item.title }}</strong>
<ElTag :type="preflightTagType(item.state)" effect="light" round size="small">
{{ preflightStateText(item.state) }}
</ElTag>
</div>
<p>{{ item.description }}</p>
<small>{{ item.required ? '提交前必须通过' : '建议发布前复核' }}</small>
</div>
</div>
</div>
<div class="action-row">
<ElButton
type="primary"
@@ -458,8 +778,8 @@ watch(refOptions, (options) => {
<ElButton :icon="CircleClose" :disabled="!canRetryShownRun || submitting" @click="retryRelease">
重试
</ElButton>
<span v-if="form.projectKey && !canBuildSelectedProject" class="permission-action-hint">
当前账号只有只读权限,发布操作已禁用
<span v-if="triggerDisabledReason" class="permission-action-hint">
{{ triggerDisabledReason }}
</span>
</div>
</ElForm>
@@ -601,6 +921,146 @@ watch(refOptions, (options) => {
font-size: 12px;
}
.field-warning {
margin-top: 6px;
color: #b45309;
font-size: 12px;
line-height: 1.5;
}
.production-confirmation-card {
margin-top: 6px;
padding: 14px;
border: 1px solid #f5d0a6;
border-radius: 8px;
background: #fffaf2;
}
.production-confirmation-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.production-confirmation-head strong {
display: block;
color: #7c2d12;
font-size: 14px;
}
.production-confirmation-head span {
display: block;
margin-top: 4px;
color: #9a5a26;
font-size: 12px;
}
.production-confirmation-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0 14px;
}
.notify-target-field {
grid-column: 1 / -1;
}
.danger-note {
margin-top: 12px;
}
.release-preflight-card {
margin-top: 12px;
padding: 14px;
border: 1px solid #d8e2ef;
border-radius: 8px;
background: #f8fafc;
}
.release-preflight-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.release-preflight-head strong {
display: block;
color: #0f172a;
font-size: 14px;
}
.release-preflight-head span {
display: block;
margin-top: 4px;
color: #64748b;
font-size: 12px;
}
.preflight-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
}
.preflight-item {
min-width: 0;
padding: 10px;
border: 1px solid #e2e8f0;
border-left-width: 3px;
border-radius: 6px;
background: #fff;
}
.preflight-item.is-healthy {
border-left-color: #16a34a;
}
.preflight-item.is-warning {
border-left-color: #d97706;
}
.preflight-item.is-error {
border-left-color: #dc2626;
}
.preflight-item-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.preflight-item-head strong {
min-width: 0;
overflow: hidden;
color: #0f172a;
font-size: 13px;
font-weight: 600;
text-overflow: ellipsis;
white-space: nowrap;
}
.preflight-item p {
display: -webkit-box;
min-height: 36px;
margin: 8px 0 6px;
overflow: hidden;
color: #475569;
font-size: 12px;
line-height: 1.5;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.preflight-item small {
color: #94a3b8;
font-size: 11px;
}
.commit-preview {
display: grid;
gap: 4px;
@@ -677,6 +1137,14 @@ watch(refOptions, (options) => {
.form-grid {
grid-template-columns: 1fr;
}
.production-confirmation-grid {
grid-template-columns: 1fr;
}
.preflight-grid {
grid-template-columns: 1fr;
}
}
@media (max-width: 1180px) {