feat: 精简发布确认并支持回滚和助手操作

- 删除三个留档必填项与重复检查卡片,提交前核对真实锁定版本。

- 增加待确认操作卡片、发布回执与历史成功版本回滚入口,保护会话隔离和迟到响应。

- 折叠助手来源并清理系统设置的无效实现提示,保留并行通知配置改动。
This commit is contained in:
湛兮
2026-10-28 10:22:19 +08:00
parent 2071fdd5bb
commit 8910ee6be3
15 changed files with 296 additions and 179 deletions
+39 -120
View File
@@ -1,24 +1,30 @@
<script setup lang="ts">
import { computed, reactive, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ElMessage } from 'element-plus'
import { Promotion, Refresh } from '@element-plus/icons-vue'
import { devopsApi } from '../services/devopsApi'
import { confirmOperation } from '../services/operationConfirmation'
import StatusPill from '../components/StatusPill.vue'
import { usePlatformStore } from '../stores/platform'
import { formatTime } from '../utils/releases'
import type { EnvironmentName } from '../types/devops'
import type { EnvironmentName, OperationPlan } from '../types/devops'
const platform = usePlatformStore()
const route = useRoute()
const router = useRouter()
const form = reactive({ projectKey: '', environment: 'test' as EnvironmentName, ref: '', note: '' })
const confirmation = reactive({ rollback: '', window: '', notify: '', reviewed: false })
const form = reactive({
projectKey: '',
environment: 'test' as EnvironmentName,
ref: '',
})
const confirmation = reactive({ reviewed: false })
const submitting = ref(false)
const refsLoading = ref(false)
const refsError = ref('')
const submittedRunId = ref('')
let refsRequest = 0
let requestKey = ''
let preparedPlan: OperationPlan | undefined
const selectedProject = computed(() =>
platform.projects.find((project) => project.key === form.projectKey),
)
@@ -40,54 +46,25 @@ const latestRun = computed(() =>
),
)
const submittedRun = computed(() => platform.runs.find((run) => run.id === submittedRunId.value))
const productionReady = computed(
() =>
form.environment !== 'production' ||
(confirmation.reviewed &&
confirmation.rollback.trim() &&
confirmation.window.trim() &&
confirmation.notify.trim()),
)
const productionReady = computed(() => form.environment !== 'production' || confirmation.reviewed)
const disabledReason = computed(() => {
if (!selectedProject.value || !selectedEnvironment.value) return '请选择项目与发布环境'
if (!platform.canBuildProject(form.projectKey)) return '当前项目为只读权限,请联系管理员授权'
if (!selectedEnvironment.value.jenkinsJob) return '当前环境尚未配置构建任务'
if (refsLoading.value) return '正在读取可发布版本…'
if (refsError.value) return '版本读取失败,请重试'
if (refs.value?.source !== 'gitea') return '无法实时核对版本,请检查仓库接入后重试'
if (!refOptions.value.length)
return useTags.value
? '暂无可发布标签,请先在仓库创建版本标签'
: '暂无可发布分支,请检查仓库接入'
if (!selectedRef.value) return `请选择${useTags.value ? '版本标签' : '分支'}`
if (!productionReady.value) return '请填写生产确认信息并勾选核对项'
if (!productionReady.value) return '请核对目标版本并确认生产发布'
return ''
})
const checks = computed(() => [
{
title: '操作权限',
text: platform.canBuildProject(form.projectKey) ? '可发布' : '只读',
state: platform.canBuildProject(form.projectKey) ? ('healthy' as const) : ('error' as const),
},
{
title: '版本来源',
text:
refs.value?.source === 'gitea'
? 'Gitea 实时读取'
: refs.value
? '后端备用版本,请复核'
: '尚未读取',
state: refs.value?.source === 'gitea' ? ('healthy' as const) : ('warning' as const),
},
{
title: '构建任务',
text: selectedEnvironment.value?.jenkinsJob || '未配置',
state: selectedEnvironment.value?.jenkinsStatus || ('warning' as const),
},
])
function resetConfirmation() {
confirmation.reviewed = false
requestKey = ''
preparedPlan = undefined
}
function applyRoute() {
const projectKey = typeof route.query.projectKey === 'string' ? route.query.projectKey : ''
@@ -147,10 +124,7 @@ watch(
},
{ immediate: true },
)
watch(
() => [form.ref, form.note, confirmation.rollback, confirmation.window, confirmation.notify],
resetConfirmation,
)
watch(() => [form.ref], resetConfirmation)
// 首次进入时 applyRoute 可能早于项目 watcher 注册。
if (form.projectKey) void loadRefs()
@@ -173,41 +147,22 @@ async function triggerRelease() {
if (submitting.value || disabledReason.value) return
submitting.value = true
try {
await ElMessageBox.confirm(
`将 ${selectedProject.value?.name} 的 ${form.ref} 发布到${selectedEnvironment.value?.label}。`,
form.environment === 'production' ? '确认生产发布' : '确认发布',
{
confirmButtonText: '确认发布',
cancelButtonText: '取消',
type: 'warning',
autofocus: false,
},
)
} catch {
submitting.value = false
return
}
try {
// 网络重试沿用同一幂等键,参数变更后才开启新的发布请求。
requestKey ||= crypto.randomUUID()
const run = await platform.createDeployRun({
projectKey: form.projectKey,
environment: form.environment,
ref: form.ref,
remark: form.note.trim(),
idempotencyKey: requestKey,
productionConfirmation:
form.environment === 'production'
? {
confirmed: true,
confirmedAt: new Date().toISOString(),
summary: `回滚方案:${confirmation.rollback.trim()};业务窗口:${confirmation.window.trim()};通知对象:${confirmation.notify.trim()}`,
}
: undefined,
})
const plan =
preparedPlan && Date.parse(preparedPlan.expiresAt) > Date.now()
? preparedPlan
: await devopsApi.prepareOperation({
kind: 'deploy',
projectKey: form.projectKey,
environment: form.environment,
ref: form.ref,
})
preparedPlan = plan
if (!(await confirmOperation(plan))) return
const run = await platform.executeOperation(plan.confirmationToken!)
submittedRunId.value = run.id
requestKey = ''
ElMessage.success('发布已提交,可查看进度与日志')
preparedPlan = undefined
if (run.status === 'failed') ElMessage.error('发布未成功,请查看日志')
else ElMessage.success('发布已提交,可查看实际进度与日志')
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '发布提交失败,请重试')
} finally {
@@ -243,7 +198,6 @@ async function triggerRelease() {
<section class="panel release-form">
<div class="panel-header">
<h2>发布内容</h2>
<span>01 — 选择目标</span>
</div>
<div class="panel-body">
<ElForm label-position="top" @submit.prevent="triggerRelease">
@@ -292,7 +246,9 @@ async function triggerRelease() {
@click="loadRefs"
/>
</div>
<div v-if="refsError" class="inline-error" role="alert">{{ refsError }}</div>
<div v-if="refsError" class="inline-error" role="alert">
{{ refsError }}
</div>
<div v-if="sha" class="commit-preview">
<span class="mono">{{ sha.slice(0, 10) }}</span
><span>{{ selectedRef?.commit?.message?.split('\n')[0] || '无提交说明' }}</span>
@@ -309,43 +265,11 @@ async function triggerRelease() {
当前为后端备用版本列表,请确认仓库接入后再发布。
</div>
</ElFormItem>
<ElFormItem label="发布备注(选填)"
><ElInput
v-model="form.note"
type="textarea"
:rows="2"
maxlength="120"
show-word-limit
placeholder="这次发布改了什么…"
aria-label="发布备注"
/></ElFormItem>
<section v-if="form.environment === 'production'" class="production-confirmation">
<h2>生产发布确认</h2>
<p>核对目标版本,并说明发布与回滚安排。</p>
<ElFormItem label="回滚方案"
><ElInput
v-model="confirmation.rollback"
maxlength="90"
placeholder="例如:回滚到上一个生产标签…"
aria-label="回滚方案"
/></ElFormItem>
<div class="confirmation-grid">
<ElFormItem label="发布窗口"
><ElInput
v-model="confirmation.window"
maxlength="60"
placeholder="例如:今晚 23:00…"
aria-label="发布窗口" /></ElFormItem
><ElFormItem label="通知对象"
><ElInput
v-model="confirmation.notify"
maxlength="80"
placeholder="例如:项目负责人…"
aria-label="通知对象"
/></ElFormItem>
</div>
<p>将部署所选版本,提交前还会显示锁定的具体提交。</p>
<ElCheckbox v-model="confirmation.reviewed"
>已核对版本、构建任务和以上生产发布安排</ElCheckbox
>已核对目标版本,确认发布到生产环境</ElCheckbox
>
</section>
<div class="submit-row">
@@ -368,7 +292,9 @@ async function triggerRelease() {
<div class="panel-header"><h2>目标环境</h2></div>
<div class="panel-body">
<strong class="context-project">{{ selectedProject?.name || '尚未选择项目' }}</strong>
<p class="context-environment">{{ selectedEnvironment?.label || '—' }}</p>
<p class="context-environment">
{{ selectedEnvironment?.label || '—' }}
</p>
<dl>
<dt>最近发布</dt>
<dd v-if="latestRun"><StatusPill :state="latestRun.status" /></dd>
@@ -386,13 +312,6 @@ async function triggerRelease() {
>
</div>
</section>
<details class="checks" open>
<summary>发布检查</summary>
<div v-for="check in checks" :key="check.title" class="check-row">
<span>{{ check.title }}</span
><StatusPill :state="check.state" :text="check.text" />
</div>
</details>
</aside>
</div>
</div>
+50 -42
View File
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { devopsApi } from '../services/devopsApi'
import { confirmOperation } from '../services/operationConfirmation'
import { computed, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -34,7 +36,9 @@ function filter(key: string) {
return computed({
get: () => query(key),
set: (value: string) => {
void router.replace({ query: { ...route.query, [key]: value || undefined, page: undefined } })
void router.replace({
query: { ...route.query, [key]: value || undefined, page: undefined },
})
},
})
}
@@ -84,7 +88,9 @@ function resetFilters() {
void router.replace({ query: { runId: route.query.runId } })
}
function changePage(value: number) {
void router.replace({ query: { ...route.query, page: value > 1 ? value : undefined } })
void router.replace({
query: { ...route.query, page: value > 1 ? value : undefined },
})
}
async function refresh() {
busy.value = 'refresh'
@@ -96,48 +102,33 @@ async function refresh() {
busy.value = ''
}
}
async function runAction(action: 'retry' | 'cancel' | 'sync') {
async function runAction(action: 'retry' | 'cancel' | 'sync' | 'rollback') {
const run = selectedRun.value
if (!run || !platform.canBuildProject(run.projectKey) || busy.value) return
const label = { retry: '重试发布', cancel: '取消发布', sync: '同步构建状态' }[action]
busy.value = action
try {
await ElMessageBox.confirm(
`${label}:${run.projectName} / ${run.environment === 'production' ? '生产' : '测试'} / ${run.ref}`,
label,
{
confirmButtonText: `确认${label}`,
cancelButtonText: '返回',
type: 'warning',
autofocus: false,
},
)
} catch {
busy.value = ''
return
}
try {
const result =
action === 'retry'
? await platform.retryDeployRun(run)
: action === 'cancel'
? await platform.cancelDeployRun(run)
: await platform.syncJenkinsRun(run)
if (action === 'retry') selectRun(result)
ElMessage.success(`${label}已完成`)
if (action === 'sync') {
await platform.syncJenkinsRun(run)
ElMessage.success('已读取最新构建状态')
return
}
const plan = await devopsApi.prepareOperation({
kind: action,
runId: run.id,
})
if (!(await confirmOperation(plan))) return
const result = await platform.executeOperation(plan.confirmationToken!)
selectRun(result)
if (result.status === 'failed') ElMessage.error('操作未成功,请查看日志')
else ElMessage.success('操作已提交,可查看实际进度与日志')
} catch (error) {
if (isDevopsApiError(error) && error.code === 'CONFLICT') {
try {
await platform.refreshRuns()
ElMessage.warning('发布状态已变化,已刷新最新记录')
} catch {
ElMessage.error('状态已变化,刷新失败,请重试')
}
} else ElMessage.error(error instanceof Error ? error.message : `${label}失败`)
if (isDevopsApiError(error) && error.code === 'CONFLICT') await refresh()
ElMessage.error(error instanceof Error ? error.message : '操作失败,请重试')
} finally {
busy.value = ''
}
}
async function adminAction(action: string | number | object) {
if (session.role !== 'super_admin' || busy.value || (action !== 'import' && action !== 'sync'))
return
@@ -207,7 +198,9 @@ async function adminAction(action: string | number | object) {
:title="toolResult"
:type="toolFailures.length ? 'warning' : 'success'"
@close="toolResult = ''"
><p v-for="failure in toolFailures" :key="failure">{{ failure }}</p></ElAlert
><p v-for="failure in toolFailures" :key="failure">
{{ failure }}
</p></ElAlert
>
<section class="panel">
<div class="run-filters">
@@ -248,7 +241,9 @@ async function adminAction(action: string | number | object) {
>
<ElTableColumn label="项目 / 版本" min-width="210"
><template #default="{ row }"
><button class="run-name" @click.stop="selectRun(row)">{{ row.projectName }}</button>
><button class="run-name" @click.stop="selectRun(row)">
{{ row.projectName }}
</button>
<div class="field-hint mono">{{ row.ref }}</div></template
></ElTableColumn
>
@@ -315,10 +310,7 @@ async function adminAction(action: string | number | object) {
>Jenkins #{{ selectedRun.jenkinsBuildNumber }} ↗</a
>
</div>
<div
v-if="canAct && (selectedActive || ['failed', 'canceled'].includes(selectedRun.status))"
class="run-actions toolbar"
>
<div v-if="canAct" class="run-actions toolbar">
<ElButton
v-if="selectedActive && (selectedRun.jenkinsQueueId || selectedRun.jenkinsBuildNumber)"
size="small"
@@ -341,7 +333,21 @@ async function adminAction(action: string | number | object) {
@click="runAction('retry')"
>重试发布</ElButton
>
<ElButton
v-if="selectedRun.status === 'success'"
size="small"
:loading="busy === 'rollback'"
:disabled="Boolean(busy)"
@click="runAction('rollback')"
>回滚到此版本</ElButton
>
</div>
<p v-if="selectedRun.resolvedCommit" class="field-hint">
{{ selectedRun.operationKind === 'rollback' ? '回滚提交' : '实际锁定提交' }}:<span
class="mono"
>{{ selectedRun.resolvedCommit }}</span
>
</p>
<ElButton
class="ask-run"
text
@@ -388,7 +394,9 @@ async function adminAction(action: string | number | object) {
.run-filters {
display: grid;
grid-template-columns: minmax(150px, 1.2fr) 115px 120px minmax(200px, 1.4fr) auto;
grid-template-columns:
minmax(150px, 1.2fr) 115px 120px minmax(200px, 1.4fr)
auto;
gap: 10px;
padding: 20px;
border-bottom: 1px solid var(--border);
+2 -6
View File
@@ -331,7 +331,7 @@ function variableHelp(item: IntegrationConfigItem, name: string) {
function variableDescription(
item: IntegrationConfigItem,
name: string,
group: VariableGroup,
_group: VariableGroup,
): string {
const help = variableHelp(item, name)
@@ -343,12 +343,9 @@ function variableDescription(
return item.note
}
return `后端暂未返回 ${item.name} ${group.label} ${name} 的变量说明;请在 /settings/integration-config 响应中补充 variableHelp。`
return '该变量由服务端配置。'
}
function variableSourceLabel(item: IntegrationConfigItem, name: string): string {
return variableHelp(item, name)?.description ? '后端返回' : '等待后端说明'
}
async function loadAgentConfig() {
if (!canManageSystemConfig.value) {
@@ -552,7 +549,6 @@ function resetAuditFilters() {
<div class="variable-tooltip">
<strong class="mono">{{ name }}</strong>
<p>{{ variableDescription(item, name, group) }}</p>
<small>{{ group.label }} · {{ variableSourceLabel(item, name) }}</small>
<small v-if="variableHelp(item, name)?.example">
示例:{{ variableHelp(item, name)?.example }}
</small>