diff --git a/src/services/devopsApi.ts b/src/services/devopsApi.ts index d8ad670..bf02f79 100644 --- a/src/services/devopsApi.ts +++ b/src/services/devopsApi.ts @@ -41,6 +41,9 @@ import { http } from './http' type DataSource = 'backend' type BackendHealthStatus = 'ok' | 'not_configured' | 'unavailable' type BackendRunStatus = 'pending' | 'queued' | 'running' | 'success' | 'failed' | 'canceled' +type DashboardOptions = { + includeAdminConfig?: boolean +} type BackendVariableHelpValue = | string | { @@ -311,12 +314,15 @@ export const devopsApi = { lastDataSource = 'backend' }, - async getDashboard(): Promise { + async getDashboard(options: DashboardOptions = {}): Promise { + const integrationConfigPromise = options.includeAdminConfig + ? fetchIntegrationConfigStatus() + : Promise.resolve(emptyIntegrationConfigStatus()) const [health, backendProjects, backendRuns, integrationConfig] = await Promise.all([ fetchHealth(), fetchProjects(), fetchRuns(), - fetchIntegrationConfigStatus(), + integrationConfigPromise, ]) const adaptedProjects = toProjectConfigs(backendProjects) lastDataSource = 'backend' @@ -482,6 +488,13 @@ async function fetchIntegrationConfigStatus(): Promise return sanitizeIntegrationConfigStatus(data) } +function emptyIntegrationConfigStatus(): IntegrationConfigStatus { + return { + checkedAt: new Date().toISOString(), + integrations: [], + } +} + function toIntegrationStatuses(health: BackendHealth): IntegrationStatus[] { return [ toIntegrationStatus('jenkins', 'Jenkins', health), diff --git a/src/stores/platform.ts b/src/stores/platform.ts index 1a93700..179ac22 100644 --- a/src/stores/platform.ts +++ b/src/stores/platform.ts @@ -4,6 +4,7 @@ import { computed, ref } from 'vue' import { defineStore } from 'pinia' import { devopsApi } from '../services/devopsApi' +import { useSessionStore } from './session' import type { AgentCard, AuditLogEntry, @@ -42,19 +43,23 @@ export const usePlatformStore = defineStore('platform', () => { ) async function loadAll() { + const session = useSessionStore() + const includeAdminData = session.role === 'super_admin' + loading.value = true try { - const summary = await devopsApi.getDashboard() + const summary = await devopsApi.getDashboard({ includeAdminConfig: includeAdminData }) projects.value = summary.projects runs.value = summary.runs integrations.value = summary.integrations agentCards.value = summary.agentCards settings.value = summary.settings integrationConfig.value = summary.integrationConfig - const [processXml, recentAuditLogs] = await Promise.all([ - devopsApi.getReleaseProcessXml(), - devopsApi.getAuditLogs(), - ]) + const processXmlPromise = devopsApi.getReleaseProcessXml() + const auditLogsPromise = includeAdminData + ? devopsApi.getAuditLogs() + : Promise.resolve([]) + const [processXml, recentAuditLogs] = await Promise.all([processXmlPromise, auditLogsPromise]) releaseProcessXml.value = processXml auditLogs.value = recentAuditLogs dataSource.value = devopsApi.getLastDataSource() diff --git a/src/views/ReleaseCenterView.vue b/src/views/ReleaseCenterView.vue index a2abeb9..3ddfbf6 100644 --- a/src/views/ReleaseCenterView.vue +++ b/src/views/ReleaseCenterView.vue @@ -14,10 +14,10 @@ import type { EnvironmentName, ProjectRefItem, ReleaseRun, ReleaseStatus } from const platform = usePlatformStore() const form = reactive({ - projectKey: 'access-manage', + projectKey: '', environment: 'test' as EnvironmentName, - ref: 'develop', - note: '测试环境部署验证', + ref: '', + note: '发布验证', confirmed: false, }) @@ -240,7 +240,7 @@ async function syncJenkinsRun() { } async function loadProjectRefs() { - if (!form.projectKey) { + if (!form.projectKey || !selectedProject.value) { return } @@ -270,6 +270,17 @@ function useFailedRun() { watch( () => [form.projectKey, platform.projects.length], () => { + const availableProject = selectedProject.value ?? platform.projects[0] + + if (!availableProject) { + return + } + + if (form.projectKey !== availableProject.key) { + form.projectKey = availableProject.key + return + } + const firstEnvironment = selectedProject.value?.environments[0] if (firstEnvironment && !selectedProject.value?.environments.some((env) => env.name === form.environment)) {