feat: 初始化DevOps平台前端
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import type {
|
||||
AgentCard,
|
||||
CreateDeployRunPayload,
|
||||
IntegrationStatus,
|
||||
IntegrationConfigStatus,
|
||||
ProjectConfig,
|
||||
ProjectRefs,
|
||||
JenkinsSyncSummary,
|
||||
ReleaseRun,
|
||||
SystemSetting,
|
||||
} from '../types/devops'
|
||||
|
||||
/**
|
||||
* 平台运行态聚合后端和 mock 降级数据,页面只消费统一后的展示模型。
|
||||
*/
|
||||
export const usePlatformStore = defineStore('platform', () => {
|
||||
const loading = ref(false)
|
||||
const dataSource = ref<'backend' | 'mock'>('mock')
|
||||
const projects = ref<ProjectConfig[]>([])
|
||||
const runs = ref<ReleaseRun[]>([])
|
||||
const integrations = ref<IntegrationStatus[]>([])
|
||||
const agentCards = ref<AgentCard[]>([])
|
||||
const settings = ref<SystemSetting[]>([])
|
||||
const integrationConfig = ref<IntegrationConfigStatus>({
|
||||
checkedAt: '',
|
||||
integrations: [],
|
||||
})
|
||||
const releaseProcessXml = ref('')
|
||||
const projectRefs = ref<Record<string, ProjectRefs>>({})
|
||||
|
||||
const failedRuns = computed(() => runs.value.filter((run) => run.status === 'failed'))
|
||||
const runningRuns = computed(() =>
|
||||
runs.value.filter((run) => run.status === 'queued' || run.status === 'running'),
|
||||
)
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
try {
|
||||
const summary = await devopsApi.getDashboard()
|
||||
projects.value = summary.projects
|
||||
runs.value = summary.runs
|
||||
integrations.value = summary.integrations
|
||||
agentCards.value = summary.agentCards
|
||||
settings.value = summary.settings
|
||||
integrationConfig.value = summary.integrationConfig
|
||||
releaseProcessXml.value = await devopsApi.getReleaseProcessXml()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createDeployRun(payload: CreateDeployRunPayload) {
|
||||
const run = await devopsApi.createDeployRun(payload, projects.value)
|
||||
upsertRun(run)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return run
|
||||
}
|
||||
|
||||
async function cancelDeployRun(run: ReleaseRun) {
|
||||
const canceled = await devopsApi.cancelDeployRun(run.id, run)
|
||||
upsertRun(canceled)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return canceled
|
||||
}
|
||||
|
||||
async function retryDeployRun(run: ReleaseRun) {
|
||||
const retried = await devopsApi.retryDeployRun(run.id, run)
|
||||
upsertRun(retried)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return retried
|
||||
}
|
||||
|
||||
async function syncJenkinsRun(run: ReleaseRun) {
|
||||
const synced = await devopsApi.syncJenkinsRun(run.id, run, projects.value)
|
||||
upsertRun(synced)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return synced
|
||||
}
|
||||
|
||||
async function syncJenkinsRuns(): Promise<JenkinsSyncSummary> {
|
||||
const result = await devopsApi.syncJenkinsRuns(projects.value)
|
||||
result.syncedRuns.forEach(upsertRun)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return result
|
||||
}
|
||||
|
||||
async function loadProjectRefs(projectKey: string) {
|
||||
const refs = await devopsApi.getProjectRefs(projectKey, projects.value)
|
||||
projectRefs.value = {
|
||||
...projectRefs.value,
|
||||
[projectKey]: refs,
|
||||
}
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return refs
|
||||
}
|
||||
|
||||
function upsertRun(run: ReleaseRun) {
|
||||
runs.value = [run, ...runs.value.filter((item) => item.id !== run.id)]
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
dataSource,
|
||||
projects,
|
||||
runs,
|
||||
integrations,
|
||||
agentCards,
|
||||
settings,
|
||||
integrationConfig,
|
||||
releaseProcessXml,
|
||||
projectRefs,
|
||||
failedRuns,
|
||||
runningRuns,
|
||||
loadAll,
|
||||
createDeployRun,
|
||||
cancelDeployRun,
|
||||
retryDeployRun,
|
||||
syncJenkinsRun,
|
||||
syncJenkinsRuns,
|
||||
loadProjectRefs,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useSessionStore = defineStore('session', () => {
|
||||
const operator = ref('ops-admin')
|
||||
const role = ref<'admin' | 'operator' | 'viewer'>('admin')
|
||||
const token = ref('mock-session')
|
||||
|
||||
const isAuthenticated = computed(() => Boolean(token.value))
|
||||
|
||||
function login(name: string) {
|
||||
operator.value = name || 'ops-admin'
|
||||
token.value = 'mock-session'
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = ''
|
||||
}
|
||||
|
||||
return {
|
||||
operator,
|
||||
role,
|
||||
token,
|
||||
isAuthenticated,
|
||||
login,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user