feat: 初始化DevOps平台前端

This commit is contained in:
湛兮
2026-06-11 20:49:59 +08:00
commit 60931e2c21
38 changed files with 7033 additions and 0 deletions
+360
View File
@@ -0,0 +1,360 @@
<script setup lang="ts">
import { CircleClose, Promotion, RefreshRight, VideoPause } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, reactive, ref, watch } from 'vue'
import BpmnStatusViewer from '../components/BpmnStatusViewer.vue'
import RunExecutionDetails from '../components/RunExecutionDetails.vue'
import StatusPill from '../components/StatusPill.vue'
import { usePlatformStore } from '../stores/platform'
import type { EnvironmentName, ReleaseRun, ReleaseStatus } from '../types/devops'
const platform = usePlatformStore()
const form = reactive({
projectKey: 'access-manage',
environment: 'test' as EnvironmentName,
ref: 'develop',
note: '测试环境部署验证',
confirmed: false,
})
const localStatus = ref<ReleaseStatus>('idle')
const activeRun = ref<ReleaseRun | null>(null)
const submitting = ref(false)
const refsLoading = ref(false)
const selectedProject = computed(() => {
return platform.projects.find((project) => project.key === form.projectKey)
})
const currentRefs = computed(() => platform.projectRefs[form.projectKey])
const environmentOptions = computed(() => {
const environments = selectedProject.value?.environments ?? []
if (!environments.length) {
return [
{ label: '测试环境', value: 'test' },
{ label: '生产环境', value: 'production' },
]
}
return environments.map((environment) => ({
label: environment.label,
value: environment.name,
}))
})
const selectedEnvironment = computed(() => {
return selectedProject.value?.environments.find((environment) => environment.name === form.environment)
})
const useBranchRefs = computed(() => {
return selectedEnvironment.value?.branchPolicy === 'master'
})
const refOptions = computed(() => {
const refs = currentRefs.value
if (form.environment === 'production' && !useBranchRefs.value) {
return refs?.tags.map((tag) => tag.name) ?? ['v2026.06.05-envsplit.7']
}
return refs?.branches.map((branch) => branch.name) ?? [selectedProject.value?.defaultBranch ?? 'develop']
})
const refSourceText = computed(() => {
const source = currentRefs.value?.source
if (source === 'gitea') {
return 'Gitea 实时 refs'
}
if (source === 'fallback') {
return '后端 fallback refs'
}
return '本地 mock refs'
})
const canTrigger = computed(() => {
if (!form.projectKey || !form.environment || !form.ref) {
return false
}
return form.environment === 'production' ? form.confirmed : true
})
const shownRun = computed(() => {
return activeRun.value || platform.runs[0]
})
const canSyncJenkins = computed(() => {
return shownRun.value?.status === 'queued' || shownRun.value?.status === 'running'
})
async function triggerRelease() {
submitting.value = true
try {
const run = await platform.createDeployRun({
projectKey: form.projectKey,
environment: form.environment,
ref: form.ref,
operator: 'ops-admin',
remark: form.note,
idempotencyKey: `${form.projectKey}:${form.environment}:${form.ref}:${Date.now()}`,
})
activeRun.value = run
localStatus.value = run.status
ElMessage.success(platform.dataSource === 'backend' ? '发布单已提交到后端' : '后端不可用,已生成本地发布单')
} finally {
submitting.value = false
}
}
async function cancelRelease() {
if (!shownRun.value) {
return
}
submitting.value = true
try {
const run = await platform.cancelDeployRun(shownRun.value)
activeRun.value = run
localStatus.value = run.status
ElMessage.success('发布单已取消')
} finally {
submitting.value = false
}
}
async function retryRelease() {
if (!shownRun.value) {
return
}
submitting.value = true
try {
const run = await platform.retryDeployRun(shownRun.value)
activeRun.value = run
localStatus.value = run.status
ElMessage.success(platform.dataSource === 'backend' ? '已提交重试发布单' : '后端不可用,已生成本地重试单')
} finally {
submitting.value = false
}
}
async function syncJenkinsRun() {
if (!shownRun.value) {
return
}
submitting.value = true
try {
const run = await platform.syncJenkinsRun(shownRun.value)
activeRun.value = run
localStatus.value = run.status
ElMessage.success(platform.dataSource === 'backend' ? '已同步 Jenkins 状态' : '后端不可用,保留本地状态')
} finally {
submitting.value = false
}
}
async function loadProjectRefs() {
if (!form.projectKey) {
return
}
refsLoading.value = true
try {
await platform.loadProjectRefs(form.projectKey)
} finally {
refsLoading.value = false
}
}
function useFailedRun() {
const failed = platform.failedRuns[0]
if (!failed) {
return
}
form.projectKey = failed.projectKey
form.environment = failed.environment
form.ref = failed.ref
form.note = `重试 ${failed.id}`
form.confirmed = failed.environment !== 'production'
localStatus.value = 'failed'
activeRun.value = failed
}
watch(
() => [form.projectKey, platform.projects.length],
() => {
const firstEnvironment = selectedProject.value?.environments[0]
if (firstEnvironment && !selectedProject.value?.environments.some((env) => env.name === form.environment)) {
form.environment = firstEnvironment.name
}
void loadProjectRefs()
},
{ immediate: true },
)
watch(refOptions, (options) => {
if (options.length > 0 && !options.includes(form.ref)) {
form.ref = options[0]
}
})
</script>
<template>
<div class="page-shell">
<div class="page-header">
<div>
<h1>发布中心</h1>
<p>选择项目、环境和 ref/tag,填写备注后触发发布;生产环境必须完成二次确认。</p>
</div>
<div class="toolbar">
<ElButton :icon="RefreshRight" @click="useFailedRun">载入最近失败</ElButton>
<StatusPill :state="localStatus" />
</div>
</div>
<div class="two-column">
<section class="panel">
<div class="panel-header">
<h2>发布参数</h2>
<span>{{ platform.dataSource === 'backend' ? '通过后端创建发布单' : '后端不可用时使用本地降级' }}</span>
</div>
<div class="panel-body">
<ElForm label-position="top">
<div class="form-grid">
<ElFormItem label="项目">
<ElSelect v-model="form.projectKey" filterable>
<ElOption
v-for="project in platform.projects"
:key="project.key"
:label="project.name"
:value="project.key"
/>
</ElSelect>
</ElFormItem>
<ElFormItem label="环境">
<ElSegmented
v-model="form.environment"
:options="environmentOptions"
/>
</ElFormItem>
<ElFormItem label="ref / tag">
<ElSelect
v-model="form.ref"
filterable
allow-create
default-first-option
:loading="refsLoading"
>
<ElOption v-for="item in refOptions" :key="item" :label="item" :value="item" />
</ElSelect>
<div class="field-hint">
{{ form.environment === 'production' ? selectedProject?.tagPolicy : selectedProject?.defaultBranch }}
· {{ refSourceText }}
</div>
</ElFormItem>
<ElFormItem label="备注">
<ElInput v-model="form.note" type="textarea" :rows="3" maxlength="120" show-word-limit />
</ElFormItem>
</div>
<ElAlert
v-if="form.environment === 'production'"
class="danger-note"
title="生产发布需要二次确认:已确认 tag、回滚方案、通知对象和业务窗口。"
type="warning"
:closable="false"
/>
<ElCheckbox v-model="form.confirmed" class="confirm-line">
我确认本次发布参数、目标环境和通知范围无误
</ElCheckbox>
<div class="action-row">
<ElButton
type="primary"
:icon="Promotion"
:disabled="!canTrigger || submitting"
:loading="submitting"
@click="triggerRelease"
>
触发发布
</ElButton>
<ElButton :icon="VideoPause" :disabled="localStatus !== 'queued' || submitting" @click="cancelRelease">
取消
</ElButton>
<ElButton :icon="CircleClose" :disabled="localStatus !== 'failed' || submitting" @click="retryRelease">
重试
</ElButton>
</div>
</ElForm>
</div>
</section>
<section class="panel">
<div class="panel-header">
<h2>当前发布单</h2>
<div class="toolbar compact-toolbar">
<ElButton
size="small"
:icon="RefreshRight"
:disabled="!canSyncJenkins || submitting"
:loading="submitting && canSyncJenkins"
@click="syncJenkinsRun"
>
同步 Jenkins
</ElButton>
<StatusPill :state="shownRun?.status || 'idle'" />
</div>
</div>
<div class="panel-body" v-if="shownRun">
<RunExecutionDetails :run="shownRun" />
</div>
</section>
</div>
<section class="panel">
<div class="panel-header">
<h2>BPMN 流程状态</h2>
<span>step.bpmnNodeId 与 BPMN XML 节点 id 对齐后高亮</span>
</div>
<div class="panel-body">
<BpmnStatusViewer
v-if="platform.releaseProcessXml && shownRun"
:xml="platform.releaseProcessXml"
:steps="shownRun.steps"
/>
</div>
</section>
</div>
</template>
<style scoped>
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px 14px;
}
.confirm-line {
margin-top: 14px;
}
.action-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 16px;
}
@media (max-width: 760px) {
.form-grid {
grid-template-columns: 1fr;
}
}
</style>