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>