feat: 精简部署工作空间并接入真实助手
- 项目首页保留部署状态与日志入口,发布和管理功能收进更多菜单。 - 统一记录步骤与日志,限制轮询、日志渲染和助手短会话开销。 - 接入只读 Agent 问答、来源与个人历史,补充权限和并发回归。
This commit is contained in:
@@ -1,76 +1,66 @@
|
||||
# DevOps 运维平台前端
|
||||
# DevOps · 项目与部署
|
||||
|
||||
Vue 3 + Vite + TypeScript 实现的 DevOps 运维控制台第一阶段,用于管理本地项目和 DevOps 平台自身的发布状态、Jenkins/Gitea/通知平台/LLM 接入状态、发布步骤轨迹和 Agent 辅助能力。
|
||||
一个精简的部署工作空间,基于 Vue 3、Vite、TypeScript、Element Plus、Pinia 和 Vue Router。业务数据通过 `devops-platform-api` 获取。
|
||||
|
||||
## 当前范围
|
||||
## 页面与操作
|
||||
|
||||
- 登录、总览、项目配置、成员权限、发布中心、运行记录、系统配置,以及全局右侧 Agent 抽屉。
|
||||
- 所有项目、发布、refs、流程和集成状态均调用 `devops-platform-api`,前端不再提供本地 mock 数据降级。
|
||||
- 总览页提供值班焦点、优先 Run 队列、项目发布健康、项目环境摘要和跨页快捷入口,用于快速定位失败发布、项目阻断、配置缺口和通知 outbox 风险。
|
||||
- 成员权限页调用后端 `/members` 和 `/messages`,展示账号/构建权限/安全状态概览,支持角色、启停、安全状态和关键词筛选,并维护普通成员账号、项目权限、密码重置和平台消息。
|
||||
- 项目配置提供项目可发布性概览、项目/仓库搜索、发布态/权限筛选、Gitea/Jenkins/Webhook 诊断展开和发布/运行记录上下文跳转。
|
||||
- 发布中心包含项目、环境、后端返回的 ref/tag、备注、发布前检查、生产发布回滚/窗口/通知确认、触发、取消、重试和 Jenkins 状态同步入口。
|
||||
- 运行记录展示状态概览、项目/环境/状态/关键词筛选、Jenkins queue/build、Build URL、开始/结束时间、执行提示、失败摘要和日志摘要,并提供超级管理员导入 Jenkins 直接构建记录的入口。
|
||||
- 系统配置页展示集成配置、Agent 密钥状态、通知 outbox 和审计日志概览,支持通知投递与审计记录筛选,用于定位配置缺失、通知失败和敏感操作。
|
||||
- 发布步骤轨迹区使用后端 run steps 作为状态来源,左侧展示节点输出或 Jenkins 构建日志,右侧粘性展示进度统计、节点时间线和详情面板。
|
||||
- Agent 作为全局工具从顶部打开,只包含发布风险摘要、失败诊断、Runbook 问答、发布说明草稿和事故复盘草稿,并通过后端 Agent API 创建调用记录。
|
||||
- **项目 `/overview`**:单行项目列表,部署中的排在前面;仅保留部署状态、环境/版本、时间和日志入口。支持部署中、最近失败与项目搜索。
|
||||
- **记录 `/runs`**:按项目、环境、状态和关键词查询,每页 20 条。打开记录抽屉后查看步骤、统一输出和 Jenkins 日志。
|
||||
- **助手**:首页直接提问,或从顶部打开右侧抽屉。可问最近部署、纳管项目、构建结果及失败原因;后端模型自主调用只读工具,回答附来源。
|
||||
- **更多功能**:发布、接入、成员权限和设置统一收进顶部菜单。生产发布保留确认要求,权限由后端校验。
|
||||
|
||||
## 技术栈
|
||||
登录由后端识别角色,无需先选择管理员或成员。原有 `/releases`、`/projects`、`/members`、`/settings` 链接保留。
|
||||
|
||||
- Vue 3
|
||||
- Vite
|
||||
- TypeScript
|
||||
- Element Plus
|
||||
- Pinia
|
||||
- Vue Router
|
||||
- Axios
|
||||
## 数据与资源约定
|
||||
|
||||
## 本地启动
|
||||
- 首页仅请求项目、发布记录和健康摘要;管理数据在设置中按需读取。
|
||||
- 有执行中任务时每 12 秒刷新,隐藏的标签页暂停请求。
|
||||
- 日志按后端游标读取,执行中每 4.5 秒跟随;可暂停,最多渲染最近 600 行。
|
||||
- 助手复用现有 API 与远程模型,不运行本地模型或新常驻服务。一次最多 4 次工具调用、45 秒;普通请求仍采用独立的短超时。
|
||||
- 浏览器只保留最近 12 条助手消息,发送最近两轮成功问答;退出时清空数据、取消浏览器请求并忽略迟到响应。
|
||||
- 助手来源由后端真实记录生成;项目/记录使用内部路由,构建链接只接受后端提供的 HTTP(S) 地址。
|
||||
- 失败时显示真实错误,保留并标明上次数据;不构造前端 mock 或成功结果。
|
||||
- 最近发布按时间与后端版本号合并,迟到刷新不能回退已取消的任务或移除新记录。
|
||||
- 部署记录是最后同步结果,构建成功也不等于线上服务实时健康。
|
||||
|
||||
## 本地运行
|
||||
|
||||
需要 Node.js 22 和 pnpm。
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
本地前端默认监听 `http://localhost:4301`。如使用 `VITE_API_BASE_URL=http://localhost:4300`,浏览器会直接请求本地 API;如不设置该变量,Vite 会把 `/api` 默认代理到 `http://localhost:4300`,并自动去掉 `/api` 前缀。需要通过 `/api` 代理联调远端 API 时,可临时设置 `DEVOPS_API_PROXY_TARGET=https://devops.mrzhan.top/api`。
|
||||
默认前端地址 `http://localhost:4301`。Vite 把 `/api` 代理到 `http://localhost:4300` 并去掉 `/api` 前缀。可设置 `VITE_API_BASE_URL` 或 `DEVOPS_API_PROXY_TARGET` 调整 API 目标。
|
||||
|
||||
## 构建检查
|
||||
模型密钥仅在后端配置,浏览器不保存或直接使用供应商密钥。生产后端使用已有加密配置。
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
npm test
|
||||
npm run build
|
||||
```
|
||||
|
||||
## API 契约来源
|
||||
构建脚本为 `vue-tsc -b && vite build`。回归使用 Node.js 测试运行器和 Vite 模块解析,没有新增测试框架依赖;测试替身仅在测试文件中使用。
|
||||
|
||||
接口入口为 `src/services/devopsApi.ts`,只调用后端统一 envelope 响应;后端不可用时页面应暴露真实接口错误,不伪造项目、运行记录或 refs。后续以 `/Users/mac033/Desktop/my-project/devops-platform-docs/devops-platform-implementation-tracker.md` 中的产品约束和后端 OpenAPI 为准继续收敛字段。
|
||||
验证覆盖发布排序、请求去重、错误恢复、权限与会话隔离、并发刷新,以及助手短上下文和迟到回答。记录见 [验证说明](docs/minimal-workspace-verification.md)。真实模型、Jenkins、数据库和线上部署需要分别验收。
|
||||
|
||||
通知平台配置方案见 [docs/notification-platform-config.md](docs/notification-platform-config.md),包含企业微信、飞书和通用 webhook 的后端变量、安全边界与验证步骤。`/settings` 页面支持展示后端返回的变量说明字段,用于 hover 查看每个变量含义,并通过 `/agent/config` 维护后端保存的模型 baseURL、model 和 key。
|
||||
## 代码入口
|
||||
|
||||
浏览器端不得保存或直连以下密钥和服务:
|
||||
- `src/views/OverviewView.vue`:项目与部署列表。
|
||||
- `src/layouts/MainLayout.vue`:顶部导航、刷新、错误条和助手抽屉。
|
||||
- `src/views/RunsView.vue`:记录、筛选、分页和详情。
|
||||
- `src/components/PipelineStatusViewer.vue`:统一步骤与日志输出。
|
||||
- `src/components/GlobalAgentDrawer.vue`、`src/stores/assistant.ts`:自然语言问答和短会话。
|
||||
- `src/stores/platform.ts`、`src/utils/releases.ts`:业务数据、排序、并发与会话隔离。
|
||||
- `src/services/devopsApi.ts`、`src/services/http.ts`:统一 API 与错误模型。
|
||||
|
||||
- Jenkins token
|
||||
- Gitea token
|
||||
- 通知 webhook
|
||||
- LLM API key/baseURL/model
|
||||
## 接口边界
|
||||
|
||||
## 发布步骤边界
|
||||
前端不直连 Jenkins、Gitea、通知或模型供应商。发布步骤来源为服务端 `run.steps`,统一以 `nodeId` 定位;状态机、权限、幂等、审计和脱敏由后端负责。
|
||||
|
||||
- 前端只负责后端 `run.steps` 的状态、节点详情和日志展示,不渲染流程图 XML。
|
||||
- 后端返回的节点标识在前端统一映射为 `run.steps[].nodeId`,用于步骤选择、详情定位和日志联动。
|
||||
- 流程推进、失败停留、审计日志和状态机由后端负责。
|
||||
运维助手限于 DevOps,只提供查询与分析;发布、取消、重试仍通过明确操作与权限检查执行。
|
||||
|
||||
## Agent 边界
|
||||
|
||||
前端不提供泛聊天入口。Agent 入口仅围绕 DevOps 运维场景:
|
||||
|
||||
- 发布风险摘要
|
||||
- 失败诊断
|
||||
- Runbook 问答
|
||||
- 发布说明草稿
|
||||
- 事故复盘草稿
|
||||
|
||||
模型调用、脱敏、审计、白名单知识库和密钥管理由后端代理实现。
|
||||
|
||||
## 开源许可
|
||||
|
||||
本仓库使用 MIT License。提交公开仓库前请确认 `.env`、部署密钥和真实第三方 token 未进入 Git 历史或提交内容。
|
||||
MIT License。环境文件与真实凭据不得进入 Git。
|
||||
|
||||
@@ -1,43 +1,16 @@
|
||||
# DevOps 运维平台前端 RTK
|
||||
# DevOps 前端维护入口
|
||||
|
||||
## 项目定位
|
||||
技术栈保持 Vue 3 + Vite + TypeScript + Element Plus + Pinia。所有业务数据统一经后端 API,不提供前端业务 mock 降级。
|
||||
|
||||
`devops-platform-web` 是 DevOps 运维平台前端,用于统一查看和操作当前项目的部署与发布流程:
|
||||
- `/overview`:精简项目列表,部署中优先,直接查看日志;首页可以向只读助手提问。
|
||||
- `/runs?projectKey=…&environment=…&status=…&q=…&page=…&runId=…`:查询、分页、步骤与日志抽屉。
|
||||
- 顶部助手:真实远程模型通过后端自主调用只读工具;回答显示真实来源。没有独立侧栏页面或泛聊天能力。
|
||||
- 顶部更多菜单:`/releases`、`/projects`、`/members`、`/settings` 保留,管理路由继续按权限保护。
|
||||
- `/settings?tab=integrations|notifications|audit|agent`:集成、通知、审计、模型配置。
|
||||
- `/login`:统一登录;角色由后端识别;保留首次改密。
|
||||
|
||||
- `access-manage`
|
||||
- `role-admin`
|
||||
- `role-user`
|
||||
- `my-resume`
|
||||
- `devops-platform-api`
|
||||
- `devops-platform-web`
|
||||
平台与助手分别由 `src/stores/platform.ts`、`src/stores/assistant.ts` 维护。退出时重置,并忽略迟到请求。助手消息最多 12 条,只发送最近两轮成功问答,普通 API 与助手有不同超时。
|
||||
|
||||
当前前端只调用 `devops-platform-api`,不再提供本地 mock 数据降级。
|
||||
步骤与状态只来自服务端,不渲染流程图 XML,不在浏览器推进状态机。外部供应商密钥只由后端加密管理。
|
||||
|
||||
## 页面结构
|
||||
|
||||
- `/login`:真实平台账号登录入口,支持 token 恢复和首次改密。
|
||||
- `/overview`:总览,展示值班焦点、优先 Run 队列、项目发布健康、服务状态和项目环境快捷入口。
|
||||
- `/projects`:项目配置,展示项目可发布性概览、发布态/权限筛选、Gitea 仓库、Jenkins Job、通知通道、环境策略和上下文跳转。
|
||||
- `/members`:成员权限,仅超级管理员可见,展示账号/构建权限/安全状态概览,支持成员筛选,并维护普通成员、项目权限和密码重置消息。
|
||||
- `/releases`:发布中心,提供发布参数、后端 ref/tag 选择、发布前检查、生产发布确认、触发、取消、重试和发布步骤轨迹。
|
||||
- `/runs`:运行记录,展示 run 状态概览、筛选列表、执行详情、步骤轨迹,并支持超级管理员导入 Jenkins 直接构建记录。
|
||||
- 顶部 Agent 按钮:打开全局右侧抽屉,只保留 DevOps 场景能力;`/agent` 仅重定向到总览,不作为独立侧边栏入口。
|
||||
- `/settings`:系统配置,展示集成配置、Agent、通知 outbox 和审计日志概览,支持通知/审计筛选,并维护后端 Agent 模型配置。
|
||||
|
||||
## 数据约定
|
||||
|
||||
- API 封装入口:`src/services/devopsApi.ts`
|
||||
- Axios 实例:`src/services/http.ts`
|
||||
- 平台状态:`src/stores/platform.ts`
|
||||
- 登录状态:`src/stores/session.ts`
|
||||
|
||||
## 后续接入点
|
||||
|
||||
- `devopsApi` 所有项目、发布、refs、流程、成员、消息和 Agent 调用均走后端接口。
|
||||
- 发布中心触发按钮接入后端发布单创建接口。
|
||||
- 运行记录接入后端 run/step 查询接口。
|
||||
- Jenkins 直接构建不由前端直连 Jenkins;运行记录页调用后端 `/deploy-runs/import-jenkins` 扫描已纳管 job 并导入 run。
|
||||
- 发布步骤轨迹以后端 run steps 为准,前端不再拉取或渲染流程图 XML。
|
||||
- Agent 面板调用后端 Agent proxy,前端只传 DevOps 场景参数。
|
||||
- Agent 配置页调用后端 `/agent/config`,前端不持久化 key、baseURL 或 model。
|
||||
- Agent 能力限定为发布风险摘要、失败诊断、Runbook 问答、发布说明草稿和事故复盘草稿。
|
||||
验证命令:`npm test`、`npm run build`。真实模型与生产发布验收必须与本地测试分开记录。
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 极简部署与只读 Agent 验证
|
||||
|
||||
本记录说明上线前的验证范围。生产发布由现有 Gitea master webhook → Jenkins → 部署脚本执行,实际结果以目标构建和线上接口验收为准。
|
||||
|
||||
## 界面
|
||||
|
||||
首页仅展示项目、部署状态及日志入口,正在部署的项目优先;发布、权限与设置收进更多菜单。记录详情只保留一套步骤与日志面板。助手可从首页直接提问,也可关联某次发布。
|
||||
|
||||
已检查桌面布局和窄屏布局;截图为本地联调数据,不能代表生产状态。
|
||||
|
||||
## 自动化
|
||||
|
||||
- 前端 `npm test`:12 项回归,覆盖请求、排序、权限、迟到请求和有界助手上下文。
|
||||
- 前端 `npm run build`:TypeScript 与 Vite 生产构建。
|
||||
- 后端 `npm run lint`、`npm test -- --runInBand`、`npm run prisma:generate`、`npm run build`。
|
||||
- 后端回归额外覆盖只读工具、授权范围、模型循环/并发上限、流式读取大小、密钥脱敏和个人历史隔离。
|
||||
- `git diff --check` 检查两个仓库。
|
||||
|
||||
Vite 仍有依赖内部 `@vueuse/core` 的两条 PURE annotation 提示,不阻断构建。本次没有增加运行时依赖。
|
||||
|
||||
## 真实模型与系统
|
||||
|
||||
使用用户提供的服务端 DeepSeek 密钥进行真实调用;本地模型配置受 Git 忽略,不输出密钥。
|
||||
|
||||
- 项目问答:模型调用 `list_projects`,根据真实查询返回 6 个纳管项目和来源。
|
||||
- Jenkins 问答:模型调用 `recent_builds`,实时读取 `devops-platform-web/production` 的构建结果,区分构建、平台部署记录与服务健康。
|
||||
- 本地平台未连接生产数据库时明确标记 memory 数据源,不将种子记录当成线上部署。
|
||||
- 生产还需验证真实数据库问答、持久化来源、页面日志、Jenkins 成功构建及资源占用。
|
||||
|
||||
服务器基线:约 3.7GB 总内存、约 1.4GB 可用,API RSS 约 110MB。API 与 Web 顺序部署,避免同时构建。
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
+3
-2
@@ -1,10 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>devops-platform-web</title>
|
||||
<meta name="theme-color" content="#f8f9fb" />
|
||||
<title>DevOps · 发布工作空间</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
+2
-1
@@ -7,7 +7,8 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"test": "node --test tests/*.test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
|
||||
+8
-1
@@ -1,3 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ElConfigProvider } from 'element-plus'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterView />
|
||||
<ElConfigProvider :locale="zhCn">
|
||||
<RouterView />
|
||||
</ElConfigProvider>
|
||||
</template>
|
||||
|
||||
@@ -1,480 +1,431 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 全局右侧 Agent 抽屉,只展示后端受控的 DevOps 场景能力和上下文摘要。
|
||||
*/
|
||||
import { Close, Promotion } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import { Close, Promotion, Plus } from '@element-plus/icons-vue'
|
||||
import { nextTick, onMounted, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAssistantStore } from '../stores/assistant'
|
||||
import { usePlatformStore } from '../stores/platform'
|
||||
import type { AgentInvocation, AgentMode, AgentPurpose } from '../types/devops'
|
||||
|
||||
type AgentMessage = {
|
||||
id: string
|
||||
role: 'user' | 'assistant'
|
||||
title: string
|
||||
content: string
|
||||
contextSummary?: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
import { useSessionStore } from '../stores/session'
|
||||
import type { AgentSource, AgentInvocation } from '../types/devops'
|
||||
|
||||
const emit = defineEmits<{ close: [] }>()
|
||||
const assistant = useAssistantStore()
|
||||
const platform = usePlatformStore()
|
||||
const selectedMode = ref<AgentMode>('risk')
|
||||
const selectedProject = ref('')
|
||||
const selectedRun = ref('')
|
||||
const prompt = ref('帮我检查当前发布是否存在配置、构建或通知风险。')
|
||||
const sending = ref(false)
|
||||
const session = useSessionStore()
|
||||
const router = useRouter()
|
||||
const prompt = ref('')
|
||||
const messageList = ref<HTMLElement>()
|
||||
const historyOpen = ref(false)
|
||||
const historyLoading = ref(false)
|
||||
const messages = ref<AgentMessage[]>([
|
||||
{
|
||||
id: 'welcome',
|
||||
role: 'assistant',
|
||||
title: 'DevOps Agent',
|
||||
content: '请选择项目和任务类型,我会基于平台已有的发布、构建、流程和配置上下文生成结果。',
|
||||
createdAt: formatTime(new Date().toISOString()),
|
||||
},
|
||||
])
|
||||
|
||||
const purposeTitles: Record<AgentPurpose, string> = {
|
||||
'release-risk': '发布风险',
|
||||
'failure-diagnosis': '失败诊断',
|
||||
'runbook-qa': 'Runbook',
|
||||
'release-note': '发布说明',
|
||||
'incident-review': '事故复盘',
|
||||
}
|
||||
|
||||
const activeCard = computed(() => {
|
||||
return platform.agentCards.find((card) => card.mode === selectedMode.value)
|
||||
const historyError = ref('')
|
||||
const suggestions = ['最近的部署情况怎么样?', '目前有哪些主要项目?', '最近有哪些失败的部署?']
|
||||
onMounted(() => {
|
||||
void assistant.loadStatus()
|
||||
})
|
||||
|
||||
const failedRunOptions = computed(() => {
|
||||
return platform.failedRuns.filter((run) => !selectedProject.value || run.projectKey === selectedProject.value)
|
||||
})
|
||||
|
||||
const requiresRunSelection = computed(() =>
|
||||
selectedMode.value === 'diagnosis' || selectedMode.value === 'incidentReview',
|
||||
)
|
||||
|
||||
const sendDisabled = computed(() => {
|
||||
if (sending.value || !prompt.value.trim()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return requiresRunSelection.value && !selectedRun.value
|
||||
})
|
||||
|
||||
const purpose = computed<AgentPurpose>(() => {
|
||||
if (selectedMode.value === 'diagnosis') {
|
||||
return 'failure-diagnosis'
|
||||
}
|
||||
|
||||
if (selectedMode.value === 'incidentReview') {
|
||||
return 'incident-review'
|
||||
}
|
||||
|
||||
if (selectedMode.value === 'runbook') {
|
||||
return 'runbook-qa'
|
||||
}
|
||||
|
||||
if (selectedMode.value === 'releaseNotes') {
|
||||
return 'release-note'
|
||||
}
|
||||
|
||||
return 'release-risk'
|
||||
})
|
||||
|
||||
watch(
|
||||
() => platform.projects,
|
||||
(projects) => {
|
||||
if (!selectedProject.value && projects[0]) {
|
||||
selectedProject.value = projects[0].key
|
||||
}
|
||||
() => [assistant.messages.length, assistant.pending],
|
||||
async () => {
|
||||
await nextTick()
|
||||
if (messageList.value) messageList.value.scrollTop = messageList.value.scrollHeight
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(failedRunOptions, (runs) => {
|
||||
if (requiresRunSelection.value) {
|
||||
selectedRun.value = runs[0]?.id ?? ''
|
||||
}
|
||||
})
|
||||
|
||||
watch(selectedMode, (mode) => {
|
||||
if (mode === 'diagnosis' || mode === 'incidentReview') {
|
||||
selectedRun.value = failedRunOptions.value[0]?.id ?? ''
|
||||
}
|
||||
|
||||
if (mode === 'diagnosis') {
|
||||
prompt.value = '请根据最近失败 run 的 Jenkins 日志摘要和流程节点给出排查步骤。'
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === 'incidentReview') {
|
||||
prompt.value = '请基于这个失败 run 生成事故复盘草稿,包含时间线、影响、根因假设和预防项。'
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === 'runbook') {
|
||||
prompt.value = '生产发布失败后,应该先检查哪些平台信息?'
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === 'releaseNotes') {
|
||||
prompt.value = '请为本次 master 发布生成发布说明草稿,并列出验证范围。'
|
||||
return
|
||||
}
|
||||
|
||||
prompt.value = '帮我检查当前发布是否存在配置、构建或通知风险。'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void loadInvocationHistory()
|
||||
})
|
||||
|
||||
async function loadInvocationHistory() {
|
||||
function send(value = prompt.value) {
|
||||
if (!value.trim() || assistant.pending) return
|
||||
prompt.value = ''
|
||||
void assistant.ask(value)
|
||||
}
|
||||
function changeScope() {
|
||||
assistant.startNew()
|
||||
}
|
||||
async function showHistory() {
|
||||
historyOpen.value = !historyOpen.value
|
||||
if (!historyOpen.value) return
|
||||
historyLoading.value = true
|
||||
|
||||
historyError.value = ''
|
||||
try {
|
||||
const invocations = await devopsApi.listAgentInvocations()
|
||||
messages.value = [
|
||||
messages.value[0],
|
||||
...invocations.slice(0, 20).map(toHistoryMessage),
|
||||
]
|
||||
await assistant.loadRecent()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : 'Agent 历史加载失败')
|
||||
historyError.value = error instanceof Error ? error.message : '读取历史失败'
|
||||
} finally {
|
||||
historyLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function sendPrompt() {
|
||||
const text = prompt.value.trim()
|
||||
|
||||
if (!text) {
|
||||
return
|
||||
}
|
||||
|
||||
sending.value = true
|
||||
messages.value.push({
|
||||
id: `user-${Date.now()}`,
|
||||
role: 'user',
|
||||
title: activeCard.value?.title ?? '运维问题',
|
||||
content: text,
|
||||
createdAt: formatTime(new Date().toISOString()),
|
||||
})
|
||||
|
||||
function sourceLocation(source: AgentSource) {
|
||||
return source.kind === 'deployment' && source.runId
|
||||
? { name: 'runs', query: { runId: source.runId } }
|
||||
: { name: 'projects', query: { projectKey: source.projectKey } }
|
||||
}
|
||||
function safeBuildUrl(source: AgentSource): string | undefined {
|
||||
if (source.kind !== 'build' || !source.url) return undefined
|
||||
try {
|
||||
const invocation = await devopsApi.createAgentInvocation({
|
||||
type: purpose.value,
|
||||
projectKey: selectedProject.value || undefined,
|
||||
runId: requiresRunSelection.value ? selectedRun.value || undefined : undefined,
|
||||
promptSummary: text,
|
||||
})
|
||||
|
||||
messages.value.push({
|
||||
id: invocation.id,
|
||||
role: 'assistant',
|
||||
title: invocation.status === 'success' ? 'Agent 结果' : 'Agent 调用失败',
|
||||
content: invocation.resultMarkdown || 'Agent 未返回内容',
|
||||
contextSummary: invocation.contextSummary,
|
||||
createdAt: formatTime(invocation.createdAt),
|
||||
})
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : 'Agent 调用失败')
|
||||
} finally {
|
||||
sending.value = false
|
||||
const url = new URL(source.url)
|
||||
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password
|
||||
? url.toString()
|
||||
: undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function toHistoryMessage(invocation: AgentInvocation): AgentMessage {
|
||||
return {
|
||||
id: invocation.id,
|
||||
role: 'assistant',
|
||||
title: `${purposeTitles[invocation.type]} · ${statusLabel(invocation.status)}`,
|
||||
content: [
|
||||
`问题:${invocation.promptSummary}`,
|
||||
'',
|
||||
invocation.resultMarkdown || 'Agent 未返回内容',
|
||||
].join('\n'),
|
||||
contextSummary: invocation.contextSummary,
|
||||
createdAt: formatTime(invocation.createdAt),
|
||||
}
|
||||
function restoreHistory(record: AgentInvocation) {
|
||||
assistant.restore(record)
|
||||
historyOpen.value = false
|
||||
}
|
||||
|
||||
function statusLabel(status: AgentInvocation['status']): string {
|
||||
if (status === 'success') {
|
||||
return '成功'
|
||||
}
|
||||
|
||||
if (status === 'failed') {
|
||||
return '失败'
|
||||
}
|
||||
|
||||
if (status === 'running') {
|
||||
return '运行中'
|
||||
}
|
||||
|
||||
return '等待中'
|
||||
function openSettings() {
|
||||
emit('close')
|
||||
void router.push({ name: 'settings', query: { tab: 'agent' } })
|
||||
}
|
||||
|
||||
function handleComposerKeydown(event: KeyboardEvent) {
|
||||
if (event.key !== 'Enter' || (!event.metaKey && !event.ctrlKey)) {
|
||||
return
|
||||
}
|
||||
|
||||
function keydown(event: KeyboardEvent) {
|
||||
if (event.isComposing || event.key !== 'Enter' || (!event.metaKey && !event.ctrlKey)) return
|
||||
event.preventDefault()
|
||||
void sendPrompt()
|
||||
}
|
||||
|
||||
function formatTime(value: string): string {
|
||||
const date = new Date(value)
|
||||
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return value
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(date)
|
||||
send()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside class="agent-drawer">
|
||||
<header class="agent-header">
|
||||
<div>
|
||||
<strong>Agent</strong>
|
||||
<span>{{ activeCard?.title ?? 'DevOps 助手' }}</span>
|
||||
</div>
|
||||
<ElButton :icon="Close" circle text @click="emit('close')" />
|
||||
<div><strong>运维助手</strong><span>查项目、部署和构建,回答附来源</span></div>
|
||||
<ElButton text :icon="Close" aria-label="关闭运维助手" @click="emit('close')" />
|
||||
</header>
|
||||
|
||||
<div class="agent-context">
|
||||
<ElSegmented
|
||||
v-model="selectedMode"
|
||||
class="mode-switch"
|
||||
:options="[
|
||||
{ label: '风险', value: 'risk' },
|
||||
{ label: '诊断', value: 'diagnosis' },
|
||||
{ label: 'Runbook', value: 'runbook' },
|
||||
{ label: '发布说明', value: 'releaseNotes' },
|
||||
{ label: '复盘', value: 'incidentReview' },
|
||||
]"
|
||||
/>
|
||||
|
||||
<ElSelect v-model="selectedProject" filterable placeholder="选择项目">
|
||||
<ElOption
|
||||
<div class="agent-scope">
|
||||
<ElSelect
|
||||
v-model="assistant.projectKey"
|
||||
clearable
|
||||
filterable
|
||||
:disabled="assistant.pending"
|
||||
placeholder="所有可访问项目"
|
||||
aria-label="助手查询范围"
|
||||
@change="changeScope"
|
||||
><ElOption
|
||||
v-for="project in platform.projects"
|
||||
:key="project.key"
|
||||
:label="project.name"
|
||||
:value="project.key"
|
||||
/>
|
||||
</ElSelect>
|
||||
|
||||
<ElSelect
|
||||
v-if="requiresRunSelection"
|
||||
v-model="selectedRun"
|
||||
filterable
|
||||
placeholder="选择失败 Run"
|
||||
:value="project.key" /></ElSelect
|
||||
><ElButton
|
||||
text
|
||||
:icon="Plus"
|
||||
:disabled="assistant.pending"
|
||||
aria-label="开启新对话"
|
||||
title="开启新对话"
|
||||
@click="assistant.startNew"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="assistant.statusError" class="agent-notice error" role="alert">
|
||||
{{ assistant.statusError }}<ElButton text @click="assistant.loadStatus">重试</ElButton>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="assistant.status && !assistant.status.configured"
|
||||
class="agent-notice"
|
||||
role="status"
|
||||
>
|
||||
尚未接入模型。<ElButton
|
||||
v-if="session.role === 'super_admin'"
|
||||
text
|
||||
type="primary"
|
||||
@click="openSettings"
|
||||
>配置模型</ElButton
|
||||
><span v-else>请联系管理员配置。</span>
|
||||
</div>
|
||||
<div v-if="assistant.status?.dataSource === 'memory'" class="data-scope">
|
||||
平台部署记录来自本地开发数据;Jenkins 构建可按需查询。
|
||||
</div>
|
||||
<div v-if="assistant.runId" class="data-scope">
|
||||
关联发布:<span class="mono">{{ assistant.runId }}</span>
|
||||
</div>
|
||||
<div ref="messageList" class="message-list" aria-live="polite" aria-relevant="additions">
|
||||
<div v-if="!assistant.messages.length" class="assistant-welcome">
|
||||
<h2>想了解什么?</h2>
|
||||
<p>直接提问,助手会按需读取你有权限的记录。</p>
|
||||
<button
|
||||
v-for="question in suggestions"
|
||||
:key="question"
|
||||
class="suggestion"
|
||||
:disabled="assistant.pending || assistant.status?.configured === false"
|
||||
@click="send(question)"
|
||||
>
|
||||
{{ question }}<span aria-hidden="true">↗</span>
|
||||
</button>
|
||||
</div>
|
||||
<article
|
||||
v-for="message in assistant.messages"
|
||||
:key="message.id"
|
||||
class="agent-message"
|
||||
:class="[message.role, { failed: message.status === 'failed' }]"
|
||||
>
|
||||
<ElOption
|
||||
v-for="run in failedRunOptions"
|
||||
:key="run.id"
|
||||
:label="`${run.id} · ${run.ref}`"
|
||||
:value="run.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
<div v-if="requiresRunSelection && !selectedRun" class="agent-context-hint">
|
||||
当前项目没有可用于分析的失败 run。
|
||||
<strong>{{
|
||||
message.role === 'user' ? '你' : message.status === 'failed' ? '查询未完成' : '运维助手'
|
||||
}}</strong>
|
||||
<p>{{ message.content }}</p>
|
||||
<details v-if="message.sources?.length" class="sources" open>
|
||||
<summary>本次查询来源 · {{ message.sources.length }}</summary>
|
||||
<template v-for="source in message.sources" :key="source.id"
|
||||
><a
|
||||
v-if="safeBuildUrl(source)"
|
||||
:href="safeBuildUrl(source)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>[{{ source.id }}] {{ source.label }} ↗</a
|
||||
><RouterLink v-else :to="sourceLocation(source)" @click="emit('close')"
|
||||
>[{{ source.id }}] {{ source.label }} →</RouterLink
|
||||
></template
|
||||
>
|
||||
</details>
|
||||
<details v-if="message.tools?.length" class="tool-trace">
|
||||
<summary>查询过程 · {{ message.tools.length }} 步</summary>
|
||||
<p v-for="(tool, index) in message.tools" :key="index">
|
||||
{{ tool.status === 'success' ? '✓' : '!' }} {{ tool.summary }}
|
||||
</p>
|
||||
</details>
|
||||
</article>
|
||||
<div v-if="assistant.pending" class="agent-pending" role="status">正在查询并整理回答…</div>
|
||||
</div>
|
||||
<div class="history-area">
|
||||
<button class="history-toggle" @click="showHistory">
|
||||
{{ historyOpen ? '收起最近提问' : '最近提问' }}
|
||||
</button>
|
||||
<div v-if="historyOpen" class="history-list">
|
||||
<span v-if="historyLoading">正在读取…</span
|
||||
><span v-else-if="historyError" role="alert">{{ historyError }}</span
|
||||
><span v-else-if="!assistant.recent.length">暂无提问记录</span
|
||||
><button
|
||||
v-for="record in assistant.recent"
|
||||
:key="record.id"
|
||||
:disabled="assistant.pending"
|
||||
@click="restoreHistory(record)"
|
||||
>
|
||||
{{ record.promptSummary }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="message-list">
|
||||
<div v-if="historyLoading" class="history-loading">正在加载历史记录...</div>
|
||||
<article v-for="message in messages" :key="message.id" class="agent-message" :class="message.role">
|
||||
<div class="message-meta">
|
||||
<strong>{{ message.title }}</strong>
|
||||
<span>{{ message.createdAt }}</span>
|
||||
</div>
|
||||
<p>{{ message.content }}</p>
|
||||
<small v-if="message.contextSummary" class="message-context">
|
||||
上下文:{{ message.contextSummary }}
|
||||
</small>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<footer class="agent-composer">
|
||||
<form class="agent-composer" @submit.prevent="send()">
|
||||
<ElInput
|
||||
v-model="prompt"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
maxlength="300"
|
||||
show-word-limit
|
||||
:rows="3"
|
||||
maxlength="2000"
|
||||
resize="none"
|
||||
@keydown="handleComposerKeydown"
|
||||
placeholder="问问最近部署、项目情况或失败原因…"
|
||||
aria-label="向运维助手提问"
|
||||
@keydown="keydown"
|
||||
/>
|
||||
<ElButton
|
||||
type="primary"
|
||||
:icon="Promotion"
|
||||
:loading="sending"
|
||||
:disabled="sendDisabled"
|
||||
@click="sendPrompt"
|
||||
>
|
||||
发送
|
||||
</ElButton>
|
||||
</footer>
|
||||
<div class="composer-footer">
|
||||
<span>只读查询 · ⌘ / Ctrl + Enter</span
|
||||
><ElButton
|
||||
type="primary"
|
||||
:icon="Promotion"
|
||||
:loading="assistant.pending"
|
||||
:disabled="!prompt.trim() || assistant.pending || assistant.status?.configured === false"
|
||||
native-type="submit"
|
||||
>提问</ElButton
|
||||
>
|
||||
</div>
|
||||
</form>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-drawer {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
display: flex;
|
||||
flex: 0 0 420px;
|
||||
flex-direction: column;
|
||||
width: 420px;
|
||||
height: 100vh;
|
||||
border-left: 1px solid #dfe7f2;
|
||||
background: #ffffff;
|
||||
box-shadow: -8px 0 22px rgb(15 23 42 / 8%);
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.agent-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 64px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid #edf1f7;
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.agent-header strong,
|
||||
.agent-header span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.agent-header strong {
|
||||
color: #111827;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.agent-header span {
|
||||
margin-top: 3px;
|
||||
color: #748093;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.agent-context {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid #edf1f7;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.mode-switch {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.agent-context-hint {
|
||||
color: #8a5a00;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
min-height: 0;
|
||||
padding: 16px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.history-loading {
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.agent-message {
|
||||
max-width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
}
|
||||
|
||||
.agent-message.user {
|
||||
border-color: #bfdbfe;
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.message-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.message-meta strong {
|
||||
color: #172033;
|
||||
}
|
||||
|
||||
.message-meta span {
|
||||
flex-shrink: 0;
|
||||
color: #8a95a7;
|
||||
}
|
||||
|
||||
.agent-message p {
|
||||
margin: 0;
|
||||
color: #334155;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.message-context {
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--text);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.agent-composer {
|
||||
.agent-header span {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
.agent-scope {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.agent-notice {
|
||||
padding: 10px 18px;
|
||||
background: #fffaf0;
|
||||
color: #936b29;
|
||||
font-size: 12px;
|
||||
}
|
||||
.agent-notice.error {
|
||||
background: #fff5f5;
|
||||
color: #ad4b4b;
|
||||
}
|
||||
.data-scope {
|
||||
padding: 8px 18px;
|
||||
background: #fafafd;
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
line-height: 1.6;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.message-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 22px 20px;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
.assistant-welcome {
|
||||
padding: 20px 0;
|
||||
}
|
||||
.assistant-welcome h2 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 20px;
|
||||
font-weight: 550;
|
||||
}
|
||||
.assistant-welcome p {
|
||||
margin: 0 0 28px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.7;
|
||||
}
|
||||
.suggestion {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
margin: 9px 0;
|
||||
padding: 13px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 7px;
|
||||
background: #fcfcfe;
|
||||
color: #636a78;
|
||||
font-size: 12px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.suggestion:hover {
|
||||
color: var(--accent);
|
||||
border-color: #cec7e5;
|
||||
}
|
||||
.suggestion:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
.agent-message {
|
||||
margin-bottom: 26px;
|
||||
color: #454d5d;
|
||||
}
|
||||
.agent-message > strong {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
.agent-message > p {
|
||||
margin: 9px 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.9;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.agent-message.user {
|
||||
padding: 12px 14px;
|
||||
border-radius: 8px;
|
||||
background: #f5f3fa;
|
||||
}
|
||||
.agent-message.user > p {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.agent-message.failed {
|
||||
color: #a44a4a;
|
||||
}
|
||||
.sources {
|
||||
margin-top: 16px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.sources summary,
|
||||
.tool-trace summary {
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sources a {
|
||||
display: block;
|
||||
padding: 7px 0 0;
|
||||
color: var(--accent);
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.sources a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.tool-trace {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.tool-trace p {
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
.agent-pending {
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
.history-area {
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 8px 18px;
|
||||
}
|
||||
.history-toggle {
|
||||
padding: 3px 0;
|
||||
border: 0;
|
||||
color: var(--text-muted);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 10px;
|
||||
}
|
||||
.history-list {
|
||||
max-height: 150px;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 14px 16px 16px;
|
||||
border-top: 1px solid #edf1f7;
|
||||
background: #ffffff;
|
||||
gap: 5px;
|
||||
padding: 10px 0;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.agent-composer .el-button {
|
||||
align-self: flex-end;
|
||||
.history-list button {
|
||||
padding: 7px 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #5a526f;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.agent-drawer {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
z-index: 20;
|
||||
width: min(420px, 100vw);
|
||||
max-width: 100vw;
|
||||
}
|
||||
.agent-composer {
|
||||
padding: 12px 16px 16px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.composer-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.composer-footer span {
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import type { Component } from 'vue'
|
||||
|
||||
defineProps<{
|
||||
label: string
|
||||
value: string | number
|
||||
caption: string
|
||||
icon: Component
|
||||
tone?: 'neutral' | 'success' | 'warning' | 'danger'
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="metric-tile" :class="tone || 'neutral'">
|
||||
<div class="metric-icon">
|
||||
<ElIcon>
|
||||
<component :is="icon" />
|
||||
</ElIcon>
|
||||
</div>
|
||||
<div>
|
||||
<span>{{ label }}</span>
|
||||
<strong>{{ value }}</strong>
|
||||
<small>{{ caption }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.metric-tile {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
min-height: 108px;
|
||||
padding: 16px;
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.metric-icon {
|
||||
display: grid;
|
||||
flex: 0 0 38px;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
place-items: center;
|
||||
border-radius: 8px;
|
||||
background: #edf4ff;
|
||||
color: #1d5fd0;
|
||||
}
|
||||
|
||||
span,
|
||||
small {
|
||||
display: block;
|
||||
color: #748093;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
strong {
|
||||
display: block;
|
||||
margin: 7px 0 5px;
|
||||
color: #111827;
|
||||
font-size: 24px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.success .metric-icon {
|
||||
background: #e9f8f0;
|
||||
color: #16844a;
|
||||
}
|
||||
|
||||
.warning .metric-icon {
|
||||
background: #fff6df;
|
||||
color: #a96f00;
|
||||
}
|
||||
|
||||
.danger .metric-icon {
|
||||
background: #fff0f0;
|
||||
color: #bc3434;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,394 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 发布执行详情聚合 run 元数据、步骤摘要和按需读取的 Jenkins build 日志。
|
||||
*/
|
||||
import { RefreshRight, Tickets } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import type { JenkinsBuildLog, ReleaseRun } from '../types/devops'
|
||||
import StatusPill from './StatusPill.vue'
|
||||
|
||||
const props = defineProps<{
|
||||
run: ReleaseRun
|
||||
}>()
|
||||
|
||||
const logVisible = ref(false)
|
||||
const logLoading = ref(false)
|
||||
const logText = ref('')
|
||||
const logMeta = ref<JenkinsBuildLog | null>(null)
|
||||
|
||||
const notableSteps = computed(() =>
|
||||
props.run.steps.filter(
|
||||
(step) =>
|
||||
step.status === 'failed' ||
|
||||
step.status === 'skipped' ||
|
||||
step.errorSummary ||
|
||||
step.message ||
|
||||
step.logExcerpt,
|
||||
),
|
||||
)
|
||||
|
||||
const canReadJenkinsLog = computed(
|
||||
() => props.run.jenkinsBuildNumber !== undefined && props.run.jenkinsBuildNumber !== null,
|
||||
)
|
||||
|
||||
const logTitle = computed(() => {
|
||||
const buildNumber = props.run.jenkinsBuildNumber
|
||||
|
||||
return buildNumber ? `Jenkins 日志 #${buildNumber}` : 'Jenkins 日志'
|
||||
})
|
||||
|
||||
function noteLabel(status: string) {
|
||||
return status === 'failed' ? '失败摘要' : '执行提示'
|
||||
}
|
||||
|
||||
function displayText(value?: string | number) {
|
||||
if (value === undefined || value === null || value === '' || value === '-') {
|
||||
return '未返回'
|
||||
}
|
||||
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function finishText() {
|
||||
if (props.run.finishedAt && props.run.finishedAt !== '-') {
|
||||
return props.run.finishedAt
|
||||
}
|
||||
|
||||
if (props.run.status === 'queued' || props.run.status === 'running') {
|
||||
return '未结束'
|
||||
}
|
||||
|
||||
return '未返回'
|
||||
}
|
||||
|
||||
function buildText() {
|
||||
if (props.run.jenkinsBuildNumber !== undefined && props.run.jenkinsBuildNumber !== null) {
|
||||
return `#${props.run.jenkinsBuildNumber}`
|
||||
}
|
||||
|
||||
return '未返回'
|
||||
}
|
||||
|
||||
function resetJenkinsLog() {
|
||||
logVisible.value = false
|
||||
logLoading.value = false
|
||||
logText.value = ''
|
||||
logMeta.value = null
|
||||
}
|
||||
|
||||
async function openJenkinsLog() {
|
||||
if (!canReadJenkinsLog.value) {
|
||||
ElMessage.warning('当前发布单尚未关联 Jenkins build')
|
||||
return
|
||||
}
|
||||
|
||||
logVisible.value = true
|
||||
|
||||
if (!logText.value) {
|
||||
await loadJenkinsLog(0)
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadJenkinsLog() {
|
||||
await loadJenkinsLog(0)
|
||||
}
|
||||
|
||||
async function loadMoreJenkinsLog() {
|
||||
await loadJenkinsLog(logMeta.value?.nextStart ?? 0)
|
||||
}
|
||||
|
||||
async function loadJenkinsLog(start: number) {
|
||||
logLoading.value = true
|
||||
try {
|
||||
const log = await devopsApi.getJenkinsLog(props.run.id, start)
|
||||
logMeta.value = log
|
||||
logText.value = start === 0 ? log.text : `${logText.value}${log.text}`
|
||||
} finally {
|
||||
logLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.run.id, resetJenkinsLog)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="run-execution-details">
|
||||
<dl class="detail-grid">
|
||||
<dt>Run ID</dt>
|
||||
<dd class="mono">{{ displayText(run.id) }}</dd>
|
||||
<dt>项目</dt>
|
||||
<dd>{{ displayText(run.projectName) }}</dd>
|
||||
<dt>环境</dt>
|
||||
<dd>{{ displayText(run.environment) }}</dd>
|
||||
<dt>ref/tag</dt>
|
||||
<dd class="mono">{{ displayText(run.ref) }}</dd>
|
||||
<dt>操作者</dt>
|
||||
<dd>{{ displayText(run.actor) }}</dd>
|
||||
<dt>状态</dt>
|
||||
<dd><StatusPill :state="run.status" /></dd>
|
||||
<dt>开始时间</dt>
|
||||
<dd>{{ displayText(run.startedAt) }}</dd>
|
||||
<dt>结束时间</dt>
|
||||
<dd>{{ finishText() }}</dd>
|
||||
<dt>Jenkins Queue</dt>
|
||||
<dd class="mono">{{ displayText(run.jenkinsQueueId) }}</dd>
|
||||
<dt>Jenkins Build</dt>
|
||||
<dd class="mono">{{ buildText() }}</dd>
|
||||
<dt>Jenkins 日志</dt>
|
||||
<dd>
|
||||
<ElButton
|
||||
size="small"
|
||||
:icon="Tickets"
|
||||
:disabled="!canReadJenkinsLog"
|
||||
:loading="logLoading"
|
||||
@click="openJenkinsLog"
|
||||
>
|
||||
查看日志
|
||||
</ElButton>
|
||||
</dd>
|
||||
<dt>Jenkins 状态</dt>
|
||||
<dd>{{ displayText(run.jenkinsSummary) }}</dd>
|
||||
<dt>Build URL</dt>
|
||||
<dd>
|
||||
<a v-if="run.jenkinsBuildUrl" :href="run.jenkinsBuildUrl" target="_blank" rel="noreferrer">
|
||||
{{ run.jenkinsBuildUrl }}
|
||||
</a>
|
||||
<span v-else>未返回</span>
|
||||
</dd>
|
||||
<dt>Commit</dt>
|
||||
<dd>{{ displayText(run.commitSummary) }}</dd>
|
||||
<dt>备注</dt>
|
||||
<dd>{{ displayText(run.note) }}</dd>
|
||||
</dl>
|
||||
|
||||
<div class="failure-block">
|
||||
<div class="failure-header">
|
||||
<strong>执行提示 / 日志摘要</strong>
|
||||
<span>{{ notableSteps.length ? `${notableSteps.length} 个节点` : '未返回异常或提示' }}</span>
|
||||
</div>
|
||||
<div v-if="notableSteps.length" class="failure-list">
|
||||
<article
|
||||
v-for="step in notableSteps"
|
||||
:key="step.id"
|
||||
class="failure-item"
|
||||
:class="{ danger: step.status === 'failed' }"
|
||||
>
|
||||
<div class="failure-title">
|
||||
<strong>{{ step.name }}</strong>
|
||||
<StatusPill :state="step.status" />
|
||||
</div>
|
||||
<p v-if="step.errorSummary">
|
||||
<span>{{ noteLabel(step.status) }}</span>
|
||||
{{ step.errorSummary }}
|
||||
</p>
|
||||
<p v-if="step.message">
|
||||
<span>执行消息</span>
|
||||
{{ step.message }}
|
||||
</p>
|
||||
<pre v-if="step.logExcerpt">{{ step.logExcerpt }}</pre>
|
||||
<p v-if="!step.errorSummary && !step.message && !step.logExcerpt">
|
||||
<span>节点摘要</span>
|
||||
{{ step.summary }}
|
||||
</p>
|
||||
</article>
|
||||
</div>
|
||||
<div v-else class="empty-line">后端尚未返回异常摘要、执行提示或日志摘要。</div>
|
||||
</div>
|
||||
|
||||
<ElDrawer v-model="logVisible" :title="logTitle" size="min(760px, 92vw)" append-to-body>
|
||||
<div class="jenkins-log-drawer">
|
||||
<div class="jenkins-log-toolbar">
|
||||
<span>
|
||||
{{ logMeta ? `${logMeta.jobPath} · start ${logMeta.start} -> ${logMeta.nextStart}` : '等待读取' }}
|
||||
</span>
|
||||
<div class="log-actions">
|
||||
<ElButton size="small" :icon="RefreshRight" :loading="logLoading" @click="reloadJenkinsLog">
|
||||
重新读取
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-if="logMeta?.hasMore"
|
||||
size="small"
|
||||
:loading="logLoading"
|
||||
@click="loadMoreJenkinsLog"
|
||||
>
|
||||
继续加载
|
||||
</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
<pre v-if="logText" class="jenkins-log-output">{{ logText }}</pre>
|
||||
<div v-else class="empty-line">Jenkins 暂无日志。</div>
|
||||
</div>
|
||||
</ElDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.run-execution-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 112px minmax(0, 1fr);
|
||||
gap: 10px 12px;
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.detail-grid dt {
|
||||
color: #7b8798;
|
||||
}
|
||||
|
||||
.detail-grid dd {
|
||||
margin: 0;
|
||||
min-width: 0;
|
||||
color: #172033;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.detail-grid a {
|
||||
color: #1d5fd0;
|
||||
}
|
||||
|
||||
.detail-grid :deep(.el-button) {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.failure-block {
|
||||
border-top: 1px solid #edf1f7;
|
||||
padding-top: 14px;
|
||||
}
|
||||
|
||||
.failure-header,
|
||||
.failure-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.failure-header strong,
|
||||
.failure-title strong {
|
||||
color: #172033;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.failure-header span {
|
||||
color: #7b8798;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.failure-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.failure-item {
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
}
|
||||
|
||||
.failure-item.danger {
|
||||
border-color: #f0d5d5;
|
||||
background: #fffafa;
|
||||
}
|
||||
|
||||
.failure-item p {
|
||||
margin: 8px 0 0;
|
||||
color: #4b5565;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.failure-item p span {
|
||||
display: inline-block;
|
||||
margin-right: 8px;
|
||||
color: #62572c;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.failure-item.danger p span {
|
||||
color: #9f2f2f;
|
||||
}
|
||||
|
||||
.failure-item pre {
|
||||
max-height: 180px;
|
||||
margin: 10px 0 0;
|
||||
padding: 10px;
|
||||
overflow: auto;
|
||||
border-radius: 6px;
|
||||
background: #172033;
|
||||
color: #eef4ff;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.empty-line {
|
||||
margin-top: 10px;
|
||||
color: #7b8798;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.jenkins-log-drawer {
|
||||
display: flex;
|
||||
min-height: 100%;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.jenkins-log-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: #5f6b7a;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.log-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.jenkins-log-output {
|
||||
flex: 1;
|
||||
min-height: 420px;
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
overflow: auto;
|
||||
border-radius: 6px;
|
||||
background: #111827;
|
||||
color: #e5edf8;
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.detail-grid {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 4px 0;
|
||||
}
|
||||
|
||||
.detail-grid dd + dt {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.jenkins-log-toolbar {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+208
-270
@@ -1,61 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ChatLineRound,
|
||||
Connection,
|
||||
DataAnalysis,
|
||||
DocumentChecked,
|
||||
Fold,
|
||||
Monitor,
|
||||
Operation,
|
||||
Setting,
|
||||
SwitchButton,
|
||||
Tickets,
|
||||
Tools,
|
||||
User,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { ChatLineRound, Monitor, MoreFilled, Refresh, SwitchButton } from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, onUnmounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import GlobalAgentDrawer from '../components/GlobalAgentDrawer.vue'
|
||||
import StatusPill from '../components/StatusPill.vue'
|
||||
import { useAssistantStore } from '../stores/assistant'
|
||||
import { usePlatformStore } from '../stores/platform'
|
||||
import { useSessionStore } from '../stores/session'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const platform = usePlatformStore()
|
||||
const collapsed = ref(false)
|
||||
const agentOpen = ref(false)
|
||||
|
||||
const activeMenu = computed(() => route.path)
|
||||
|
||||
const menus = computed(() => [
|
||||
{ path: '/overview', label: '总览', icon: DataAnalysis },
|
||||
{ path: '/projects', label: '项目配置', icon: Operation },
|
||||
...(session.role === 'super_admin'
|
||||
? [{ path: '/members', label: '成员权限', icon: User }]
|
||||
: []),
|
||||
{ path: '/releases', label: '发布中心', icon: DocumentChecked },
|
||||
{ path: '/runs', label: '运行记录', icon: Tickets },
|
||||
...(session.role === 'super_admin'
|
||||
? [{ path: '/settings', label: '系统配置', icon: Setting }]
|
||||
: []),
|
||||
])
|
||||
|
||||
const jenkinsStatus = computed(() => {
|
||||
return platform.integrations.find((item) => item.key === 'jenkins')?.state || 'offline'
|
||||
const session = useSessionStore()
|
||||
const assistant = useAssistantStore()
|
||||
const agentOpen = computed({
|
||||
get: () => assistant.isOpen,
|
||||
set: (value) => {
|
||||
assistant.isOpen = value
|
||||
},
|
||||
})
|
||||
|
||||
const apiModeLabel = computed(() => {
|
||||
return '后端 API'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (!platform.projects.length) {
|
||||
void platform.loadAll()
|
||||
const canPublish = computed(() =>
|
||||
platform.projects.some((project) => platform.canBuildProject(project.key)),
|
||||
)
|
||||
let timer: ReturnType<typeof setInterval> | undefined
|
||||
let refreshing = false
|
||||
async function refresh() {
|
||||
try {
|
||||
await platform.loadAll()
|
||||
} catch {
|
||||
/* 页面提供真实错误与重试。 */
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
platform.reset()
|
||||
assistant.reset()
|
||||
void refresh()
|
||||
timer = setInterval(async () => {
|
||||
if (document.hidden || !platform.runningRuns.length || refreshing || platform.loading) return
|
||||
refreshing = true
|
||||
try {
|
||||
await platform.refreshRuns()
|
||||
} catch {
|
||||
/* 页面显示错误,保留上次数据。 */
|
||||
} finally {
|
||||
refreshing = false
|
||||
}
|
||||
}, 12000)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
clearInterval(timer)
|
||||
platform.reset()
|
||||
assistant.reset()
|
||||
})
|
||||
|
||||
async function logout() {
|
||||
await session.logout()
|
||||
await router.push('/login')
|
||||
@@ -63,250 +58,193 @@ async function logout() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElContainer class="layout">
|
||||
<ElAside class="sidebar" :width="collapsed ? '72px' : '232px'">
|
||||
<div class="brand" :class="{ collapsed }">
|
||||
<ElIcon>
|
||||
<Monitor />
|
||||
</ElIcon>
|
||||
<span v-if="!collapsed">DevOps 运维平台</span>
|
||||
</div>
|
||||
<ElMenu :default-active="activeMenu" router :collapse="collapsed" class="nav-menu">
|
||||
<ElMenuItem v-for="item in menus" :key="item.path" :index="item.path">
|
||||
<ElIcon>
|
||||
<component :is="item.icon" />
|
||||
</ElIcon>
|
||||
<template #title>{{ item.label }}</template>
|
||||
</ElMenuItem>
|
||||
</ElMenu>
|
||||
</ElAside>
|
||||
|
||||
<ElContainer class="workspace" :class="{ 'agent-open': agentOpen }">
|
||||
<ElContainer class="content-shell">
|
||||
<ElHeader class="topbar">
|
||||
<div class="toolbar">
|
||||
<ElButton :icon="Fold" circle @click="collapsed = !collapsed" />
|
||||
<div class="env-strip">
|
||||
<span>本地开发</span>
|
||||
<StatusPill :state="jenkinsStatus" text="Jenkins" />
|
||||
<ElTag type="success" round>
|
||||
{{ apiModeLabel }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<ElButton :icon="ChatLineRound" :type="agentOpen ? 'primary' : 'default'" @click="agentOpen = !agentOpen">
|
||||
Agent
|
||||
</ElButton>
|
||||
<ElTag type="primary" effect="plain" round>
|
||||
<ElIcon><Connection /></ElIcon>
|
||||
后端已联通
|
||||
</ElTag>
|
||||
<ElDropdown>
|
||||
<ElButton>
|
||||
{{ session.displayName || session.operator }}
|
||||
<ElIcon class="el-icon--right"><Tools /></ElIcon>
|
||||
</ElButton>
|
||||
<template #dropdown>
|
||||
<ElDropdownMenu>
|
||||
<ElDropdownItem disabled>角色:{{ session.roleLabel }}</ElDropdownItem>
|
||||
<ElDropdownItem :icon="SwitchButton" @click="logout">退出登录</ElDropdownItem>
|
||||
</ElDropdownMenu>
|
||||
</template>
|
||||
</ElDropdown>
|
||||
</div>
|
||||
</ElHeader>
|
||||
<nav class="mobile-nav" aria-label="移动端模块导航">
|
||||
<RouterLink
|
||||
v-for="item in menus"
|
||||
:key="`mobile-${item.path}`"
|
||||
v-slot="{ navigate }"
|
||||
custom
|
||||
:to="item.path"
|
||||
<div class="app-layout">
|
||||
<a class="skip-link" href="#main-content">跳转到主要内容</a>
|
||||
<header class="topbar">
|
||||
<div class="topbar-inner">
|
||||
<RouterLink class="brand" to="/overview" aria-label="DevOps 项目"
|
||||
><ElIcon aria-hidden="true"><Monitor /></ElIcon><span>DevOps</span></RouterLink
|
||||
>
|
||||
<nav class="primary-nav" aria-label="主要导航">
|
||||
<RouterLink to="/overview" :aria-current="route.name === 'overview' ? 'page' : undefined"
|
||||
>项目</RouterLink
|
||||
><RouterLink to="/runs" :aria-current="route.name === 'runs' ? 'page' : undefined"
|
||||
>记录</RouterLink
|
||||
>
|
||||
<button
|
||||
class="mobile-nav-item"
|
||||
:class="{ active: activeMenu === item.path }"
|
||||
type="button"
|
||||
@click="navigate"
|
||||
>
|
||||
<ElIcon>
|
||||
<component :is="item.icon" />
|
||||
</ElIcon>
|
||||
<span>{{ item.label }}</span>
|
||||
</button>
|
||||
</RouterLink>
|
||||
</nav>
|
||||
<ElMain class="main-area" v-loading="platform.loading">
|
||||
<RouterView />
|
||||
</ElMain>
|
||||
</ElContainer>
|
||||
<GlobalAgentDrawer v-if="agentOpen" @close="agentOpen = false" />
|
||||
</ElContainer>
|
||||
</ElContainer>
|
||||
<div class="topbar-actions">
|
||||
<ElButton
|
||||
text
|
||||
:icon="Refresh"
|
||||
:loading="platform.loading"
|
||||
aria-label="刷新部署数据"
|
||||
title="刷新部署数据"
|
||||
@click="refresh"
|
||||
/><ElButton
|
||||
text
|
||||
:icon="ChatLineRound"
|
||||
:aria-expanded="agentOpen"
|
||||
@click="agentOpen = !agentOpen"
|
||||
>助手</ElButton
|
||||
><ElDropdown trigger="click"
|
||||
><ElButton text :icon="MoreFilled" aria-label="更多功能" /><template #dropdown
|
||||
><ElDropdownMenu
|
||||
><ElDropdownItem v-if="canPublish"
|
||||
><RouterLink to="/releases">发起发布</RouterLink></ElDropdownItem
|
||||
><ElDropdownItem v-if="session.role === 'super_admin'"
|
||||
><RouterLink to="/projects">项目接入</RouterLink></ElDropdownItem
|
||||
><ElDropdownItem v-if="session.role === 'super_admin'"
|
||||
><RouterLink to="/members">成员权限</RouterLink></ElDropdownItem
|
||||
><ElDropdownItem v-if="session.role === 'super_admin'"
|
||||
><RouterLink to="/settings">设置</RouterLink></ElDropdownItem
|
||||
><ElDropdownItem divided :icon="SwitchButton" @click="logout"
|
||||
>退出 {{ session.displayName || session.operator }}</ElDropdownItem
|
||||
></ElDropdownMenu
|
||||
></template
|
||||
></ElDropdown
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main id="main-content" class="main-area" tabindex="-1" :aria-busy="platform.loading">
|
||||
<ElAlert
|
||||
v-if="platform.loadError"
|
||||
class="load-error"
|
||||
title="部署数据更新失败"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
>{{ platform.loadError }}<span v-if="platform.lastLoadedAt"> · 当前为上次读取结果。</span
|
||||
><ElButton text type="danger" :loading="platform.loading" @click="refresh"
|
||||
>重试</ElButton
|
||||
></ElAlert
|
||||
>
|
||||
<div v-if="platform.loading && !platform.lastLoadedAt" class="initial-loading" role="status">
|
||||
正在读取部署情况…
|
||||
</div>
|
||||
<div v-else-if="platform.loadError && !platform.lastLoadedAt" class="quiet-empty">
|
||||
暂时无法读取项目,请检查后端服务后重试。
|
||||
</div>
|
||||
<RouterView v-else />
|
||||
</main>
|
||||
<ElDrawer
|
||||
v-model="agentOpen"
|
||||
title="运维助手"
|
||||
:with-header="false"
|
||||
size="480px"
|
||||
class="agent-panel"
|
||||
destroy-on-close
|
||||
><GlobalAgentDrawer v-if="agentOpen" @close="agentOpen = false"
|
||||
/></ElDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.layout {
|
||||
.app-layout {
|
||||
min-height: 100vh;
|
||||
background: #f5f7fb;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
height: 100vh;
|
||||
border-right: 1px solid #e0e6ef;
|
||||
background: #101828;
|
||||
transition: width 0.2s ease;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
height: 64px;
|
||||
padding: 0 20px;
|
||||
border-bottom: 1px solid rgb(255 255 255 / 9%);
|
||||
color: #ffffff;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.brand.collapsed {
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.brand .el-icon {
|
||||
color: #7dd3fc;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.nav-menu {
|
||||
--el-menu-bg-color: #101828;
|
||||
--el-menu-text-color: #b8c2d6;
|
||||
--el-menu-active-color: #ffffff;
|
||||
--el-menu-hover-bg-color: #1d2939;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.workspace,
|
||||
.content-shell {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.workspace.agent-open .content-shell {
|
||||
width: calc(100% - 420px);
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 64px;
|
||||
border-bottom: 1px solid #e0e6ef;
|
||||
background: #ffffff;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.mobile-nav {
|
||||
display: none;
|
||||
gap: 8px;
|
||||
max-width: 100%;
|
||||
padding: 10px 12px;
|
||||
overflow-x: auto;
|
||||
border-bottom: 1px solid #e0e6ef;
|
||||
background: #ffffff;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.mobile-nav::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-nav-item {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
min-width: 88px;
|
||||
height: 38px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #d8e2ef;
|
||||
border-radius: 8px;
|
||||
background: #f8fafc;
|
||||
color: #475467;
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mobile-nav-item.active {
|
||||
border-color: #7aa7f7;
|
||||
background: #edf4ff;
|
||||
color: #1d5fd0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.mobile-nav-item .el-icon {
|
||||
flex: 0 0 auto;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.env-strip {
|
||||
.topbar-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #596578;
|
||||
gap: 44px;
|
||||
height: 100%;
|
||||
max-width: 1220px;
|
||||
padding: 0 30px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.brand {
|
||||
display: inline-flex;
|
||||
gap: 9px;
|
||||
align-items: center;
|
||||
color: #303543;
|
||||
font-size: 17px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
.brand .el-icon {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background: #2d3240;
|
||||
color: #fff;
|
||||
border-radius: 7px;
|
||||
font-size: 17px;
|
||||
}
|
||||
.primary-nav {
|
||||
display: flex;
|
||||
gap: 26px;
|
||||
height: 100%;
|
||||
}
|
||||
.primary-nav a {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
padding: 0 2px;
|
||||
border-bottom: 2px solid transparent;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.main-area {
|
||||
padding: 22px;
|
||||
overflow-x: hidden;
|
||||
.primary-nav a[aria-current='page'] {
|
||||
color: var(--accent);
|
||||
border-color: var(--accent);
|
||||
font-weight: 550;
|
||||
}
|
||||
|
||||
@media (max-width: 840px) {
|
||||
.sidebar {
|
||||
.primary-nav a:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
.topbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.main-area {
|
||||
max-width: 1220px;
|
||||
margin: 0 auto;
|
||||
padding: 34px 30px 60px;
|
||||
}
|
||||
.load-error {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.initial-loading {
|
||||
padding: 80px 0;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
@media (max-width: 650px) {
|
||||
.topbar {
|
||||
height: 58px;
|
||||
}
|
||||
.topbar-inner {
|
||||
padding: 0 16px;
|
||||
gap: 23px;
|
||||
}
|
||||
.brand {
|
||||
font-size: 15px;
|
||||
}
|
||||
.brand .el-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-nav {
|
||||
display: flex;
|
||||
.primary-nav {
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
flex-wrap: wrap;
|
||||
height: auto;
|
||||
min-height: 64px;
|
||||
padding: 12px;
|
||||
.primary-nav a {
|
||||
font-size: 12px;
|
||||
}
|
||||
.topbar-actions {
|
||||
gap: 0;
|
||||
}
|
||||
.topbar-actions :deep(.el-button) {
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.main-area {
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.workspace.agent-open .content-shell {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.topbar > .toolbar {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.topbar .env-strip {
|
||||
order: 2;
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.mobile-nav-item {
|
||||
min-width: 82px;
|
||||
padding: 24px 16px 40px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
-18
@@ -3,10 +3,8 @@ import './style.css'
|
||||
import App from './App.vue'
|
||||
import {
|
||||
ElAlert,
|
||||
ElAside,
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElContainer,
|
||||
ElDialog,
|
||||
ElDrawer,
|
||||
ElDropdown,
|
||||
@@ -15,21 +13,14 @@ import {
|
||||
ElEmpty,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElHeader,
|
||||
ElIcon,
|
||||
ElInput,
|
||||
ElLink,
|
||||
ElLoading,
|
||||
ElMain,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElOption,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElSegmented,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
@@ -42,10 +33,8 @@ const app = createApp(App)
|
||||
|
||||
for (const component of [
|
||||
ElAlert,
|
||||
ElAside,
|
||||
ElButton,
|
||||
ElCheckbox,
|
||||
ElContainer,
|
||||
ElDialog,
|
||||
ElDrawer,
|
||||
ElDropdown,
|
||||
@@ -54,20 +43,13 @@ for (const component of [
|
||||
ElEmpty,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElHeader,
|
||||
ElIcon,
|
||||
ElInput,
|
||||
ElLink,
|
||||
ElMain,
|
||||
ElMenu,
|
||||
ElMenuItem,
|
||||
ElOption,
|
||||
ElRadio,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElSegmented,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
ElTable,
|
||||
ElTableColumn,
|
||||
ElTag,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
import type {
|
||||
AgentCard,
|
||||
AgentQuestionPayload,
|
||||
AgentConfigSummary,
|
||||
AgentConnectionTestResult,
|
||||
AgentInvocation,
|
||||
@@ -533,6 +534,21 @@ export const devopsApi = {
|
||||
return data
|
||||
},
|
||||
|
||||
async getAgentStatus(): Promise<{ configured: boolean; dataSource: 'memory' | 'database' }> {
|
||||
const { data } = await http.get('/agent/status')
|
||||
return data
|
||||
},
|
||||
async askAgent(payload: AgentQuestionPayload, signal?: AbortSignal): Promise<AgentInvocation> {
|
||||
const { data } = await http.post<AgentInvocation>('/agent/questions', payload, {
|
||||
timeout: 55_000,
|
||||
signal,
|
||||
})
|
||||
return data
|
||||
},
|
||||
async getAgentQuestions(): Promise<AgentInvocation[]> {
|
||||
const { data } = await http.get<AgentInvocation[]>('/agent/questions')
|
||||
return data
|
||||
},
|
||||
async createAgentInvocation(
|
||||
payload: CreateAgentInvocationPayload,
|
||||
): Promise<AgentInvocation> {
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import type { AgentInvocation, AgentSource, AgentToolTrace } from '../types/devops'
|
||||
|
||||
export type AssistantMessage = {
|
||||
id: string
|
||||
role: 'user' | 'assistant'
|
||||
content: string
|
||||
status: 'success' | 'failed'
|
||||
sources?: AgentSource[]
|
||||
tools?: AgentToolTrace[]
|
||||
}
|
||||
export const useAssistantStore = defineStore('assistant', () => {
|
||||
const isOpen = ref(false)
|
||||
const pending = ref(false)
|
||||
const messages = ref<AssistantMessage[]>([])
|
||||
const projectKey = ref('')
|
||||
const runId = ref('')
|
||||
const status = ref<{ configured: boolean; dataSource: 'memory' | 'database' } | null>(null)
|
||||
const statusError = ref('')
|
||||
const recent = ref<AgentInvocation[]>([])
|
||||
let generation = 0
|
||||
let controller: AbortController | undefined
|
||||
|
||||
async function loadStatus() {
|
||||
const current = generation
|
||||
try {
|
||||
const value = await devopsApi.getAgentStatus()
|
||||
if (current !== generation) return
|
||||
status.value = value
|
||||
statusError.value = ''
|
||||
} catch (error) {
|
||||
if (current === generation)
|
||||
statusError.value = error instanceof Error ? error.message : '无法读取助手状态'
|
||||
}
|
||||
}
|
||||
function open(question = '', context: { projectKey?: string; runId?: string } = {}) {
|
||||
isOpen.value = true
|
||||
if (pending.value) return
|
||||
if (projectKey.value !== (context.projectKey || '') || runId.value !== (context.runId || ''))
|
||||
messages.value = []
|
||||
projectKey.value = context.projectKey || ''
|
||||
runId.value = context.runId || ''
|
||||
if (question.trim()) void ask(question)
|
||||
}
|
||||
async function ask(question: string) {
|
||||
if (pending.value || !question.trim()) return
|
||||
const text = question.trim().slice(0, 2000)
|
||||
const current = generation
|
||||
const priorTurns: Array<{ role: 'user' | 'assistant'; content: string }> = []
|
||||
for (let index = 0; index < messages.value.length - 1; index += 1) {
|
||||
const user = messages.value[index]
|
||||
const answer = messages.value[index + 1]
|
||||
if (user?.role === 'user' && answer?.role === 'assistant' && answer.status === 'success')
|
||||
priorTurns.push(
|
||||
{ role: 'user', content: user.content.slice(0, 1400) },
|
||||
{ role: 'assistant', content: answer.content.slice(0, 1400) },
|
||||
)
|
||||
}
|
||||
const history = priorTurns.slice(-4)
|
||||
pending.value = true
|
||||
messages.value = [
|
||||
...messages.value,
|
||||
{ id: crypto.randomUUID(), role: 'user' as const, content: text, status: 'success' as const },
|
||||
].slice(-12)
|
||||
controller = new AbortController()
|
||||
try {
|
||||
const result = await devopsApi.askAgent(
|
||||
{
|
||||
question: text,
|
||||
projectKey: projectKey.value || undefined,
|
||||
runId: runId.value || undefined,
|
||||
history,
|
||||
},
|
||||
controller.signal,
|
||||
)
|
||||
if (current !== generation) return
|
||||
messages.value.push({
|
||||
id: result.id,
|
||||
role: 'assistant',
|
||||
content: result.resultMarkdown || '助手未返回结果',
|
||||
status: result.status === 'success' ? 'success' : 'failed',
|
||||
sources: result.sources,
|
||||
tools: result.toolExecutions,
|
||||
})
|
||||
} catch (error) {
|
||||
if (current !== generation) return
|
||||
messages.value.push({
|
||||
id: crypto.randomUUID(),
|
||||
role: 'assistant',
|
||||
content: error instanceof Error ? error.message : '查询失败,请重试',
|
||||
status: 'failed',
|
||||
})
|
||||
} finally {
|
||||
if (current === generation) {
|
||||
pending.value = false
|
||||
messages.value = messages.value.slice(-12)
|
||||
}
|
||||
}
|
||||
}
|
||||
async function loadRecent() {
|
||||
const current = generation
|
||||
const records = await devopsApi.getAgentQuestions()
|
||||
if (current === generation) recent.value = records.slice(0, 20)
|
||||
}
|
||||
function startNew() {
|
||||
if (pending.value) return
|
||||
messages.value = []
|
||||
runId.value = ''
|
||||
}
|
||||
function restore(record: AgentInvocation) {
|
||||
if (pending.value) return
|
||||
projectKey.value = record.projectKey || ''
|
||||
runId.value = record.runId || ''
|
||||
messages.value = [
|
||||
{
|
||||
id: `${record.id}-question`,
|
||||
role: 'user',
|
||||
content: record.promptSummary,
|
||||
status: 'success',
|
||||
},
|
||||
{
|
||||
id: record.id,
|
||||
role: 'assistant',
|
||||
content: record.resultMarkdown || '没有回答内容',
|
||||
status: record.status === 'success' ? 'success' : 'failed',
|
||||
sources: record.sources,
|
||||
tools: record.toolExecutions,
|
||||
},
|
||||
]
|
||||
}
|
||||
function reset() {
|
||||
generation += 1
|
||||
controller?.abort()
|
||||
isOpen.value = false
|
||||
pending.value = false
|
||||
messages.value = []
|
||||
recent.value = []
|
||||
projectKey.value = ''
|
||||
runId.value = ''
|
||||
status.value = null
|
||||
statusError.value = ''
|
||||
}
|
||||
return {
|
||||
isOpen,
|
||||
pending,
|
||||
messages,
|
||||
projectKey,
|
||||
runId,
|
||||
status,
|
||||
statusError,
|
||||
recent,
|
||||
open,
|
||||
ask,
|
||||
loadStatus,
|
||||
loadRecent,
|
||||
startNew,
|
||||
restore,
|
||||
reset,
|
||||
}
|
||||
})
|
||||
+126
-58
@@ -5,6 +5,7 @@ import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import { useSessionStore } from './session'
|
||||
import { latestRunsByEnvironment, mergeRunVersions, newestRuns } from '../utils/releases'
|
||||
import type {
|
||||
AgentCard,
|
||||
AuditLogEntry,
|
||||
@@ -32,6 +33,11 @@ type ProjectGiteaWebhookStatus = NonNullable<
|
||||
*/
|
||||
export const usePlatformStore = defineStore('platform', () => {
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
const lastLoadedAt = ref('')
|
||||
let pendingLoad: Promise<void> | undefined
|
||||
let generation = 0
|
||||
let runRevision = 0
|
||||
const dataSource = ref<'backend'>('backend')
|
||||
const projects = ref<ProjectConfig[]>([])
|
||||
const runs = ref<ReleaseRun[]>([])
|
||||
@@ -68,77 +74,123 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
return Boolean(projectKey) && projectPermissionLevel(projectKey) === 'build'
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
const session = useSessionStore()
|
||||
const includeAdminData = session.role === 'super_admin'
|
||||
|
||||
function loadAll(): Promise<void> {
|
||||
if (pendingLoad) return pendingLoad
|
||||
const currentGeneration = generation
|
||||
const requestedRevision = runRevision
|
||||
loading.value = true
|
||||
try {
|
||||
const summary = await devopsApi.getDashboard({ includeAdminConfig: includeAdminData })
|
||||
projects.value = summary.projects
|
||||
runs.value = summary.runs
|
||||
applyProjectRunSummaries()
|
||||
integrations.value = summary.integrations
|
||||
agentCards.value = summary.agentCards
|
||||
settings.value = summary.settings
|
||||
integrationConfig.value = summary.integrationConfig
|
||||
const auditLogsPromise = includeAdminData
|
||||
? devopsApi.getAuditLogs()
|
||||
: Promise.resolve<AuditLogEntry[]>([])
|
||||
const notificationOutboxPromise = includeAdminData
|
||||
? devopsApi.getNotificationOutbox()
|
||||
: Promise.resolve<NotificationOutboxMessage[]>([])
|
||||
const [recentAuditLogs, recentNotificationOutbox] = await Promise.all([
|
||||
auditLogsPromise,
|
||||
notificationOutboxPromise,
|
||||
])
|
||||
auditLogs.value = recentAuditLogs
|
||||
notificationOutbox.value = recentNotificationOutbox
|
||||
applyProjectGiteaDiagnostics()
|
||||
applyProjectJenkinsDiagnostics()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
pendingLoad = (async () => {
|
||||
try {
|
||||
// 核心页面只读取三个接口;管理配置、通知和审计在设置页按需读取。
|
||||
const summary = await devopsApi.getDashboard()
|
||||
if (currentGeneration !== generation) return
|
||||
projects.value = summary.projects
|
||||
if (requestedRevision === runRevision)
|
||||
runs.value = mergeRunVersions(summary.runs, runs.value)
|
||||
applyProjectRunSummaries()
|
||||
integrations.value = summary.integrations
|
||||
agentCards.value = summary.agentCards
|
||||
settings.value = summary.settings
|
||||
applyProjectGiteaDiagnostics()
|
||||
applyProjectJenkinsDiagnostics()
|
||||
lastLoadedAt.value = new Date().toISOString()
|
||||
loadError.value = ''
|
||||
} catch (error) {
|
||||
if (currentGeneration === generation)
|
||||
loadError.value = error instanceof Error ? error.message : '无法读取项目数据,请重试'
|
||||
throw error
|
||||
} finally {
|
||||
if (currentGeneration === generation) {
|
||||
loading.value = false
|
||||
pendingLoad = undefined
|
||||
}
|
||||
}
|
||||
})()
|
||||
return pendingLoad
|
||||
}
|
||||
|
||||
async function loadAdminData() {
|
||||
if (useSessionStore().role !== 'super_admin') return
|
||||
const currentGeneration = generation
|
||||
const [config, recentAuditLogs, recentNotifications] = await Promise.all([
|
||||
devopsApi.getIntegrationConfigStatus(),
|
||||
devopsApi.getAuditLogs(),
|
||||
devopsApi.getNotificationOutbox(),
|
||||
])
|
||||
if (currentGeneration !== generation) return
|
||||
integrationConfig.value = config
|
||||
auditLogs.value = recentAuditLogs
|
||||
notificationOutbox.value = recentNotifications
|
||||
}
|
||||
|
||||
function reset() {
|
||||
generation += 1
|
||||
pendingLoad = undefined
|
||||
loading.value = false
|
||||
loadError.value = ''
|
||||
lastLoadedAt.value = ''
|
||||
projects.value = []
|
||||
runs.value = []
|
||||
integrations.value = []
|
||||
agentCards.value = []
|
||||
settings.value = []
|
||||
auditLogs.value = []
|
||||
notificationOutbox.value = []
|
||||
projectRefs.value = {}
|
||||
projectJenkinsDiagnostics.value = null
|
||||
projectGiteaDiagnostics.value = null
|
||||
integrationConfig.value = { checkedAt: '', integrations: [] }
|
||||
}
|
||||
|
||||
async function createDeployRun(payload: CreateDeployRunPayload) {
|
||||
const currentGeneration = generation
|
||||
const run = await devopsApi.createDeployRun(payload, projects.value)
|
||||
if (currentGeneration !== generation) return run
|
||||
upsertRun(run)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return run
|
||||
}
|
||||
|
||||
async function cancelDeployRun(run: ReleaseRun) {
|
||||
const currentGeneration = generation
|
||||
const canceled = await devopsApi.cancelDeployRun(run.id, projects.value)
|
||||
if (currentGeneration !== generation) return canceled
|
||||
upsertRun(canceled)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return canceled
|
||||
}
|
||||
|
||||
async function retryDeployRun(run: ReleaseRun) {
|
||||
const currentGeneration = generation
|
||||
const retried = await devopsApi.retryDeployRun(run.id, projects.value)
|
||||
if (currentGeneration !== generation) return retried
|
||||
upsertRun(retried)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return retried
|
||||
}
|
||||
|
||||
async function syncJenkinsRun(run: ReleaseRun) {
|
||||
const currentGeneration = generation
|
||||
const synced = await devopsApi.syncJenkinsRun(run.id, projects.value)
|
||||
if (currentGeneration !== generation) return synced
|
||||
upsertRun(synced)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return synced
|
||||
}
|
||||
|
||||
async function syncJenkinsRuns(): Promise<JenkinsSyncSummary> {
|
||||
const currentGeneration = generation
|
||||
const result = await devopsApi.syncJenkinsRuns(projects.value)
|
||||
if (currentGeneration !== generation) return result
|
||||
result.syncedRuns.forEach(upsertRun)
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return result
|
||||
}
|
||||
|
||||
async function importJenkinsBuilds(): Promise<JenkinsImportSummary> {
|
||||
const currentGeneration = generation
|
||||
const result = await devopsApi.importJenkinsBuilds(projects.value)
|
||||
if (currentGeneration !== generation) return result
|
||||
result.importedRuns.forEach(upsertRun)
|
||||
result.syncedRuns.forEach(upsertRun)
|
||||
applyProjectRunSummaries()
|
||||
@@ -150,14 +202,27 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
* 发布单状态被其他请求推进时,只刷新 run 列表并同步项目环境摘要。
|
||||
*/
|
||||
async function refreshRuns() {
|
||||
runs.value = await devopsApi.getRuns(projects.value)
|
||||
applyProjectRunSummaries()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return runs.value
|
||||
const currentGeneration = generation
|
||||
const requestedRevision = runRevision
|
||||
try {
|
||||
const refreshed = await devopsApi.getRuns(projects.value)
|
||||
if (currentGeneration !== generation || requestedRevision !== runRevision) return runs.value
|
||||
runs.value = mergeRunVersions(refreshed, runs.value)
|
||||
applyProjectRunSummaries()
|
||||
lastLoadedAt.value = new Date().toISOString()
|
||||
loadError.value = ''
|
||||
return runs.value
|
||||
} catch (error) {
|
||||
if (currentGeneration === generation)
|
||||
loadError.value = error instanceof Error ? error.message : '发布记录更新失败'
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProjectRefs(projectKey: string) {
|
||||
const currentGeneration = generation
|
||||
const refs = await devopsApi.getProjectRefs(projectKey)
|
||||
if (currentGeneration !== generation) return refs
|
||||
projectRefs.value = {
|
||||
...projectRefs.value,
|
||||
[projectKey]: refs,
|
||||
@@ -167,7 +232,9 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
}
|
||||
|
||||
async function loadProjectJenkinsDiagnostics(): Promise<ProjectJenkinsDiagnosticsSummary> {
|
||||
const currentGeneration = generation
|
||||
const diagnostics = await devopsApi.getProjectJenkinsDiagnostics()
|
||||
if (currentGeneration !== generation) return diagnostics
|
||||
projectJenkinsDiagnostics.value = diagnostics
|
||||
applyProjectJenkinsDiagnostics()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
@@ -175,7 +242,9 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
}
|
||||
|
||||
async function loadProjectGiteaDiagnostics(): Promise<ProjectGiteaDiagnosticsSummary> {
|
||||
const currentGeneration = generation
|
||||
const diagnostics = await devopsApi.getProjectGiteaDiagnostics()
|
||||
if (currentGeneration !== generation) return diagnostics
|
||||
projectGiteaDiagnostics.value = diagnostics
|
||||
applyProjectGiteaDiagnostics()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
@@ -273,19 +342,27 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
}
|
||||
|
||||
async function loadAuditLogs() {
|
||||
auditLogs.value = await devopsApi.getAuditLogs()
|
||||
const currentGeneration = generation
|
||||
const records = await devopsApi.getAuditLogs()
|
||||
if (currentGeneration !== generation) return []
|
||||
auditLogs.value = records
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return auditLogs.value
|
||||
}
|
||||
|
||||
async function loadNotificationOutbox() {
|
||||
notificationOutbox.value = await devopsApi.getNotificationOutbox()
|
||||
const currentGeneration = generation
|
||||
const records = await devopsApi.getNotificationOutbox()
|
||||
if (currentGeneration !== generation) return []
|
||||
notificationOutbox.value = records
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return notificationOutbox.value
|
||||
}
|
||||
|
||||
async function retryNotificationOutboxMessage(id: string) {
|
||||
const currentGeneration = generation
|
||||
const message = await devopsApi.retryNotificationOutboxMessage(id)
|
||||
if (currentGeneration !== generation) return message
|
||||
notificationOutbox.value = [
|
||||
message,
|
||||
...notificationOutbox.value.filter((item) => item.id !== message.id),
|
||||
@@ -295,28 +372,20 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
}
|
||||
|
||||
function upsertRun(run: ReleaseRun) {
|
||||
runs.value = [run, ...runs.value.filter((item) => item.id !== run.id)]
|
||||
const existing = runs.value.find((item) => item.id === run.id)
|
||||
if (existing && existing.version > run.version) return
|
||||
runRevision += 1
|
||||
runs.value = newestRuns([run, ...runs.value.filter((item) => item.id !== run.id)])
|
||||
applyProjectRunSummaries()
|
||||
}
|
||||
|
||||
function applyProjectRunSummaries() {
|
||||
const latestRunByEnvironment = new Map<string, ReleaseRun>()
|
||||
|
||||
// 后端 /deploy-runs 按最近记录返回;首次出现的项目环境即当前展示摘要。
|
||||
runs.value.forEach((run) => {
|
||||
const key = projectEnvironmentKey(run.projectKey, run.environment)
|
||||
|
||||
if (!latestRunByEnvironment.has(key)) {
|
||||
latestRunByEnvironment.set(key, run)
|
||||
}
|
||||
})
|
||||
const latestRunByEnvironment = latestRunsByEnvironment(runs.value)
|
||||
|
||||
projects.value = projects.value.map((project) => ({
|
||||
...project,
|
||||
environments: project.environments.map((environment) => {
|
||||
const run = latestRunByEnvironment.get(
|
||||
projectEnvironmentKey(project.key, environment.name),
|
||||
)
|
||||
const run = latestRunByEnvironment.get(projectEnvironmentKey(project.key, environment.name))
|
||||
|
||||
if (!run) {
|
||||
return {
|
||||
@@ -343,6 +412,10 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
|
||||
return {
|
||||
loading,
|
||||
loadError,
|
||||
lastLoadedAt,
|
||||
reset,
|
||||
loadAdminData,
|
||||
dataSource,
|
||||
projects,
|
||||
runs,
|
||||
@@ -440,9 +513,7 @@ function giteaDiagnosticMessage(
|
||||
return 'Gitea 仓库不可用'
|
||||
}
|
||||
|
||||
function giteaWebhookDiagnosticMessage(
|
||||
status: ProjectGiteaWebhookStatus,
|
||||
): string {
|
||||
function giteaWebhookDiagnosticMessage(status: ProjectGiteaWebhookStatus): string {
|
||||
if (status === 'ok') {
|
||||
return 'Jenkins relay hook 已配置'
|
||||
}
|
||||
@@ -476,9 +547,6 @@ function aggregateGiteaState(
|
||||
return 'healthy'
|
||||
}
|
||||
|
||||
function projectEnvironmentKey(
|
||||
projectKey: string,
|
||||
environment: ReleaseRun['environment'],
|
||||
): string {
|
||||
function projectEnvironmentKey(projectKey: string, environment: ReleaseRun['environment']): string {
|
||||
return `${projectKey}:${environment}`
|
||||
}
|
||||
|
||||
+206
-93
@@ -2,225 +2,338 @@
|
||||
|
||||
:root {
|
||||
font-family:
|
||||
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
|
||||
Inter,
|
||||
-apple-system,
|
||||
BlinkMacSystemFont,
|
||||
'Segoe UI',
|
||||
'PingFang SC',
|
||||
'Microsoft YaHei',
|
||||
sans-serif;
|
||||
color: #172033;
|
||||
background: #f5f7fb;
|
||||
color: #272d3a;
|
||||
background: #f8f9fb;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
--text: #272d3a;
|
||||
--text-muted: #727986;
|
||||
--border: #e9ebf0;
|
||||
--accent: #6656ad;
|
||||
--el-color-primary: #6656ad;
|
||||
--el-color-primary-light-3: #9488c6;
|
||||
--el-color-primary-light-5: #b3abd6;
|
||||
--el-color-primary-light-7: #d1cce6;
|
||||
--el-color-primary-light-8: #e0ddef;
|
||||
--el-color-primary-light-9: #f0eef7;
|
||||
--el-color-primary-dark-2: #51448a;
|
||||
--el-border-color: #e2e5ec;
|
||||
--el-border-color-light: #eceef3;
|
||||
--el-text-color-primary: #272d3a;
|
||||
--el-text-color-regular: #5e6573;
|
||||
--el-font-size-base: 13px;
|
||||
--el-border-radius-base: 6px;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
background: #f5f7fb;
|
||||
}
|
||||
|
||||
button,
|
||||
input,
|
||||
textarea,
|
||||
select {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
button,
|
||||
a {
|
||||
touch-action: manipulation;
|
||||
}
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
#app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.skip-link {
|
||||
position: fixed;
|
||||
top: -80px;
|
||||
left: 16px;
|
||||
z-index: 3000;
|
||||
padding: 12px 20px;
|
||||
border-radius: 6px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
.skip-link:focus {
|
||||
top: 10px;
|
||||
}
|
||||
.page-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
gap: 22px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
gap: 18px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.eyebrow {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
color: #9398a5;
|
||||
font-size: 10px;
|
||||
font-weight: 550;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
margin: 0;
|
||||
color: #111827;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0;
|
||||
color: var(--text);
|
||||
font-size: 25px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.6px;
|
||||
text-wrap: balance;
|
||||
}
|
||||
|
||||
.page-header p {
|
||||
margin: 8px 0 0;
|
||||
color: #697386;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
margin: 9px 0 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.panel {
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
|
||||
min-width: 0;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
overflow: clip;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 16px 18px;
|
||||
border-bottom: 1px solid #edf1f7;
|
||||
padding: 18px 22px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.panel-header h2 {
|
||||
margin: 0;
|
||||
color: #182033;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.panel-header span {
|
||||
color: #748093;
|
||||
color: #39404e;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.panel-header span {
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
padding: 18px;
|
||||
padding: 22px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #748093;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.two-column {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
|
||||
gap: 16px;
|
||||
grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.three-column {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.section-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.compact-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.list-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 12px;
|
||||
border: 1px solid #edf1f7;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: #fcfcfd;
|
||||
}
|
||||
|
||||
.list-row strong {
|
||||
color: #172033;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.list-row small {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: #7b8798;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
margin-top: 6px;
|
||||
color: #7b8798;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
line-height: 1.6;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.el-card,
|
||||
.el-table,
|
||||
.el-input__wrapper,
|
||||
.el-select__wrapper,
|
||||
.el-textarea__inner,
|
||||
.el-button,
|
||||
.el-tag {
|
||||
border-radius: 8px;
|
||||
.button-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
min-height: 34px;
|
||||
padding: 0 14px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
color: #51596a;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.button-link:hover {
|
||||
border-color: var(--accent);
|
||||
color: var(--accent);
|
||||
}
|
||||
.button-link.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
.button-link.primary:hover {
|
||||
background: #574894;
|
||||
}
|
||||
.text-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--accent);
|
||||
font-size: 12px;
|
||||
}
|
||||
.text-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.quiet-empty {
|
||||
padding: 48px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.quiet-empty strong {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #606878;
|
||||
}
|
||||
.quiet-empty p {
|
||||
margin: 9px 0 12px;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.el-button {
|
||||
font-weight: 450;
|
||||
}
|
||||
|
||||
.el-menu {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.el-table {
|
||||
--el-table-border-color: var(--border);
|
||||
--el-table-row-hover-bg-color: #faf9fd;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 12px;
|
||||
}
|
||||
.el-table th.el-table__cell {
|
||||
background: #f7f9fc;
|
||||
color: #4b5565;
|
||||
background: #fbfbfd;
|
||||
color: #818794;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.el-table .el-table__cell {
|
||||
padding: 13px 0;
|
||||
}
|
||||
.el-tag {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.danger-note {
|
||||
border: 1px solid #ffd9d9;
|
||||
background: #fff7f7;
|
||||
color: #a63232;
|
||||
border: 1px solid #f4e2cf;
|
||||
background: #fffbf5;
|
||||
color: #9a682e;
|
||||
}
|
||||
.el-select {
|
||||
width: 100%;
|
||||
}
|
||||
.el-dialog,
|
||||
.el-drawer {
|
||||
max-width: calc(100vw - 24px);
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.status-grid,
|
||||
.three-column,
|
||||
.section-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.two-column {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.page-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.page-header h1 {
|
||||
font-size: 23px;
|
||||
}
|
||||
|
||||
.status-grid,
|
||||
.three-column,
|
||||
.section-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.panel-header {
|
||||
padding: 16px;
|
||||
}
|
||||
.panel-body {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
.agent-panel .el-drawer__body {
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
+24
-13
@@ -5,13 +5,7 @@ export type HealthState = 'healthy' | 'warning' | 'error' | 'offline'
|
||||
|
||||
export type EnvironmentName = 'test' | 'production'
|
||||
|
||||
export type ReleaseStatus =
|
||||
| 'queued'
|
||||
| 'running'
|
||||
| 'success'
|
||||
| 'failed'
|
||||
| 'canceled'
|
||||
| 'idle'
|
||||
export type ReleaseStatus = 'queued' | 'running' | 'success' | 'failed' | 'canceled' | 'idle'
|
||||
|
||||
export type StepStatus =
|
||||
| 'pending'
|
||||
@@ -22,12 +16,7 @@ export type StepStatus =
|
||||
| 'skipped'
|
||||
| 'canceled'
|
||||
|
||||
export type AgentMode =
|
||||
| 'risk'
|
||||
| 'diagnosis'
|
||||
| 'runbook'
|
||||
| 'releaseNotes'
|
||||
| 'incidentReview'
|
||||
export type AgentMode = 'risk' | 'diagnosis' | 'runbook' | 'releaseNotes' | 'incidentReview'
|
||||
|
||||
export type AgentPurpose =
|
||||
| 'release-risk'
|
||||
@@ -511,6 +500,26 @@ export interface CreateDeployRunPayload {
|
||||
}
|
||||
}
|
||||
|
||||
export interface AgentSource {
|
||||
id: string
|
||||
kind: 'project' | 'deployment' | 'build'
|
||||
projectKey: string
|
||||
runId?: string
|
||||
label: string
|
||||
checkedAt: string
|
||||
url?: string
|
||||
}
|
||||
export interface AgentToolTrace {
|
||||
name: string
|
||||
status: 'success' | 'failed'
|
||||
summary: string
|
||||
}
|
||||
export interface AgentQuestionPayload {
|
||||
question: string
|
||||
projectKey?: string
|
||||
runId?: string
|
||||
history?: Array<{ role: 'user' | 'assistant'; content: string }>
|
||||
}
|
||||
export interface AgentInvocation {
|
||||
id: string
|
||||
runId?: string
|
||||
@@ -520,6 +529,8 @@ export interface AgentInvocation {
|
||||
promptSummary: string
|
||||
contextSummary?: string
|
||||
resultMarkdown?: string
|
||||
sources?: AgentSource[]
|
||||
toolExecutions?: AgentToolTrace[]
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { ReleaseRun } from '../types/devops'
|
||||
|
||||
export function runTime(run: Pick<ReleaseRun, 'startedAt'>): number {
|
||||
const value = Date.parse(run.startedAt)
|
||||
return Number.isNaN(value) ? 0 : value
|
||||
}
|
||||
|
||||
export function newestRuns<T extends Pick<ReleaseRun, 'startedAt'>>(runs: T[]): T[] {
|
||||
return [...runs].sort((a, b) => runTime(b) - runTime(a))
|
||||
}
|
||||
|
||||
/** 按项目和环境聚合最近发布,已恢复的历史失败不再进入待处理列表。 */
|
||||
export function latestRunsByEnvironment(runs: ReleaseRun[]): Map<string, ReleaseRun> {
|
||||
const latest = new Map<string, ReleaseRun>()
|
||||
for (const run of newestRuns(runs)) {
|
||||
const key = `${run.projectKey}:${run.environment}`
|
||||
if (!latest.has(key)) latest.set(key, run)
|
||||
}
|
||||
return latest
|
||||
}
|
||||
|
||||
export function formatTime(value?: string): string {
|
||||
if (!value || !Number.isFinite(Date.parse(value))) return '—'
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(new Date(value))
|
||||
}
|
||||
|
||||
/** 并发刷新不能把较新的乐观锁版本回退为迟到的旧快照。 */
|
||||
export function mergeRunVersions(incoming: ReleaseRun[], current: ReleaseRun[]): ReleaseRun[] {
|
||||
const known = new Map(current.map((run) => [run.id, run]))
|
||||
return newestRuns(
|
||||
incoming.map((run) => {
|
||||
const existing = known.get(run.id)
|
||||
return existing && existing.version > run.version ? existing : run
|
||||
}),
|
||||
)
|
||||
}
|
||||
+67
-135
@@ -9,18 +9,15 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import { useSessionStore } from '../stores/session'
|
||||
|
||||
type LoginRole = 'super_admin' | 'member'
|
||||
|
||||
const SUPER_ADMIN_ACCOUNT = 'zhanxi'
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const loading = ref(false)
|
||||
const forgotPasswordLoading = ref(false)
|
||||
const loginRole = ref<LoginRole>('super_admin')
|
||||
|
||||
const loginForm = reactive({
|
||||
account: SUPER_ADMIN_ACCOUNT,
|
||||
account: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
@@ -30,34 +27,23 @@ const passwordForm = reactive({
|
||||
confirmPassword: '',
|
||||
})
|
||||
|
||||
const redirect = computed(() =>
|
||||
typeof route.query.redirect === 'string' ? route.query.redirect : '/overview',
|
||||
)
|
||||
const roleHint = computed(() =>
|
||||
loginRole.value === 'super_admin'
|
||||
? '超级管理员不提供忘记密码入口,请通过服务器运维方式重置。'
|
||||
: '普通成员首次登录或重置密码后,必须先修改临时密码。',
|
||||
)
|
||||
const isSuperAdminLogin = computed(() => loginRole.value === 'super_admin')
|
||||
|
||||
function switchLoginRole(role: LoginRole) {
|
||||
loginRole.value = role
|
||||
loginForm.account = role === 'super_admin' ? SUPER_ADMIN_ACCOUNT : ''
|
||||
loginForm.password = ''
|
||||
}
|
||||
|
||||
function handleLoginRoleChange(value: unknown) {
|
||||
if (value === 'super_admin' || value === 'member') {
|
||||
switchLoginRole(value)
|
||||
}
|
||||
}
|
||||
const redirect = computed(() => {
|
||||
const value = route.query.redirect
|
||||
return typeof value === 'string' && value.startsWith('/') && !value.startsWith('//')
|
||||
? value
|
||||
: '/overview'
|
||||
})
|
||||
const isSuperAdminLogin = computed(() => loginForm.account.trim() === SUPER_ADMIN_ACCOUNT)
|
||||
const loginError = ref('')
|
||||
|
||||
async function submitLogin() {
|
||||
if (loading.value) return
|
||||
loginError.value = ''
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
const user = await session.login({
|
||||
account: isSuperAdminLogin.value ? SUPER_ADMIN_ACCOUNT : loginForm.account.trim(),
|
||||
account: loginForm.account.trim(),
|
||||
password: loginForm.password,
|
||||
})
|
||||
passwordForm.currentPassword = loginForm.password
|
||||
@@ -69,7 +55,7 @@ async function submitLogin() {
|
||||
|
||||
await router.push(redirect.value)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '登录失败')
|
||||
loginError.value = error instanceof Error ? error.message : '登录失败,请重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -88,15 +74,11 @@ async function requestPasswordReset() {
|
||||
}
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认向超级管理员发送账号 ${account} 的密码重置请求?`,
|
||||
'忘记密码',
|
||||
{
|
||||
confirmButtonText: '发送请求',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
},
|
||||
)
|
||||
await ElMessageBox.confirm(`确认向超级管理员发送账号 ${account} 的密码重置请求?`, '忘记密码', {
|
||||
confirmButtonText: '发送请求',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
@@ -162,28 +144,20 @@ function accountLabel() {
|
||||
<section class="login-panel">
|
||||
<div class="login-copy">
|
||||
<ElIcon><Monitor /></ElIcon>
|
||||
<h1>DevOps 运维平台</h1>
|
||||
<p>使用平台账号进入控制台。</p>
|
||||
<h1>登录 DevOps</h1>
|
||||
<p>项目发布,简单有序。</p>
|
||||
</div>
|
||||
<ElForm class="login-form" label-position="top" @submit.prevent="submit">
|
||||
<template v-if="!session.mustChangePassword">
|
||||
<div class="role-switch">
|
||||
<ElRadioGroup
|
||||
:model-value="loginRole"
|
||||
size="large"
|
||||
@change="handleLoginRoleChange"
|
||||
>
|
||||
<ElRadioButton value="super_admin">超级管理员</ElRadioButton>
|
||||
<ElRadioButton value="member">普通成员</ElRadioButton>
|
||||
</ElRadioGroup>
|
||||
<p>{{ roleHint }}</p>
|
||||
</div>
|
||||
<ElFormItem label="账号">
|
||||
<ElInput
|
||||
v-model="loginForm.account"
|
||||
size="large"
|
||||
autocomplete="username"
|
||||
:readonly="isSuperAdminLogin"
|
||||
name="username"
|
||||
required
|
||||
:spellcheck="false"
|
||||
placeholder="输入平台账号…"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="密码">
|
||||
@@ -192,9 +166,11 @@ function accountLabel() {
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
required
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<p v-if="loginError" class="login-error" role="alert">{{ loginError }}</p>
|
||||
<ElButton
|
||||
type="primary"
|
||||
size="large"
|
||||
@@ -270,111 +246,67 @@ function accountLabel() {
|
||||
display: grid;
|
||||
min-height: 100vh;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
background: #eef2f7;
|
||||
padding: 28px 20px;
|
||||
background: #f8f9fb;
|
||||
}
|
||||
|
||||
.login-panel {
|
||||
display: grid;
|
||||
width: min(860px, 100%);
|
||||
grid-template-columns: 1fr 360px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #dfe6f0;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 18px 50px rgb(15 23 42 / 10%);
|
||||
width: min(410px, 100%);
|
||||
padding: 38px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.login-copy {
|
||||
padding: 44px;
|
||||
border-right: 1px solid #e6ebf3;
|
||||
background: #f8fafc;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.login-copy .el-icon {
|
||||
color: #1d5fd0;
|
||||
font-size: 34px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
margin-bottom: 24px;
|
||||
border-radius: 9px;
|
||||
background: #272d3a;
|
||||
color: #fff;
|
||||
font-size: 23px;
|
||||
}
|
||||
|
||||
.login-copy h1 {
|
||||
margin: 18px 0 10px;
|
||||
color: #111827;
|
||||
font-size: 28px;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.login-copy p {
|
||||
max-width: 420px;
|
||||
color: #697386;
|
||||
font-size: 14px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
padding: 44px 36px;
|
||||
}
|
||||
|
||||
.role-switch {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.role-switch :deep(.el-radio-group) {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.role-switch :deep(.el-radio-button__inner) {
|
||||
width: 100%;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.role-switch p {
|
||||
min-height: 20px;
|
||||
margin: 0;
|
||||
color: #697386;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--text);
|
||||
font-size: 23px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
.login-copy p {
|
||||
margin: 10px 0 0;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.login-form .el-button {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
|
||||
.forgot-password {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
.login-error {
|
||||
padding: 10px 12px;
|
||||
border-radius: 5px;
|
||||
background: #fff4f4;
|
||||
color: #b04747;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.change-title {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
margin-bottom: 18px;
|
||||
color: #111827;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.change-title span {
|
||||
color: #697386;
|
||||
gap: 6px;
|
||||
margin-bottom: 22px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.switch-account {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
.change-title span {
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 780px) {
|
||||
@media (max-width: 480px) {
|
||||
.login-panel {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.login-copy {
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid #e6ebf3;
|
||||
padding: 30px 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+64
-170
@@ -124,43 +124,9 @@ const filteredMessages = computed(() => {
|
||||
return messages.value.filter((message) => message.status === messageStatusFilter.value)
|
||||
})
|
||||
|
||||
const memberOverview = computed(() => {
|
||||
const activeCount = members.value.filter((member) => member.status === 'active').length
|
||||
const buildAccountCount = members.value.filter(memberHasBuildPermission).length
|
||||
const mustChangePasswordCount = members.value.filter((member) => member.mustChangePassword).length
|
||||
const resetRequestCount = members.value.filter((member) => member.hasPendingPasswordResetRequest).length
|
||||
|
||||
return [
|
||||
{ key: 'total', label: '平台账号', value: members.value.length, tone: 'neutral' },
|
||||
{ key: 'active', label: '启用账号', value: activeCount, tone: 'success' },
|
||||
{ key: 'build', label: '构建账号', value: buildAccountCount, tone: 'active' },
|
||||
{
|
||||
key: 'must-change',
|
||||
label: '待改密',
|
||||
value: mustChangePasswordCount,
|
||||
tone: mustChangePasswordCount > 0 ? 'warning' : 'neutral',
|
||||
},
|
||||
{
|
||||
key: 'reset',
|
||||
label: '请求重置',
|
||||
value: resetRequestCount,
|
||||
tone: resetRequestCount > 0 ? 'danger' : 'neutral',
|
||||
},
|
||||
{
|
||||
key: 'messages',
|
||||
label: '待处理消息',
|
||||
value: pendingMessages.value.length,
|
||||
tone: pendingMessages.value.length > 0 ? 'warning' : 'neutral',
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
const hasActiveMemberFilters = computed(() =>
|
||||
Boolean(
|
||||
accountKeyword.value.trim() ||
|
||||
roleFilter.value ||
|
||||
statusFilter.value ||
|
||||
securityFilter.value,
|
||||
accountKeyword.value.trim() || roleFilter.value || statusFilter.value || securityFilter.value,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -292,25 +258,18 @@ async function updatePermissions() {
|
||||
}
|
||||
|
||||
async function resetPassword(member: MemberSummary) {
|
||||
await ElMessageBox.confirm(
|
||||
`确认为 ${member.displayName} 生成一次性临时密码?`,
|
||||
'重置密码',
|
||||
{
|
||||
confirmButtonText: '重置',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
},
|
||||
)
|
||||
await ElMessageBox.confirm(`确认为 ${member.displayName} 生成一次性临时密码?`, '重置密码', {
|
||||
confirmButtonText: '重置',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
const updated = await devopsApi.resetMemberPassword(member.id)
|
||||
upsertMember(updated)
|
||||
await loadMessages()
|
||||
await showTemporaryPassword(updated, '临时密码已生成')
|
||||
}
|
||||
|
||||
async function showTemporaryPassword(
|
||||
member: MemberCredentialResult,
|
||||
title: string,
|
||||
) {
|
||||
async function showTemporaryPassword(member: MemberCredentialResult, title: string) {
|
||||
await ElMessageBox.alert(
|
||||
`请将以下临时密码安全发送给 ${member.displayName},成员首次登录后必须修改密码。\n\n${member.temporaryPassword}`,
|
||||
title,
|
||||
@@ -341,15 +300,11 @@ async function toggleStatus(member: MemberSummary) {
|
||||
}
|
||||
|
||||
async function deleteMember(member: MemberSummary) {
|
||||
await ElMessageBox.confirm(
|
||||
`确认删除成员 ${member.displayName}?`,
|
||||
'删除成员',
|
||||
{
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
},
|
||||
)
|
||||
await ElMessageBox.confirm(`确认删除成员 ${member.displayName}?`, '删除成员', {
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
await devopsApi.deleteMember(member.id)
|
||||
members.value = members.value.filter((item) => item.id !== member.id)
|
||||
ElMessage.success('成员已删除')
|
||||
@@ -394,10 +349,9 @@ async function loadMessages() {
|
||||
}
|
||||
|
||||
function upsertMember(member: MemberSummary) {
|
||||
members.value = [
|
||||
member,
|
||||
...members.value.filter((item) => item.id !== member.id),
|
||||
].sort((left, right) => roleOrder(left) - roleOrder(right))
|
||||
members.value = [member, ...members.value.filter((item) => item.id !== member.id)].sort(
|
||||
(left, right) => roleOrder(left) - roleOrder(right),
|
||||
)
|
||||
}
|
||||
|
||||
function roleOrder(member: MemberSummary) {
|
||||
@@ -410,10 +364,7 @@ function resetPermissionMap(target: PermissionMap, member?: MemberSummary) {
|
||||
}
|
||||
|
||||
const permissionByProject = new Map(
|
||||
member?.projectPermissions.map((permission) => [
|
||||
permission.projectKey,
|
||||
permission.level,
|
||||
]) ?? [],
|
||||
member?.projectPermissions.map((permission) => [permission.projectKey, permission.level]) ?? [],
|
||||
)
|
||||
|
||||
for (const project of platform.projects) {
|
||||
@@ -444,11 +395,6 @@ function memberMatchesSecurityFilter(member: MemberSummary, filter: MemberSecuri
|
||||
return !member.mustChangePassword && !member.hasPendingPasswordResetRequest
|
||||
}
|
||||
|
||||
function memberHasBuildPermission(member: MemberSummary) {
|
||||
return member.role === 'super_admin' ||
|
||||
member.projectPermissions.some((permission) => permission.level === 'build')
|
||||
}
|
||||
|
||||
function memberBuildPermissionCount(member: MemberSummary) {
|
||||
if (member.role === 'super_admin') {
|
||||
return platform.projects.length
|
||||
@@ -584,32 +530,28 @@ function formatDateTime(value?: string) {
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<ElButton :icon="Refresh" @click="loadData">刷新</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDialog">
|
||||
新增成员
|
||||
</ElButton>
|
||||
<ElButton type="primary" :icon="Plus" @click="openCreateDialog"> 新增成员 </ElButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="member-overview-grid">
|
||||
<article
|
||||
v-for="item in memberOverview"
|
||||
:key="item.key"
|
||||
class="member-overview-card"
|
||||
:class="`tone-${item.tone}`"
|
||||
>
|
||||
<span>{{ item.label }}</span>
|
||||
<strong>{{ item.value }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>密码消息</h2>
|
||||
<span>{{ filteredMessages.length }} / {{ messages.length }} 条,{{ pendingMessages.length }} 条待处理</span>
|
||||
</div>
|
||||
<details class="panel message-disclosure">
|
||||
<summary class="panel-header">
|
||||
<h2>密码重置请求</h2>
|
||||
<span
|
||||
>{{ filteredMessages.length }} / {{ messages.length }} 条,{{
|
||||
pendingMessages.length
|
||||
}}
|
||||
条待处理</span
|
||||
>
|
||||
</summary>
|
||||
<div class="panel-body">
|
||||
<div class="message-filter-bar">
|
||||
<ElSelect v-model="messageStatusFilter" clearable placeholder="消息状态">
|
||||
<ElSelect
|
||||
aria-label="筛选密码消息状态"
|
||||
v-model="messageStatusFilter"
|
||||
clearable
|
||||
placeholder="消息状态"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in messageStatusOptions"
|
||||
:key="option.value"
|
||||
@@ -653,7 +595,7 @@ function formatDateTime(value?: string) {
|
||||
:image-size="72"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</details>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
@@ -663,13 +605,14 @@ function formatDateTime(value?: string) {
|
||||
<div class="panel-body">
|
||||
<div class="member-filter-bar">
|
||||
<ElInput
|
||||
aria-label="搜索成员"
|
||||
v-model="accountKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
placeholder="搜索账号 / 名称 / 项目权限"
|
||||
class="member-search"
|
||||
/>
|
||||
<ElSelect v-model="roleFilter" clearable placeholder="角色">
|
||||
<ElSelect aria-label="筛选成员角色" v-model="roleFilter" clearable placeholder="角色">
|
||||
<ElOption
|
||||
v-for="option in roleOptions"
|
||||
:key="option.value"
|
||||
@@ -677,7 +620,12 @@ function formatDateTime(value?: string) {
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElSelect v-model="statusFilter" clearable placeholder="账号状态">
|
||||
<ElSelect
|
||||
aria-label="筛选成员状态"
|
||||
v-model="statusFilter"
|
||||
clearable
|
||||
placeholder="账号状态"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in statusOptions"
|
||||
:key="option.value"
|
||||
@@ -685,7 +633,12 @@ function formatDateTime(value?: string) {
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElSelect v-model="securityFilter" clearable placeholder="安全状态">
|
||||
<ElSelect
|
||||
aria-label="筛选账号安全状态"
|
||||
v-model="securityFilter"
|
||||
clearable
|
||||
placeholder="安全状态"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in securityOptions"
|
||||
:key="option.value"
|
||||
@@ -743,13 +696,14 @@ function formatDateTime(value?: string) {
|
||||
<ElTableColumn label="安全状态" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<div class="security-tags">
|
||||
<ElTag v-if="row.mustChangePassword" type="warning" round>
|
||||
待改密
|
||||
</ElTag>
|
||||
<ElTag v-if="row.mustChangePassword" type="warning" round> 待改密 </ElTag>
|
||||
<ElTag v-if="row.hasPendingPasswordResetRequest" type="danger" round>
|
||||
请求重置
|
||||
</ElTag>
|
||||
<span v-if="!row.mustChangePassword && !row.hasPendingPasswordResetRequest" class="muted">
|
||||
<span
|
||||
v-if="!row.mustChangePassword && !row.hasPendingPasswordResetRequest"
|
||||
class="muted"
|
||||
>
|
||||
正常
|
||||
</span>
|
||||
</div>
|
||||
@@ -763,7 +717,11 @@ function formatDateTime(value?: string) {
|
||||
<ElTableColumn label="操作" width="330" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<div class="row-actions">
|
||||
<ElButton size="small" :disabled="!canMutate(row)" @click="openPermissionDialog(row)">
|
||||
<ElButton
|
||||
size="small"
|
||||
:disabled="!canMutate(row)"
|
||||
@click="openPermissionDialog(row)"
|
||||
>
|
||||
权限
|
||||
</ElButton>
|
||||
<ElButton
|
||||
@@ -774,11 +732,7 @@ function formatDateTime(value?: string) {
|
||||
>
|
||||
重置
|
||||
</ElButton>
|
||||
<ElButton
|
||||
size="small"
|
||||
:disabled="!canMutate(row)"
|
||||
@click="toggleStatus(row)"
|
||||
>
|
||||
<ElButton size="small" :disabled="!canMutate(row)" @click="toggleStatus(row)">
|
||||
{{ row.status === 'active' ? '禁用' : '启用' }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
@@ -852,10 +806,7 @@ function formatDateTime(value?: string) {
|
||||
{{ groupPermissionSummary(group) }}
|
||||
</span>
|
||||
</button>
|
||||
<div
|
||||
v-show="isPermissionGroupExpanded(group.key)"
|
||||
class="permission-project-list"
|
||||
>
|
||||
<div v-show="isPermissionGroupExpanded(group.key)" class="permission-project-list">
|
||||
<div
|
||||
v-for="project in group.children"
|
||||
:key="project.key"
|
||||
@@ -910,63 +861,11 @@ function formatDateTime(value?: string) {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.member-overview-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
.message-disclosure summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.member-overview-card {
|
||||
min-width: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #d8e2ef;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.member-overview-card span {
|
||||
display: block;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.member-overview-card strong {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: #0f172a;
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.member-overview-card.tone-active {
|
||||
border-color: #bfdbfe;
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.member-overview-card.tone-success {
|
||||
border-color: #bbf7d0;
|
||||
background: #f0fdf4;
|
||||
}
|
||||
|
||||
.member-overview-card.tone-warning {
|
||||
border-color: #fde68a;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.member-overview-card.tone-danger {
|
||||
border-color: #fecaca;
|
||||
background: #fef2f2;
|
||||
}
|
||||
|
||||
.message-filter-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.message-filter-bar .el-select {
|
||||
width: 160px;
|
||||
.message-disclosure:not([open]) summary {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.member-filter-bar {
|
||||
@@ -1214,17 +1113,12 @@ function formatDateTime(value?: string) {
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.member-overview-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.member-filter-bar {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.member-overview-grid,
|
||||
.member-filter-bar,
|
||||
.member-form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
+248
-685
@@ -1,734 +1,297 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Cpu,
|
||||
Failed,
|
||||
Finished,
|
||||
Promotion,
|
||||
Refresh,
|
||||
Tickets,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { computed } from 'vue'
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
import MetricTile from '../components/MetricTile.vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import StatusPill from '../components/StatusPill.vue'
|
||||
import { useAssistantStore } from '../stores/assistant'
|
||||
import { usePlatformStore } from '../stores/platform'
|
||||
import type { HealthState, ProjectConfig, ReleaseRun } from '../types/devops'
|
||||
import { formatTime, latestRunsByEnvironment } from '../utils/releases'
|
||||
import type { ReleaseRun } from '../types/devops'
|
||||
|
||||
const platform = usePlatformStore()
|
||||
|
||||
const successCount = computed(() => platform.runs.filter((run) => run.status === 'success').length)
|
||||
const failedCount = computed(() => platform.failedRuns.length)
|
||||
const runningCount = computed(() => platform.runningRuns.length)
|
||||
const readyProjectCount = computed(
|
||||
() => platform.projects.filter((project) => projectReadinessState(project) === 'ready').length,
|
||||
const assistant = useAssistantStore()
|
||||
const question = ref('')
|
||||
const search = ref('')
|
||||
const filter = ref<'all' | 'active' | 'failed'>('all')
|
||||
const latest = computed(() => latestRunsByEnvironment(platform.runs))
|
||||
const projectRows = computed(() =>
|
||||
platform.projects
|
||||
.map((project) => {
|
||||
const active = platform.runningRuns.filter((run) => run.projectKey === project.key)
|
||||
const last = platform.runs.find((run) => run.projectKey === project.key)
|
||||
const run: ReleaseRun | undefined = active[0] || last
|
||||
const failed = [...latest.value.values()].some(
|
||||
(run) => run.projectKey === project.key && run.status === 'failed',
|
||||
)
|
||||
return { project, run, activeCount: active.length, failed }
|
||||
})
|
||||
.filter(
|
||||
(row) =>
|
||||
`${row.project.key} ${row.project.name}`
|
||||
.toLowerCase()
|
||||
.includes(search.value.trim().toLowerCase()) &&
|
||||
(filter.value === 'all' ||
|
||||
(filter.value === 'active' && row.activeCount > 0) ||
|
||||
(filter.value === 'failed' && row.failed)),
|
||||
)
|
||||
.sort((a, b) => Number(b.activeCount > 0) - Number(a.activeCount > 0)),
|
||||
)
|
||||
const blockedProjects = computed(
|
||||
() => platform.projects.filter((project) => projectReadinessState(project) === 'blocked'),
|
||||
)
|
||||
const attentionProjects = computed(
|
||||
() => platform.projects.filter((project) => projectReadinessState(project) === 'attention'),
|
||||
)
|
||||
const notificationAttentionCount = computed(
|
||||
() =>
|
||||
platform.notificationOutbox.filter(
|
||||
(item) => item.status === 'pending' || item.status === 'failed' || item.status === 'dead',
|
||||
).length,
|
||||
)
|
||||
const integrationAttentionCount = computed(
|
||||
() => platform.integrationConfig.integrations.filter((item) => item.status !== 'configured').length,
|
||||
)
|
||||
|
||||
type ProjectReadinessState = 'ready' | 'attention' | 'blocked' | 'readonly'
|
||||
type FocusTone = 'success' | 'warning' | 'danger' | 'active' | 'neutral'
|
||||
type FocusItem = {
|
||||
key: string
|
||||
label: string
|
||||
value: string | number
|
||||
detail: string
|
||||
tone: FocusTone
|
||||
action: string
|
||||
to: RouteLocationRaw
|
||||
}
|
||||
|
||||
const focusItems = computed<FocusItem[]>(() => {
|
||||
const items: FocusItem[] = []
|
||||
|
||||
if (failedCount.value > 0) {
|
||||
items.push({
|
||||
key: 'failed-runs',
|
||||
label: '失败待诊断',
|
||||
value: failedCount.value,
|
||||
detail: '优先查看失败节点、日志摘要和复盘材料。',
|
||||
tone: 'danger',
|
||||
action: '查看失败 Run',
|
||||
to: { name: 'runs' },
|
||||
})
|
||||
const activeCount = computed(() => new Set(platform.runningRuns.map((run) => run.projectKey)).size)
|
||||
function ask() {
|
||||
if (question.value.trim() && !assistant.pending) {
|
||||
assistant.open(question.value)
|
||||
question.value = ''
|
||||
}
|
||||
|
||||
if (runningCount.value > 0) {
|
||||
items.push({
|
||||
key: 'running-runs',
|
||||
label: '执行中发布',
|
||||
value: runningCount.value,
|
||||
detail: '关注 Jenkins queue/build 状态和流程节点推进。',
|
||||
tone: 'active',
|
||||
action: '查看进度',
|
||||
to: { name: 'runs' },
|
||||
})
|
||||
}
|
||||
|
||||
if (blockedProjects.value.length > 0) {
|
||||
items.push({
|
||||
key: 'blocked-projects',
|
||||
label: '项目阻断',
|
||||
value: blockedProjects.value.length,
|
||||
detail: 'Gitea、Webhook、Jenkins 或通知链路存在阻断。',
|
||||
tone: 'danger',
|
||||
action: '查看项目',
|
||||
to: { name: 'projects' },
|
||||
})
|
||||
}
|
||||
|
||||
if (attentionProjects.value.length > 0) {
|
||||
items.push({
|
||||
key: 'attention-projects',
|
||||
label: '配置关注',
|
||||
value: attentionProjects.value.length,
|
||||
detail: '存在待配置项,生产发布前需要复核。',
|
||||
tone: 'warning',
|
||||
action: '定位配置',
|
||||
to: { name: 'projects' },
|
||||
})
|
||||
}
|
||||
|
||||
if (notificationAttentionCount.value > 0) {
|
||||
items.push({
|
||||
key: 'notification-outbox',
|
||||
label: '通知待排查',
|
||||
value: notificationAttentionCount.value,
|
||||
detail: '通知 outbox 存在待投递、失败或终止记录。',
|
||||
tone: 'warning',
|
||||
action: '查看 outbox',
|
||||
to: { name: 'settings' },
|
||||
})
|
||||
}
|
||||
|
||||
if (integrationAttentionCount.value > 0) {
|
||||
items.push({
|
||||
key: 'integration-config',
|
||||
label: '集成缺口',
|
||||
value: integrationAttentionCount.value,
|
||||
detail: '系统配置中存在未配置或部分配置的集成项。',
|
||||
tone: 'warning',
|
||||
action: '查看系统配置',
|
||||
to: { name: 'settings' },
|
||||
})
|
||||
}
|
||||
|
||||
if (items.length > 0) {
|
||||
return items
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
key: 'stable',
|
||||
label: '当前稳定',
|
||||
value: 'OK',
|
||||
detail: '未发现失败 run、项目阻断或待处理通知。',
|
||||
tone: 'success',
|
||||
action: '查看项目',
|
||||
to: { name: 'projects' },
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
const priorityRuns = computed(() => {
|
||||
return [...platform.runs]
|
||||
.sort((left, right) => {
|
||||
const priorityDiff = runPriority(left) - runPriority(right)
|
||||
|
||||
if (priorityDiff !== 0) {
|
||||
return priorityDiff
|
||||
}
|
||||
|
||||
return dateValue(right.startedAt) - dateValue(left.startedAt)
|
||||
})
|
||||
.slice(0, 5)
|
||||
})
|
||||
|
||||
const projectAttentionQueue = computed(() => {
|
||||
return [...blockedProjects.value, ...attentionProjects.value]
|
||||
.filter((project, index, list) => list.findIndex((item) => item.key === project.key) === index)
|
||||
.slice(0, 5)
|
||||
})
|
||||
|
||||
function runPriority(run: ReleaseRun): number {
|
||||
const priority: Record<ReleaseRun['status'], number> = {
|
||||
failed: 0,
|
||||
running: 1,
|
||||
queued: 2,
|
||||
canceled: 3,
|
||||
success: 4,
|
||||
idle: 5,
|
||||
}
|
||||
|
||||
return priority[run.status] ?? 6
|
||||
}
|
||||
|
||||
function dateValue(value?: string): number {
|
||||
if (!value || value === '-') {
|
||||
return 0
|
||||
}
|
||||
|
||||
const date = new Date(value)
|
||||
return Number.isNaN(date.getTime()) ? 0 : date.getTime()
|
||||
}
|
||||
|
||||
function formatRunTime(value?: string): string {
|
||||
if (!value || value === '-') {
|
||||
return '-'
|
||||
}
|
||||
|
||||
const date = new Date(value)
|
||||
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return value
|
||||
}
|
||||
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(date)
|
||||
}
|
||||
|
||||
function projectReadinessState(project: ProjectConfig): ProjectReadinessState {
|
||||
if (projectHasBlockingIssue(project)) {
|
||||
return 'blocked'
|
||||
}
|
||||
|
||||
if (projectHasWarningIssue(project)) {
|
||||
return 'attention'
|
||||
}
|
||||
|
||||
if (!platform.canBuildProject(project.key)) {
|
||||
return 'readonly'
|
||||
}
|
||||
|
||||
return 'ready'
|
||||
}
|
||||
|
||||
function projectReadinessLabel(project: ProjectConfig): string {
|
||||
const state = projectReadinessState(project)
|
||||
|
||||
if (state === 'ready') {
|
||||
return '可发布'
|
||||
}
|
||||
|
||||
if (state === 'blocked') {
|
||||
return '有阻断'
|
||||
}
|
||||
|
||||
if (state === 'readonly') {
|
||||
return '只读'
|
||||
}
|
||||
|
||||
return '需关注'
|
||||
}
|
||||
|
||||
function projectReadinessTagType(
|
||||
project: ProjectConfig,
|
||||
): 'success' | 'warning' | 'danger' | 'info' {
|
||||
const state = projectReadinessState(project)
|
||||
|
||||
if (state === 'ready') {
|
||||
return 'success'
|
||||
}
|
||||
|
||||
if (state === 'blocked') {
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
return state === 'attention' ? 'warning' : 'info'
|
||||
}
|
||||
|
||||
function projectReadinessSummary(project: ProjectConfig): string {
|
||||
const issues = projectIssueSummaries(project)
|
||||
|
||||
if (issues.length > 0) {
|
||||
return issues[0]
|
||||
}
|
||||
|
||||
if (!platform.canBuildProject(project.key)) {
|
||||
return '当前账号只有只读权限'
|
||||
}
|
||||
|
||||
return '发布链路可用'
|
||||
}
|
||||
|
||||
function projectIssueSummaries(project: ProjectConfig): string[] {
|
||||
const issues: string[] = []
|
||||
|
||||
appendHealthIssue(issues, 'Gitea 仓库', project.giteaStatus, project.giteaMessage)
|
||||
appendHealthIssue(issues, 'Webhook / Relay', project.giteaWebhookStatus, project.giteaWebhookMessage)
|
||||
|
||||
for (const env of project.environments) {
|
||||
appendHealthIssue(issues, `${env.label} Jenkins`, env.jenkinsStatus, env.jenkinsMessage)
|
||||
}
|
||||
|
||||
appendHealthIssue(issues, '通知链路', project.integrations.wecom)
|
||||
|
||||
return issues
|
||||
}
|
||||
|
||||
function appendHealthIssue(
|
||||
issues: string[],
|
||||
label: string,
|
||||
state: HealthState,
|
||||
message?: string,
|
||||
) {
|
||||
if (state === 'healthy') {
|
||||
return
|
||||
}
|
||||
|
||||
const stateText = state === 'warning' ? '待配置' : state === 'offline' ? '离线' : '异常'
|
||||
issues.push(`${label}${message ? `:${message}` : `:${stateText}`}`)
|
||||
}
|
||||
|
||||
function projectHasBlockingIssue(project: ProjectConfig): boolean {
|
||||
return projectHealthStates(project).some((state) => state === 'error' || state === 'offline')
|
||||
}
|
||||
|
||||
function projectHasWarningIssue(project: ProjectConfig): boolean {
|
||||
return projectHealthStates(project).some((state) => state === 'warning')
|
||||
}
|
||||
|
||||
function projectHealthStates(project: ProjectConfig): HealthState[] {
|
||||
return [
|
||||
project.giteaStatus,
|
||||
project.giteaWebhookStatus,
|
||||
project.integrations.wecom,
|
||||
...project.environments.map((env) => env.jenkinsStatus),
|
||||
]
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-shell">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>运维总览</h1>
|
||||
<p>集中查看纳管项目环境、待处理发布、Jenkins/Gitea/通知平台/LLM 当前状态。</p>
|
||||
</div>
|
||||
<ElButton :icon="Refresh" type="primary" plain :loading="platform.loading" @click="platform.loadAll">
|
||||
刷新数据
|
||||
</ElButton>
|
||||
<div class="page-shell deployment-home">
|
||||
<form class="ask-bar" @submit.prevent="ask">
|
||||
<ElInput
|
||||
v-model="question"
|
||||
aria-label="向运维助手提问"
|
||||
placeholder="问问最近部署、项目情况或失败原因…"
|
||||
maxlength="2000"
|
||||
/><ElButton
|
||||
:disabled="!question.trim() || assistant.pending"
|
||||
:loading="assistant.pending"
|
||||
native-type="submit"
|
||||
>问助手 ↗</ElButton
|
||||
>
|
||||
</form>
|
||||
<div class="project-heading">
|
||||
<h1>项目</h1>
|
||||
<span v-if="activeCount" class="active-count">{{ activeCount }} 个项目正在部署</span
|
||||
><span v-else class="muted">当前没有部署任务</span
|
||||
><span v-if="platform.runningRuns.length" class="refresh-hint">执行中自动更新</span>
|
||||
</div>
|
||||
|
||||
<div class="status-grid">
|
||||
<MetricTile label="纳管项目" :value="platform.projects.length" caption="含 DevOps 平台自管理项目" :icon="Cpu" />
|
||||
<MetricTile label="可发布项目" :value="readyProjectCount" caption="无阻断且当前账号可构建" :icon="Promotion" tone="success" />
|
||||
<MetricTile label="运行中发布" :value="runningCount" caption="当前 Jenkins 或健康检查处理中" :icon="Finished" tone="warning" />
|
||||
<MetricTile label="失败提醒" :value="failedCount" caption="需要诊断或重试的 run" :icon="Failed" tone="danger" />
|
||||
</div>
|
||||
|
||||
<div class="section-grid">
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>值班焦点</h2>
|
||||
<span>{{ focusItems.length }} 项</span>
|
||||
<section class="panel project-list">
|
||||
<div class="list-toolbar">
|
||||
<div class="list-tabs" role="group" aria-label="部署筛选">
|
||||
<button :aria-pressed="filter === 'all'" @click="filter = 'all'">全部</button
|
||||
><button :aria-pressed="filter === 'active'" @click="filter = 'active'">部署中</button
|
||||
><button :aria-pressed="filter === 'failed'" @click="filter = 'failed'">最近失败</button>
|
||||
</div>
|
||||
<div class="panel-body focus-list">
|
||||
<div
|
||||
v-for="item in focusItems"
|
||||
:key="item.key"
|
||||
class="focus-row"
|
||||
:class="`tone-${item.tone}`"
|
||||
>
|
||||
<div class="focus-main">
|
||||
<span>{{ item.label }}</span>
|
||||
<strong>{{ item.value }}</strong>
|
||||
<small>{{ item.detail }}</small>
|
||||
</div>
|
||||
<RouterLink v-slot="{ navigate }" custom :to="item.to">
|
||||
<ElButton link type="primary" @click="navigate">{{ item.action }}</ElButton>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>优先 Run 队列</h2>
|
||||
<span>{{ priorityRuns.length }} / {{ platform.runs.length }} 条</span>
|
||||
</div>
|
||||
<div class="panel-body compact-list">
|
||||
<div v-for="run in priorityRuns" :key="run.id" class="list-row run-row">
|
||||
<span>
|
||||
<strong>{{ run.projectName }} · {{ run.ref }}</strong>
|
||||
<small>{{ run.environment }} · {{ run.actor }} · {{ formatRunTime(run.startedAt) }} · {{ run.duration }}</small>
|
||||
</span>
|
||||
<div class="row-actions">
|
||||
<StatusPill :state="run.status" />
|
||||
<RouterLink :to="{ name: 'runs', query: { runId: run.id } }">
|
||||
<ElButton :icon="Tickets" link type="primary">详情</ElButton>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
<ElEmpty v-if="priorityRuns.length === 0" description="暂无运行记录" />
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>项目发布健康</h2>
|
||||
<span>{{ readyProjectCount }} / {{ platform.projects.length }} 个项目可发布</span>
|
||||
<ElInput
|
||||
v-model="search"
|
||||
:prefix-icon="Search"
|
||||
aria-label="搜索项目"
|
||||
placeholder="搜索项目…"
|
||||
clearable
|
||||
class="project-search"
|
||||
/>
|
||||
</div>
|
||||
<div class="panel-body project-attention-grid">
|
||||
<article class="health-summary-card">
|
||||
<span>成功记录</span>
|
||||
<strong>{{ successCount }}</strong>
|
||||
<small>最近发布成功数</small>
|
||||
</article>
|
||||
<article class="health-summary-card warning">
|
||||
<span>需关注</span>
|
||||
<strong>{{ attentionProjects.length }}</strong>
|
||||
<small>存在待配置项</small>
|
||||
</article>
|
||||
<article class="health-summary-card danger">
|
||||
<span>有阻断</span>
|
||||
<strong>{{ blockedProjects.length }}</strong>
|
||||
<small>发布前需要处理</small>
|
||||
</article>
|
||||
<div class="attention-list">
|
||||
<div v-if="projectAttentionQueue.length === 0" class="attention-empty">
|
||||
<strong>项目链路当前稳定</strong>
|
||||
<span>纳管项目未发现阻断或关注项。</span>
|
||||
</div>
|
||||
<div
|
||||
v-for="project in projectAttentionQueue"
|
||||
:key="project.key"
|
||||
class="attention-row"
|
||||
>
|
||||
<div>
|
||||
<strong>{{ project.name }}</strong>
|
||||
<small>{{ projectReadinessSummary(project) }}</small>
|
||||
</div>
|
||||
<div class="row-actions">
|
||||
<ElTag :type="projectReadinessTagType(project)" effect="light" round>
|
||||
{{ projectReadinessLabel(project) }}
|
||||
</ElTag>
|
||||
<RouterLink :to="{ name: 'projects' }">
|
||||
<ElButton link type="primary">查看</ElButton>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
<article
|
||||
v-for="row in projectRows"
|
||||
:key="row.project.key"
|
||||
class="project-row"
|
||||
:class="{ deploying: row.activeCount }"
|
||||
>
|
||||
<div class="project-name">
|
||||
<strong>{{ row.project.name }}</strong
|
||||
><small v-if="row.run"
|
||||
>{{ row.run.environment === 'production' ? '生产' : '测试' }} ·
|
||||
<span class="mono">{{ row.run.ref }}</span
|
||||
><span v-if="row.activeCount > 1"> · 另有 {{ row.activeCount - 1 }} 个任务</span></small
|
||||
><small v-else>尚无发布记录</small>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>项目环境</h2>
|
||||
<span>测试/生产状态和快捷入口</span>
|
||||
</div>
|
||||
<div class="project-grid panel-body">
|
||||
<article
|
||||
v-for="project in platform.projects"
|
||||
:key="project.key"
|
||||
class="project-card"
|
||||
:class="`readiness-${projectReadinessState(project)}`"
|
||||
>
|
||||
<div class="project-head">
|
||||
<div>
|
||||
<strong>{{ project.name }}</strong>
|
||||
<small>{{ project.serviceType }}</small>
|
||||
</div>
|
||||
<ElTag type="info" round>{{ project.defaultBranch }}</ElTag>
|
||||
</div>
|
||||
<div class="project-readiness">
|
||||
<ElTag :type="projectReadinessTagType(project)" effect="light" round>
|
||||
{{ projectReadinessLabel(project) }}
|
||||
</ElTag>
|
||||
<small>{{ projectReadinessSummary(project) }}</small>
|
||||
</div>
|
||||
<div class="compact-list">
|
||||
<div v-for="env in project.environments" :key="env.name" class="env-row">
|
||||
<span>
|
||||
<strong>{{ env.label }}</strong>
|
||||
<small>{{ env.version }} · {{ env.lastReleasedAt }}</small>
|
||||
</span>
|
||||
<StatusPill :state="env.status" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="project-card-actions">
|
||||
<RouterLink
|
||||
v-slot="{ navigate }"
|
||||
custom
|
||||
:to="{ name: 'releases', query: { projectKey: project.key } }"
|
||||
>
|
||||
<ElButton
|
||||
:icon="Promotion"
|
||||
link
|
||||
type="primary"
|
||||
:disabled="!platform.canBuildProject(project.key)"
|
||||
@click="navigate"
|
||||
>
|
||||
发布
|
||||
</ElButton>
|
||||
</RouterLink>
|
||||
<RouterLink :to="{ name: 'runs', query: { projectKey: project.key } }">
|
||||
<ElButton :icon="Tickets" link type="primary">运行记录</ElButton>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</article>
|
||||
<StatusPill v-if="row.run" :state="row.run.status" /><span v-else class="no-status">—</span
|
||||
><time>{{ formatTime(row.run?.startedAt) }}</time
|
||||
><RouterLink
|
||||
v-if="row.run"
|
||||
class="log-link"
|
||||
:to="{ name: 'runs', query: { runId: row.run.id } }"
|
||||
>查看日志 →</RouterLink
|
||||
><span v-else class="no-log">暂无日志</span>
|
||||
</article>
|
||||
<div v-if="!projectRows.length" class="quiet-empty">
|
||||
<strong>{{ search || filter !== 'all' ? '没有匹配的项目' : '暂无可访问的项目' }}</strong>
|
||||
<p>{{ search || filter !== 'all' ? '调整筛选后再试。' : '请联系管理员分配项目权限。' }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.focus-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
.deployment-home {
|
||||
gap: 23px;
|
||||
}
|
||||
|
||||
.focus-row {
|
||||
.ask-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 86px;
|
||||
padding: 14px;
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
padding: 10px 12px 10px 18px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 9px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.focus-row.tone-danger {
|
||||
border-color: #fecaca;
|
||||
background: #fff7f7;
|
||||
.ask-bar :deep(.el-input__wrapper) {
|
||||
box-shadow: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.focus-row.tone-warning {
|
||||
border-color: #fde68a;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.focus-row.tone-active {
|
||||
border-color: #bfdbfe;
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.focus-row.tone-success {
|
||||
border-color: #bbf7d0;
|
||||
background: #f0fdf4;
|
||||
}
|
||||
|
||||
.focus-main {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.focus-main span,
|
||||
.health-summary-card span {
|
||||
display: block;
|
||||
color: #64748b;
|
||||
.ask-bar :deep(.el-input__inner) {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.focus-main strong,
|
||||
.health-summary-card strong {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
color: #0f172a;
|
||||
font-size: 24px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.focus-main small,
|
||||
.health-summary-card small {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: #64748b;
|
||||
.ask-bar .el-button {
|
||||
flex-shrink: 0;
|
||||
border-color: transparent;
|
||||
color: var(--accent);
|
||||
background: #f4f2fa;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.row-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.run-row {
|
||||
min-height: 68px;
|
||||
}
|
||||
|
||||
.project-attention-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(140px, 0.35fr)) minmax(320px, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.health-summary-card {
|
||||
min-width: 0;
|
||||
padding: 14px;
|
||||
border: 1px solid #d8e2ef;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.health-summary-card.warning {
|
||||
border-color: #fde68a;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.health-summary-card.danger {
|
||||
border-color: #fecaca;
|
||||
background: #fef2f2;
|
||||
}
|
||||
|
||||
.attention-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.attention-row,
|
||||
.attention-empty {
|
||||
.project-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-height: 68px;
|
||||
padding: 12px;
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
gap: 15px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.attention-row strong,
|
||||
.attention-empty strong {
|
||||
display: block;
|
||||
color: #172033;
|
||||
font-size: 14px;
|
||||
.project-heading h1 {
|
||||
margin: 0;
|
||||
font-size: 21px;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.attention-row small,
|
||||
.attention-empty span {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
.project-heading > span {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.project-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.project-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
border: 1px solid #e3e8f2;
|
||||
border-radius: 8px;
|
||||
background: #fbfcff;
|
||||
}
|
||||
|
||||
.project-card.readiness-blocked {
|
||||
border-color: #fecaca;
|
||||
background: #fffafa;
|
||||
}
|
||||
|
||||
.project-card.readiness-attention {
|
||||
border-color: #fde68a;
|
||||
background: #fffdf5;
|
||||
}
|
||||
|
||||
.project-head,
|
||||
.env-row {
|
||||
display: flex;
|
||||
.active-count {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.project-head {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.project-head strong,
|
||||
.env-row strong {
|
||||
display: block;
|
||||
color: #172033;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.project-head small,
|
||||
.env-row small {
|
||||
display: block;
|
||||
margin-top: 3px;
|
||||
color: #7b8798;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.env-row {
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.project-readiness {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
min-height: 54px;
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.project-readiness small {
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
.active-count::before {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
content: '';
|
||||
}
|
||||
|
||||
.project-card-actions {
|
||||
.refresh-hint {
|
||||
color: var(--text-muted);
|
||||
margin-left: auto;
|
||||
}
|
||||
.list-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: auto;
|
||||
padding-top: 2px;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.project-grid,
|
||||
.project-attention-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.list-tabs {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
.list-tabs button {
|
||||
border: 0;
|
||||
padding: 6px 0;
|
||||
color: var(--text-muted);
|
||||
background: transparent;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
.list-tabs button[aria-pressed='true'] {
|
||||
color: var(--accent);
|
||||
font-weight: 550;
|
||||
}
|
||||
.project-search {
|
||||
max-width: 180px;
|
||||
}
|
||||
.project-search :deep(.el-input__wrapper) {
|
||||
box-shadow: none;
|
||||
background: #f7f7fa;
|
||||
}
|
||||
.project-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(200px, 1fr) 85px 135px 100px;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
padding: 15px 24px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.project-row:last-of-type {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.project-row.deploying {
|
||||
background: #fcfbff;
|
||||
}
|
||||
.project-name {
|
||||
min-width: 0;
|
||||
}
|
||||
.project-name strong {
|
||||
font-size: 13px;
|
||||
font-weight: 550;
|
||||
color: #353c49;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.project-name small {
|
||||
display: block;
|
||||
margin-top: 7px;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.project-row time {
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.log-link {
|
||||
justify-self: end;
|
||||
font-size: 12px;
|
||||
color: var(--accent);
|
||||
}
|
||||
.log-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.no-status,
|
||||
.no-log {
|
||||
color: #9b9fac;
|
||||
font-size: 11px;
|
||||
}
|
||||
.no-log {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.project-grid,
|
||||
.project-attention-grid {
|
||||
grid-template-columns: 1fr;
|
||||
.project-row {
|
||||
grid-template-columns: minmax(140px, 1fr) 72px 85px;
|
||||
gap: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.focus-row,
|
||||
.attention-row,
|
||||
.attention-empty {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
.project-row time {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.row-actions {
|
||||
justify-content: flex-start;
|
||||
.list-toolbar {
|
||||
padding: 13px 16px;
|
||||
}
|
||||
.project-search {
|
||||
max-width: 145px;
|
||||
}
|
||||
.list-tabs {
|
||||
gap: 14px;
|
||||
}
|
||||
.refresh-hint {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@media (max-width: 430px) {
|
||||
.list-toolbar {
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.project-search {
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
}
|
||||
.project-row {
|
||||
padding: 20px 16px;
|
||||
grid-template-columns: minmax(120px, 1fr) 60px 76px;
|
||||
gap: 10px;
|
||||
}
|
||||
.log-link {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+206
-674
@@ -1,269 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 项目配置页展示项目仓库、发布环境、Gitea 仓库诊断和真实 Jenkins job 诊断状态。
|
||||
*/
|
||||
import { Promotion, Refresh, Search } from '@element-plus/icons-vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Search, Refresh } from '@element-plus/icons-vue'
|
||||
import StatusPill from '../components/StatusPill.vue'
|
||||
import { usePlatformStore } from '../stores/platform'
|
||||
import type { EnvironmentStatus, HealthState, ProjectConfig, ProjectPermissionLevel } from '../types/devops'
|
||||
import { useSessionStore } from '../stores/session'
|
||||
import type { ProjectConfig } from '../types/devops'
|
||||
|
||||
const platform = usePlatformStore()
|
||||
const diagnosticsLoading = ref(false)
|
||||
const searchKeyword = ref('')
|
||||
const readinessFilter = ref<ProjectReadinessState | ''>('')
|
||||
const permissionFilter = ref<ProjectPermissionLevel | ''>('')
|
||||
|
||||
type ProjectReadinessState = 'ready' | 'attention' | 'blocked' | 'readonly'
|
||||
|
||||
const readinessOptions: Array<{ label: string; value: ProjectReadinessState }> = [
|
||||
{ label: '可发布', value: 'ready' },
|
||||
{ label: '需关注', value: 'attention' },
|
||||
{ label: '有阻断', value: 'blocked' },
|
||||
{ label: '只读', value: 'readonly' },
|
||||
]
|
||||
|
||||
const permissionOptions: Array<{ label: string; value: ProjectPermissionLevel }> = [
|
||||
{ label: '构建权限', value: 'build' },
|
||||
{ label: '只读权限', value: 'read' },
|
||||
]
|
||||
|
||||
const filteredProjects = computed(() => {
|
||||
const keyword = searchKeyword.value.trim().toLowerCase()
|
||||
|
||||
return platform.projects.filter((project) => {
|
||||
if (readinessFilter.value && projectReadinessState(project) !== readinessFilter.value) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (permissionFilter.value && platform.projectPermissionLevel(project.key) !== permissionFilter.value) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!keyword) {
|
||||
return true
|
||||
}
|
||||
|
||||
return [
|
||||
project.name,
|
||||
project.key,
|
||||
project.serviceType,
|
||||
project.repository,
|
||||
project.defaultBranch,
|
||||
project.tagPolicy,
|
||||
project.permissionLevelName,
|
||||
]
|
||||
.filter((value): value is string => typeof value === 'string' && value.length > 0)
|
||||
.some((value) => value.toLowerCase().includes(keyword))
|
||||
})
|
||||
})
|
||||
|
||||
const projectOverview = computed(() => {
|
||||
const ready = platform.projects.filter((project) => projectReadinessState(project) === 'ready').length
|
||||
const attention = platform.projects.filter((project) => projectReadinessState(project) === 'attention').length
|
||||
const blocked = platform.projects.filter((project) => projectReadinessState(project) === 'blocked').length
|
||||
const readOnly = platform.projects.filter((project) => projectReadinessState(project) === 'readonly').length
|
||||
|
||||
return [
|
||||
{ key: 'total', label: '纳管项目', value: platform.projects.length, tone: 'neutral' },
|
||||
{ key: 'ready', label: '可发布', value: ready, tone: 'success' },
|
||||
{ key: 'attention', label: '需关注', value: attention, tone: attention > 0 ? 'warning' : 'neutral' },
|
||||
{ key: 'blocked', label: '有阻断', value: blocked, tone: blocked > 0 ? 'danger' : 'neutral' },
|
||||
{ key: 'readonly', label: '只读项目', value: readOnly, tone: readOnly > 0 ? 'muted' : 'neutral' },
|
||||
]
|
||||
})
|
||||
|
||||
const hasActiveFilters = computed(() => Boolean(
|
||||
searchKeyword.value.trim() ||
|
||||
readinessFilter.value ||
|
||||
permissionFilter.value,
|
||||
))
|
||||
|
||||
onMounted(() => {
|
||||
void refreshProjectDiagnostics()
|
||||
})
|
||||
|
||||
async function refreshProjectDiagnostics() {
|
||||
diagnosticsLoading.value = true
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
platform.loadProjectJenkinsDiagnostics(),
|
||||
platform.loadProjectGiteaDiagnostics(),
|
||||
])
|
||||
} finally {
|
||||
diagnosticsLoading.value = false
|
||||
}
|
||||
const session = useSessionStore()
|
||||
const search = ref('')
|
||||
const route = useRoute()
|
||||
const selectedKey = ref(typeof route.query.projectKey === 'string' ? route.query.projectKey : '')
|
||||
watch(
|
||||
() => route.query.projectKey,
|
||||
(key) => {
|
||||
if (typeof key === 'string') selectedKey.value = key
|
||||
},
|
||||
)
|
||||
const diagnosing = ref(false)
|
||||
const diagnosisError = ref('')
|
||||
const selected = computed(() =>
|
||||
platform.projects.find((project) => project.key === selectedKey.value),
|
||||
)
|
||||
const projects = computed(() =>
|
||||
platform.projects.filter((project) =>
|
||||
`${project.name} ${project.repository}`
|
||||
.toLowerCase()
|
||||
.includes(search.value.trim().toLowerCase()),
|
||||
),
|
||||
)
|
||||
const hasDiagnostics = computed(() =>
|
||||
Boolean(platform.projectGiteaDiagnostics || platform.projectJenkinsDiagnostics),
|
||||
)
|
||||
function openProject(project: ProjectConfig) {
|
||||
selectedKey.value = project.key
|
||||
}
|
||||
|
||||
function lastBuildText(env: EnvironmentStatus): string {
|
||||
if (!env.jenkinsLastBuild?.number) {
|
||||
return '-'
|
||||
async function diagnose() {
|
||||
diagnosing.value = true
|
||||
diagnosisError.value = ''
|
||||
const results = await Promise.allSettled([
|
||||
platform.loadProjectGiteaDiagnostics(),
|
||||
platform.loadProjectJenkinsDiagnostics(),
|
||||
])
|
||||
const failures = results.filter((result) => result.status === 'rejected')
|
||||
if (failures.length) {
|
||||
diagnosisError.value = failures
|
||||
.map((result) => (result.reason instanceof Error ? result.reason.message : '诊断失败'))
|
||||
.join(';')
|
||||
ElMessage.error(diagnosisError.value)
|
||||
}
|
||||
|
||||
if (env.jenkinsLastBuild.building) {
|
||||
return `#${env.jenkinsLastBuild.number} 运行中`
|
||||
}
|
||||
|
||||
return `#${env.jenkinsLastBuild.number} ${env.jenkinsLastBuild.result || 'UNKNOWN'}`
|
||||
}
|
||||
|
||||
function commitText(project: ProjectConfig): string {
|
||||
const commit = project.giteaLatestCommit
|
||||
|
||||
if (!commit?.sha) {
|
||||
return '-'
|
||||
}
|
||||
|
||||
const title = commit.message.split('\n')[0] || '无提交说明'
|
||||
return `${commit.sha.slice(0, 8)} · ${title}`
|
||||
}
|
||||
|
||||
function branchTagText(project: ProjectConfig): string {
|
||||
if (project.giteaBranchCount === undefined && project.giteaTagCount === undefined) {
|
||||
return '尚未诊断'
|
||||
}
|
||||
|
||||
const branchCount = project.giteaBranchCount ?? 0
|
||||
const tagCount = project.giteaTagCount ?? 0
|
||||
|
||||
return `${branchCount} branches · ${tagCount} tags`
|
||||
}
|
||||
|
||||
function webhookCountText(project: ProjectConfig): string {
|
||||
if (
|
||||
project.giteaWebhookHookCount === undefined &&
|
||||
project.giteaWebhookActivePushHookCount === undefined
|
||||
) {
|
||||
return '尚未诊断'
|
||||
}
|
||||
|
||||
return `${project.giteaWebhookActivePushHookCount ?? 0}/${project.giteaWebhookHookCount ?? 0} 个 active push hook`
|
||||
}
|
||||
|
||||
function webhookHookText(hook: ProjectConfig['giteaWebhookHooks'][number]): string {
|
||||
const events = hook.events.length > 0 ? hook.events.join(', ') : '无事件'
|
||||
const branch = hook.branchFilter ? ` · ${hook.branchFilter}` : ''
|
||||
const matched = hook.matchesExpectedRelay ? ' · relay 匹配' : ''
|
||||
const active = hook.active ? '启用' : '停用'
|
||||
|
||||
return `#${hook.id} ${hook.type} · ${active} · ${events}${branch}${matched}`
|
||||
}
|
||||
|
||||
function projectReadinessState(project: ProjectConfig): ProjectReadinessState {
|
||||
if (projectHasBlockingIssue(project)) {
|
||||
return 'blocked'
|
||||
}
|
||||
|
||||
if (projectHasWarningIssue(project)) {
|
||||
return 'attention'
|
||||
}
|
||||
|
||||
if (!platform.canBuildProject(project.key)) {
|
||||
return 'readonly'
|
||||
}
|
||||
|
||||
return 'ready'
|
||||
}
|
||||
|
||||
function projectReadinessLabel(project: ProjectConfig): string {
|
||||
const state = projectReadinessState(project)
|
||||
|
||||
if (state === 'ready') {
|
||||
return '可发布'
|
||||
}
|
||||
|
||||
if (state === 'blocked') {
|
||||
return '有阻断'
|
||||
}
|
||||
|
||||
if (state === 'readonly') {
|
||||
return '只读'
|
||||
}
|
||||
|
||||
return '需关注'
|
||||
}
|
||||
|
||||
function projectReadinessTagType(
|
||||
project: ProjectConfig,
|
||||
): 'success' | 'warning' | 'danger' | 'info' {
|
||||
const state = projectReadinessState(project)
|
||||
|
||||
if (state === 'ready') {
|
||||
return 'success'
|
||||
}
|
||||
|
||||
if (state === 'blocked') {
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
return state === 'attention' ? 'warning' : 'info'
|
||||
}
|
||||
|
||||
function projectReadinessSummary(project: ProjectConfig): string {
|
||||
const issues = projectIssueSummaries(project)
|
||||
|
||||
if (issues.length > 0) {
|
||||
return issues[0]
|
||||
}
|
||||
|
||||
if (!platform.canBuildProject(project.key)) {
|
||||
return '当前账号只有只读权限'
|
||||
}
|
||||
|
||||
return 'Gitea、Jenkins、Webhook 和通知链路均未发现异常'
|
||||
}
|
||||
|
||||
function projectIssueSummaries(project: ProjectConfig): string[] {
|
||||
const issues: string[] = []
|
||||
|
||||
appendHealthIssue(issues, 'Gitea 仓库', project.giteaStatus, project.giteaMessage)
|
||||
appendHealthIssue(issues, 'Webhook / Relay', project.giteaWebhookStatus, project.giteaWebhookMessage)
|
||||
|
||||
for (const env of project.environments) {
|
||||
appendHealthIssue(issues, `${env.label} Jenkins`, env.jenkinsStatus, env.jenkinsMessage)
|
||||
}
|
||||
|
||||
appendHealthIssue(issues, '通知链路', project.integrations.wecom)
|
||||
|
||||
return issues
|
||||
}
|
||||
|
||||
function appendHealthIssue(
|
||||
issues: string[],
|
||||
label: string,
|
||||
state: HealthState,
|
||||
message?: string,
|
||||
) {
|
||||
if (state === 'healthy') {
|
||||
return
|
||||
}
|
||||
|
||||
const stateText = state === 'warning' ? '待配置' : state === 'offline' ? '离线' : '异常'
|
||||
issues.push(`${label}${message ? `:${message}` : `:${stateText}`}`)
|
||||
}
|
||||
|
||||
function projectHasBlockingIssue(project: ProjectConfig): boolean {
|
||||
return projectHealthStates(project).some((state) => state === 'error' || state === 'offline')
|
||||
}
|
||||
|
||||
function projectHasWarningIssue(project: ProjectConfig): boolean {
|
||||
return projectHealthStates(project).some((state) => state === 'warning')
|
||||
}
|
||||
|
||||
function projectHealthStates(project: ProjectConfig): HealthState[] {
|
||||
return [
|
||||
project.giteaStatus,
|
||||
project.giteaWebhookStatus,
|
||||
project.integrations.wecom,
|
||||
...project.environments.map((env) => env.jenkinsStatus),
|
||||
]
|
||||
}
|
||||
|
||||
function resetProjectFilters() {
|
||||
searchKeyword.value = ''
|
||||
readinessFilter.value = ''
|
||||
permissionFilter.value = ''
|
||||
diagnosing.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -271,442 +59,186 @@ function resetProjectFilters() {
|
||||
<div class="page-shell">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>项目配置</h1>
|
||||
<p>展示后端返回的项目、环境、Jenkins Job、Gitea 仓库和通知通道绑定关系。</p>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<ElTag type="info" round>后端配置源</ElTag>
|
||||
<ElButton
|
||||
:icon="Refresh"
|
||||
type="primary"
|
||||
plain
|
||||
:loading="diagnosticsLoading"
|
||||
@click="refreshProjectDiagnostics"
|
||||
>
|
||||
刷新项目诊断
|
||||
</ElButton>
|
||||
<h1>项目接入</h1>
|
||||
<p>查看仓库、发布环境与构建任务的对应关系。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="project-overview-grid">
|
||||
<article
|
||||
v-for="item in projectOverview"
|
||||
:key="item.key"
|
||||
class="project-overview-card"
|
||||
:class="`tone-${item.tone}`"
|
||||
<ElButton
|
||||
v-if="session.role === 'super_admin'"
|
||||
:icon="Refresh"
|
||||
:loading="diagnosing"
|
||||
@click="diagnose"
|
||||
>检查接入</ElButton
|
||||
>
|
||||
<span>{{ item.label }}</span>
|
||||
<strong>{{ item.value }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
<ElAlert
|
||||
v-if="diagnosisError"
|
||||
title="部分接入检查失败"
|
||||
:description="diagnosisError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
/>
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>项目清单</h2>
|
||||
<span>{{ filteredProjects.length }} / {{ platform.projects.length }} 个项目</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="project-filter-bar">
|
||||
<ElInput
|
||||
v-model="searchKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
placeholder="搜索项目 / 仓库 / 默认分支"
|
||||
class="project-search-input"
|
||||
/>
|
||||
<ElSelect v-model="readinessFilter" clearable placeholder="发布态">
|
||||
<ElOption
|
||||
v-for="option in readinessOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElSelect v-model="permissionFilter" clearable placeholder="权限">
|
||||
<ElOption
|
||||
v-for="option in permissionOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElButton :disabled="!hasActiveFilters" @click="resetProjectFilters">
|
||||
重置筛选
|
||||
</ElButton>
|
||||
</div>
|
||||
<ElTable :data="filteredProjects" row-key="key" empty-text="没有符合条件的项目">
|
||||
<ElTableColumn type="expand">
|
||||
<template #default="{ row }">
|
||||
<div class="env-config">
|
||||
<div class="project-diagnostic-card">
|
||||
<div class="env-config-head">
|
||||
<strong>Gitea 仓库诊断</strong>
|
||||
<StatusPill :state="row.giteaStatus" />
|
||||
</div>
|
||||
<dl>
|
||||
<dt>仓库状态</dt>
|
||||
<dd>
|
||||
<StatusPill :state="row.giteaStatus" />
|
||||
<span class="diagnostic-message">{{ row.giteaMessage }}</span>
|
||||
</dd>
|
||||
<dt>公开地址</dt>
|
||||
<dd>
|
||||
<a
|
||||
v-if="row.giteaWebUrl"
|
||||
:href="row.giteaWebUrl"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
{{ row.giteaWebUrl }}
|
||||
</a>
|
||||
<span v-else class="mono">{{ row.repository }}</span>
|
||||
</dd>
|
||||
<dt>默认分支</dt>
|
||||
<dd>{{ row.giteaDefaultBranch || row.defaultBranch }}</dd>
|
||||
<dt>分支 / Tag</dt>
|
||||
<dd>{{ branchTagText(row) }}</dd>
|
||||
<dt>默认分支 commit</dt>
|
||||
<dd class="mono">{{ commitText(row) }}</dd>
|
||||
<dt>Webhook / Relay</dt>
|
||||
<dd>
|
||||
<StatusPill :state="row.giteaWebhookStatus" />
|
||||
<span class="diagnostic-message">{{ row.giteaWebhookMessage }}</span>
|
||||
</dd>
|
||||
<dt>Relay 目标</dt>
|
||||
<dd class="mono">{{ row.giteaWebhookExpectedRelayTarget || '-' }}</dd>
|
||||
<dt>Hook 数量</dt>
|
||||
<dd>{{ webhookCountText(row) }}</dd>
|
||||
<dt>Hook 明细</dt>
|
||||
<dd>
|
||||
<div v-if="row.giteaWebhookHooks.length > 0" class="webhook-hook-list">
|
||||
<div
|
||||
v-for="hook in row.giteaWebhookHooks"
|
||||
:key="hook.id"
|
||||
class="webhook-hook-item"
|
||||
>
|
||||
<span>{{ webhookHookText(hook) }}</span>
|
||||
<small class="mono">{{ hook.target || '-' }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<span v-else>-</span>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div v-for="env in row.environments" :key="env.name" class="env-config-card">
|
||||
<div class="env-config-head">
|
||||
<strong>{{ env.label }}</strong>
|
||||
<StatusPill :state="env.status" />
|
||||
</div>
|
||||
<dl>
|
||||
<dt>分支策略</dt>
|
||||
<dd>{{ env.branchPolicy }}</dd>
|
||||
<dt>Jenkins Job</dt>
|
||||
<dd class="mono">{{ env.jenkinsJob }}</dd>
|
||||
<dt>Job 状态</dt>
|
||||
<dd>
|
||||
<StatusPill :state="env.jenkinsStatus" />
|
||||
<span class="diagnostic-message">{{ env.jenkinsMessage }}</span>
|
||||
</dd>
|
||||
<dt>最近构建</dt>
|
||||
<dd>
|
||||
<a
|
||||
v-if="env.jenkinsLastBuild?.url"
|
||||
:href="env.jenkinsLastBuild.url"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
{{ lastBuildText(env) }}
|
||||
</a>
|
||||
<span v-else>{{ lastBuildText(env) }}</span>
|
||||
</dd>
|
||||
<dt>通知通道</dt>
|
||||
<dd>{{ env.wecomRobot }}</dd>
|
||||
<dt>最近发布</dt>
|
||||
<dd>
|
||||
<div v-if="env.lastRunId !== '-'" class="latest-release">
|
||||
<div class="latest-release-head">
|
||||
<StatusPill :state="env.status" />
|
||||
<RouterLink
|
||||
class="run-link mono"
|
||||
:to="{ name: 'runs', query: { runId: env.lastRunId } }"
|
||||
>
|
||||
{{ env.lastRunId }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
<small>
|
||||
{{ env.version }} · {{ env.lastActor }} · {{ env.lastReleasedAt }}
|
||||
</small>
|
||||
</div>
|
||||
<span v-else>暂无真实发布记录</span>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="name" label="项目" min-width="150" />
|
||||
<ElTableColumn label="发布态" min-width="190">
|
||||
<template #default="{ row }">
|
||||
<div class="readiness-cell">
|
||||
<ElTag :type="projectReadinessTagType(row)" effect="light" round>
|
||||
{{ projectReadinessLabel(row) }}
|
||||
</ElTag>
|
||||
<small>{{ projectReadinessSummary(row) }}</small>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="权限" width="120">
|
||||
<template #default="{ row }">
|
||||
<ElTag :type="platform.canBuildProject(row.key) ? 'success' : 'info'" effect="plain" round>
|
||||
{{ platform.canBuildProject(row.key) ? '构建' : '只读' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="serviceType" label="类型" min-width="130" />
|
||||
<ElTableColumn prop="repository" label="Gitea 仓库" min-width="320">
|
||||
<template #default="{ row }">
|
||||
<span class="mono">{{ row.repository }}</span>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn prop="defaultBranch" label="默认分支" width="120" />
|
||||
<ElTableColumn prop="tagPolicy" label="Tag 策略" min-width="220" />
|
||||
<ElTableColumn label="集成状态" width="280">
|
||||
<template #default="{ row }">
|
||||
<div class="status-tags">
|
||||
<StatusPill :state="row.integrations.jenkins" text="Jenkins" />
|
||||
<StatusPill :state="row.integrations.gitea" text="Gitea" />
|
||||
<StatusPill :state="row.integrations.wecom" text="通知" />
|
||||
<StatusPill :state="row.integrations.llm" text="LLM" />
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
<ElTableColumn label="操作" width="170" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<div class="project-actions">
|
||||
<RouterLink
|
||||
v-slot="{ navigate }"
|
||||
custom
|
||||
:to="{ name: 'releases', query: { projectKey: row.key } }"
|
||||
>
|
||||
<ElButton
|
||||
:icon="Promotion"
|
||||
link
|
||||
type="primary"
|
||||
:disabled="!platform.canBuildProject(row.key)"
|
||||
@click="navigate"
|
||||
>
|
||||
发布
|
||||
</ElButton>
|
||||
</RouterLink>
|
||||
<RouterLink :to="{ name: 'runs', query: { projectKey: row.key } }">
|
||||
<ElButton link type="primary">运行记录</ElButton>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ElTable>
|
||||
<h2>纳管项目 · {{ projects.length }}</h2>
|
||||
<ElInput
|
||||
v-model="search"
|
||||
:prefix-icon="Search"
|
||||
aria-label="搜索项目接入"
|
||||
placeholder="搜索项目或仓库…"
|
||||
clearable
|
||||
class="project-search"
|
||||
/>
|
||||
</div>
|
||||
<ElTable :data="projects" empty-text="没有可访问的项目">
|
||||
<ElTableColumn label="项目" min-width="210"
|
||||
><template #default="{ row }"
|
||||
><button class="project-name" @click="openProject(row)">{{ row.name }}</button>
|
||||
<div class="field-hint">{{ row.defaultBranch }}</div></template
|
||||
></ElTableColumn
|
||||
>
|
||||
<ElTableColumn label="仓库" min-width="190"
|
||||
><template #default="{ row }"
|
||||
><span class="mono">{{ row.owner }}/{{ row.repo }}</span></template
|
||||
></ElTableColumn
|
||||
>
|
||||
<ElTableColumn label="发布环境" min-width="150"
|
||||
><template #default="{ row }"
|
||||
><div class="toolbar">
|
||||
<ElTag
|
||||
v-for="environment in row.environments"
|
||||
:key="environment.name"
|
||||
type="info"
|
||||
effect="plain"
|
||||
>{{ environment.label }}</ElTag
|
||||
>
|
||||
</div></template
|
||||
></ElTableColumn
|
||||
>
|
||||
<ElTableColumn v-if="hasDiagnostics" label="接入检查" width="145"
|
||||
><template #default="{ row }"
|
||||
><StatusPill :state="row.giteaStatus" text="仓库" /><StatusPill
|
||||
:state="row.integrations.jenkins"
|
||||
text="构建" /></template
|
||||
></ElTableColumn>
|
||||
<ElTableColumn label="" width="100"
|
||||
><template #default="{ row }"
|
||||
><ElButton text @click="openProject(row)">查看配置</ElButton></template
|
||||
></ElTableColumn
|
||||
>
|
||||
</ElTable>
|
||||
</section>
|
||||
<p class="field-hint">
|
||||
项目与环境配置由服务端维护。需要新增项目或修改构建任务时,请更新服务端配置。
|
||||
</p>
|
||||
<ElDrawer
|
||||
:model-value="Boolean(selected)"
|
||||
:title="selected?.name || '项目配置'"
|
||||
size="520px"
|
||||
@close="selectedKey = ''"
|
||||
>
|
||||
<template v-if="selected">
|
||||
<dl class="project-details">
|
||||
<dt>代码仓库</dt>
|
||||
<dd>
|
||||
<a
|
||||
class="text-link"
|
||||
:href="selected.repository.replace(/\.git$/, '')"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>{{ selected.owner }}/{{ selected.repo }}</a
|
||||
>
|
||||
</dd>
|
||||
<dt>默认分支</dt>
|
||||
<dd class="mono">{{ selected.defaultBranch }}</dd>
|
||||
<dt>操作权限</dt>
|
||||
<dd>{{ platform.canBuildProject(selected.key) ? '可发布' : '只读' }}</dd>
|
||||
</dl>
|
||||
<section
|
||||
v-for="environment in selected.environments"
|
||||
:key="environment.name"
|
||||
class="environment-config"
|
||||
>
|
||||
<h2>{{ environment.label }}</h2>
|
||||
<dl class="project-details">
|
||||
<dt>构建任务</dt>
|
||||
<dd class="mono">{{ environment.jenkinsJob }}</dd>
|
||||
<dt>发布策略</dt>
|
||||
<dd>{{ environment.branchPolicy }}</dd>
|
||||
</dl>
|
||||
<p v-if="hasDiagnostics" class="field-hint">
|
||||
<StatusPill :state="environment.jenkinsStatus" /> {{ environment.jenkinsMessage }}
|
||||
</p>
|
||||
<RouterLink
|
||||
v-if="platform.canBuildProject(selected.key)"
|
||||
class="button-link"
|
||||
:to="{
|
||||
name: 'releases',
|
||||
query: { projectKey: selected.key, environment: environment.name },
|
||||
}"
|
||||
>发布到此环境</RouterLink
|
||||
>
|
||||
</section>
|
||||
<details v-if="hasDiagnostics" class="diagnostics">
|
||||
<summary>仓库与 Webhook 诊断</summary>
|
||||
<p>{{ selected.giteaMessage || '暂无仓库诊断' }}</p>
|
||||
<p>{{ selected.giteaWebhookMessage || '暂无 Webhook 诊断' }}</p>
|
||||
</details>
|
||||
</template>
|
||||
</ElDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.project-overview-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
.project-search {
|
||||
width: 230px;
|
||||
}
|
||||
|
||||
.project-overview-card {
|
||||
min-width: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #d8e2ef;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.project-overview-card span {
|
||||
display: block;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.project-overview-card strong {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: #0f172a;
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.project-overview-card.tone-success {
|
||||
border-color: #bbf7d0;
|
||||
background: #f0fdf4;
|
||||
}
|
||||
|
||||
.project-overview-card.tone-warning {
|
||||
border-color: #fde68a;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.project-overview-card.tone-danger {
|
||||
border-color: #fecaca;
|
||||
background: #fef2f2;
|
||||
}
|
||||
|
||||
.project-overview-card.tone-muted {
|
||||
border-color: #e2e8f0;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.project-filter-bar {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(260px, 1.4fr) 150px 150px max-content;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.project-search-input {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.env-config {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
padding: 14px 46px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.env-config-card {
|
||||
padding: 14px;
|
||||
border: 1px solid #e1e8f2;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.project-diagnostic-card {
|
||||
grid-column: 1 / -1;
|
||||
padding: 14px;
|
||||
border: 1px solid #d7e5ff;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.env-config-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
dl {
|
||||
display: grid;
|
||||
grid-template-columns: 100px minmax(0, 1fr);
|
||||
gap: 8px 12px;
|
||||
margin: 0;
|
||||
color: #596578;
|
||||
.project-name {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
font-size: 13px;
|
||||
font-weight: 550;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
dt {
|
||||
color: #7b8798;
|
||||
.project-name:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
dd {
|
||||
.project-details {
|
||||
display: grid;
|
||||
grid-template-columns: 84px minmax(0, 1fr);
|
||||
gap: 15px;
|
||||
margin: 5px 0 25px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.project-details dt {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.project-details dd {
|
||||
margin: 0;
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.status-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
.environment-config {
|
||||
padding: 22px 0;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.readiness-cell {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
.environment-config h2 {
|
||||
margin: 0 0 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.readiness-cell small {
|
||||
color: #64748b;
|
||||
.diagnostics {
|
||||
margin-top: 12px;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.project-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
.diagnostics summary {
|
||||
cursor: pointer;
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.diagnostic-message {
|
||||
margin-left: 8px;
|
||||
color: #596578;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.latest-release {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.latest-release-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.latest-release small {
|
||||
color: #7b8798;
|
||||
}
|
||||
|
||||
.webhook-hook-list {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.webhook-hook-item {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.webhook-hook-item small {
|
||||
color: #7b8798;
|
||||
}
|
||||
|
||||
.run-link {
|
||||
color: #2563eb;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.run-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
@media (max-width: 1080px) {
|
||||
.project-overview-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.project-filter-bar {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.project-overview-grid,
|
||||
.project-filter-bar {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.env-config {
|
||||
grid-template-columns: 1fr;
|
||||
padding: 12px;
|
||||
@media (max-width: 520px) {
|
||||
.project-search {
|
||||
width: 170px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+474
-1143
File diff suppressed because it is too large
Load Diff
+407
-790
File diff suppressed because it is too large
Load Diff
+110
-275
@@ -5,8 +5,8 @@
|
||||
import { Connection, Refresh, Search } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import AuditJsonCell from '../components/AuditJsonCell.vue'
|
||||
import StatusPill from '../components/StatusPill.vue'
|
||||
import { devopsApi } from '../services/devopsApi'
|
||||
import { usePlatformStore } from '../stores/platform'
|
||||
import { useSessionStore } from '../stores/session'
|
||||
@@ -20,6 +20,29 @@ import type {
|
||||
} from '../types/devops'
|
||||
|
||||
const platform = usePlatformStore()
|
||||
const route = useRoute()
|
||||
const tabs = [
|
||||
{ key: 'integrations', label: '集成接入' },
|
||||
{ key: 'notifications', label: '通知' },
|
||||
{ key: 'audit', label: '审计' },
|
||||
{ key: 'agent', label: '运维助手' },
|
||||
]
|
||||
const activeTab = computed(() =>
|
||||
tabs.some((tab) => tab.key === route.query.tab) ? String(route.query.tab) : 'integrations',
|
||||
)
|
||||
const adminLoading = ref(false)
|
||||
const adminError = ref('')
|
||||
async function refreshAdmin() {
|
||||
adminLoading.value = true
|
||||
adminError.value = ''
|
||||
try {
|
||||
await platform.loadAdminData()
|
||||
} catch (error) {
|
||||
adminError.value = error instanceof Error ? error.message : '管理数据读取失败'
|
||||
} finally {
|
||||
adminLoading.value = false
|
||||
}
|
||||
}
|
||||
const session = useSessionStore()
|
||||
const agentConfigLoading = ref(false)
|
||||
const agentConfigTesting = ref(false)
|
||||
@@ -70,45 +93,12 @@ const outboxStatusOptions: Array<{ label: string; value: NotificationOutboxStatu
|
||||
onMounted(() => {
|
||||
if (canManageSystemConfig.value) {
|
||||
void loadAgentConfig()
|
||||
void refreshAdmin()
|
||||
}
|
||||
})
|
||||
|
||||
const canManageSystemConfig = computed(() => session.role === 'super_admin')
|
||||
|
||||
const operationOverview = computed(() => {
|
||||
const integrations = platform.integrationConfig.integrations
|
||||
const configured = integrations.filter((item) => item.status === 'configured').length
|
||||
const missing = integrations.filter((item) => item.status === 'missing').length
|
||||
const partial = integrations.filter((item) => item.status === 'partial').length
|
||||
const outboxAttention = platform.notificationOutbox.filter(
|
||||
(item) => item.status === 'pending' || item.status === 'failed' || item.status === 'dead',
|
||||
).length
|
||||
|
||||
return [
|
||||
{ key: 'integrations', label: '集成项', value: integrations.length, tone: 'neutral' },
|
||||
{ key: 'configured', label: '已配置', value: configured, tone: 'success' },
|
||||
{
|
||||
key: 'attention',
|
||||
label: '配置关注',
|
||||
value: missing + partial,
|
||||
tone: missing + partial > 0 ? 'warning' : 'neutral',
|
||||
},
|
||||
{
|
||||
key: 'agent',
|
||||
label: 'Agent 密钥',
|
||||
value: agentConfig.value?.hasKey ? '已保存' : '未配置',
|
||||
tone: agentConfig.value?.hasKey ? 'success' : 'warning',
|
||||
},
|
||||
{
|
||||
key: 'outbox',
|
||||
label: '通知待排查',
|
||||
value: outboxAttention,
|
||||
tone: outboxAttention > 0 ? 'danger' : 'neutral',
|
||||
},
|
||||
{ key: 'audit', label: '审计记录', value: platform.auditLogs.length, tone: 'active' },
|
||||
]
|
||||
})
|
||||
|
||||
const agentConfigDisabledReason = computed(() => {
|
||||
if (!canManageSystemConfig.value) {
|
||||
return '仅超级管理员可维护 Agent 模型配置'
|
||||
@@ -200,9 +190,7 @@ function configStatusLabel(status: IntegrationConfigState): string {
|
||||
return configStatusMeta[status]?.label ?? '未配置'
|
||||
}
|
||||
|
||||
function configStatusType(
|
||||
status: IntegrationConfigState,
|
||||
): 'success' | 'warning' | 'danger' {
|
||||
function configStatusType(status: IntegrationConfigState): 'success' | 'warning' | 'danger' {
|
||||
return configStatusMeta[status]?.type ?? 'danger'
|
||||
}
|
||||
|
||||
@@ -231,9 +219,7 @@ function auditActor(record: AuditLogEntry): string {
|
||||
}
|
||||
|
||||
function auditResource(record: AuditLogEntry): string {
|
||||
return record.resourceId
|
||||
? `${record.resourceType} / ${record.resourceId}`
|
||||
: record.resourceType
|
||||
return record.resourceId ? `${record.resourceType} / ${record.resourceId}` : record.resourceType
|
||||
}
|
||||
|
||||
function hasAuditRecord(value?: Record<string, unknown>): value is Record<string, unknown> {
|
||||
@@ -405,7 +391,7 @@ async function saveAgentConfig() {
|
||||
applyAgentConfig(config)
|
||||
agentConfigForm.key = ''
|
||||
ElMessage.success('Agent 配置已保存')
|
||||
await platform.loadAll()
|
||||
await platform.loadAdminData()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : 'Agent 配置保存失败')
|
||||
} finally {
|
||||
@@ -508,38 +494,40 @@ function resetAuditFilters() {
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>系统配置</h1>
|
||||
<p>展示后端集成配置状态、API 契约来源、流程映射、Agent 边界和通知维护状态。</p>
|
||||
<p>按需查看接入状态、通知投递和操作审计。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="settings-overview-grid">
|
||||
<article
|
||||
v-for="item in operationOverview"
|
||||
:key="item.key"
|
||||
class="settings-overview-card"
|
||||
:class="`tone-${item.tone}`"
|
||||
<nav class="settings-tabs" aria-label="设置分类">
|
||||
<RouterLink
|
||||
v-for="tab in tabs"
|
||||
:key="tab.key"
|
||||
:to="{ name: 'settings', query: { tab: tab.key } }"
|
||||
:aria-current="activeTab === tab.key ? 'page' : undefined"
|
||||
>{{ tab.label }}</RouterLink
|
||||
>
|
||||
<span>{{ item.label }}</span>
|
||||
<strong>{{ item.value }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
</nav>
|
||||
<ElAlert v-if="adminError" title="管理数据读取失败" type="error" :closable="false"
|
||||
>{{ adminError }}<ElButton text @click="refreshAdmin">重试</ElButton></ElAlert
|
||||
>
|
||||
<div v-if="adminLoading" class="field-hint" role="status">正在更新设置…</div>
|
||||
<section v-if="activeTab === 'integrations'" class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>后端集成配置状态</h2>
|
||||
<h2>集成接入</h2>
|
||||
<span>检查时间:{{ formatCheckedAt(platform.integrationConfig.checkedAt) }}</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="secret-boundary">
|
||||
这里只展示环境变量名和配置状态;Jenkins token、Gitea token、通知 webhook、LLM key、数据库连接串不会进入浏览器。
|
||||
这里只展示环境变量名和配置状态;Jenkins token、Gitea token、通知 webhook、LLM
|
||||
key、数据库连接串不会进入浏览器。
|
||||
</div>
|
||||
<div class="config-list">
|
||||
<article
|
||||
<details
|
||||
v-for="item in platform.integrationConfig.integrations"
|
||||
:key="item.key"
|
||||
class="config-row"
|
||||
>
|
||||
<div class="config-row-main">
|
||||
<summary class="config-row-main">
|
||||
<div>
|
||||
<h3>{{ item.name }}</h3>
|
||||
<p v-if="item.note">{{ item.note }}</p>
|
||||
@@ -547,14 +535,10 @@ function resetAuditFilters() {
|
||||
<ElTag :type="configStatusType(item.status)" effect="light" round>
|
||||
{{ configStatusLabel(item.status) }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</summary>
|
||||
|
||||
<div class="variable-grid">
|
||||
<div
|
||||
v-for="group in variableGroups(item)"
|
||||
:key="group.key"
|
||||
class="variable-group"
|
||||
>
|
||||
<div v-for="group in variableGroups(item)" :key="group.key" class="variable-group">
|
||||
<strong>{{ group.label }}</strong>
|
||||
<div class="variable-tags">
|
||||
<ElTooltip
|
||||
@@ -592,31 +576,12 @@ function resetAuditFilters() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="section-grid">
|
||||
<section v-for="item in platform.settings" :key="item.key" class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>{{ item.name }}</h2>
|
||||
<StatusPill :state="item.status" />
|
||||
</div>
|
||||
<div class="panel-body setting-card">
|
||||
<dl>
|
||||
<dt>责任方</dt>
|
||||
<dd>{{ item.owner }}</dd>
|
||||
<dt>契约</dt>
|
||||
<dd>{{ item.contract }}</dd>
|
||||
<dt>边界</dt>
|
||||
<dd>{{ item.boundary }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section v-if="canManageSystemConfig" class="panel">
|
||||
<section v-if="activeTab === 'agent' && canManageSystemConfig" class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>Agent 模型配置</h2>
|
||||
<span>{{ agentConfig?.hasKey ? '已保存密钥' : '未保存密钥' }}</span>
|
||||
@@ -626,6 +591,7 @@ function resetAuditFilters() {
|
||||
<ElForm label-position="top">
|
||||
<ElFormItem label="Base URL">
|
||||
<ElInput
|
||||
aria-label="模型服务地址"
|
||||
v-model="agentConfigForm.baseURL"
|
||||
placeholder="https://api.example.com/v1"
|
||||
autocomplete="off"
|
||||
@@ -633,6 +599,7 @@ function resetAuditFilters() {
|
||||
</ElFormItem>
|
||||
<ElFormItem label="模型">
|
||||
<ElInput
|
||||
aria-label="模型名称"
|
||||
v-model="agentConfigForm.model"
|
||||
placeholder="gpt-4.1"
|
||||
autocomplete="off"
|
||||
@@ -640,6 +607,7 @@ function resetAuditFilters() {
|
||||
</ElFormItem>
|
||||
<ElFormItem label="API Key">
|
||||
<ElInput
|
||||
aria-label="模型密钥"
|
||||
v-model="agentConfigForm.key"
|
||||
type="password"
|
||||
show-password
|
||||
@@ -665,11 +633,12 @@ function resetAuditFilters() {
|
||||
测试连接
|
||||
</ElButton>
|
||||
</div>
|
||||
<div
|
||||
class="agent-config-check"
|
||||
:class="{ ready: canSaveAgentConfig }"
|
||||
>
|
||||
{{ canSaveAgentConfig ? '保存前检查通过,API Key 只会提交给后端配置接口。' : agentConfigDisabledReason }}
|
||||
<div class="agent-config-check" :class="{ ready: canSaveAgentConfig }">
|
||||
{{
|
||||
canSaveAgentConfig
|
||||
? '保存前检查通过,API Key 只会提交给后端配置接口。'
|
||||
: agentConfigDisabledReason
|
||||
}}
|
||||
</div>
|
||||
</ElForm>
|
||||
</div>
|
||||
@@ -695,29 +664,23 @@ function resetAuditFilters() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-else class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>Agent 模型配置</h2>
|
||||
<span>仅超级管理员可维护</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="secret-boundary">
|
||||
当前账号只能查看系统配置边界;模型 key、baseURL 和 model 的保存、测试均需要后端超级管理员鉴权。
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="session.role === 'super_admin'" class="panel">
|
||||
<section v-if="activeTab === 'notifications' && session.role === 'super_admin'" class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>通知 outbox</h2>
|
||||
<span>{{ filteredNotificationOutbox.length }} / {{ platform.notificationOutbox.length }} 条</span>
|
||||
<ElButton :icon="Refresh" size="small" @click="refreshNotificationOutbox">
|
||||
刷新
|
||||
</ElButton>
|
||||
<span
|
||||
>{{ filteredNotificationOutbox.length }} /
|
||||
{{ platform.notificationOutbox.length }} 条</span
|
||||
>
|
||||
<ElButton :icon="Refresh" size="small" @click="refreshNotificationOutbox"> 刷新 </ElButton>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="settings-filter-bar">
|
||||
<ElSelect v-model="outboxStatusFilter" clearable placeholder="投递状态">
|
||||
<ElSelect
|
||||
aria-label="筛选通知投递状态"
|
||||
v-model="outboxStatusFilter"
|
||||
clearable
|
||||
placeholder="投递状态"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in outboxStatusOptions"
|
||||
:key="option.value"
|
||||
@@ -726,6 +689,7 @@ function resetAuditFilters() {
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElInput
|
||||
aria-label="搜索通知记录"
|
||||
v-model="outboxKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
@@ -736,7 +700,11 @@ function resetAuditFilters() {
|
||||
重置筛选
|
||||
</ElButton>
|
||||
</div>
|
||||
<ElTable :data="filteredNotificationOutbox" border empty-text="没有符合条件的通知 outbox 记录">
|
||||
<ElTable
|
||||
:data="filteredNotificationOutbox"
|
||||
border
|
||||
empty-text="没有符合条件的通知 outbox 记录"
|
||||
>
|
||||
<ElTableColumn label="创建时间" min-width="150">
|
||||
<template #default="{ row }">
|
||||
{{ formatCheckedAt(row.createdAt) }}
|
||||
@@ -794,23 +762,31 @@ function resetAuditFilters() {
|
||||
</ElTable>
|
||||
<ElEmpty
|
||||
v-if="filteredNotificationOutbox.length === 0"
|
||||
:description="platform.notificationOutbox.length ? '暂无符合条件的通知 outbox 记录' : '暂无通知 outbox 记录'"
|
||||
:description="
|
||||
platform.notificationOutbox.length
|
||||
? '暂无符合条件的通知 outbox 记录'
|
||||
: '暂无通知 outbox 记录'
|
||||
"
|
||||
:image-size="72"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<section v-if="activeTab === 'audit'" class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>最近运维审计</h2>
|
||||
<h2>操作审计</h2>
|
||||
<span>{{ filteredAuditLogs.length }} / {{ platform.auditLogs.length }} 条</span>
|
||||
<ElButton :icon="Refresh" size="small" @click="platform.loadAuditLogs()">
|
||||
刷新
|
||||
</ElButton>
|
||||
<ElButton :icon="Refresh" size="small" @click="platform.loadAuditLogs()"> 刷新 </ElButton>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="settings-filter-bar">
|
||||
<ElSelect v-model="auditResourceFilter" clearable filterable placeholder="资源类型">
|
||||
<ElSelect
|
||||
aria-label="筛选审计资源"
|
||||
v-model="auditResourceFilter"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="资源类型"
|
||||
>
|
||||
<ElOption
|
||||
v-for="resource in auditResourceOptions"
|
||||
:key="resource"
|
||||
@@ -819,6 +795,7 @@ function resetAuditFilters() {
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElInput
|
||||
aria-label="搜索审计记录"
|
||||
v-model="auditKeyword"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
@@ -859,167 +836,30 @@ function resetAuditFilters() {
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>前端环境变量</h2>
|
||||
<span>第一阶段仅保留 API 地址</span>
|
||||
</div>
|
||||
<div class="panel-body compact-list">
|
||||
<div class="list-row">
|
||||
<span>
|
||||
<strong class="mono">VITE_API_BASE_URL</strong>
|
||||
<small>联调时指向后端网关;未配置时默认 /api。</small>
|
||||
</span>
|
||||
<ElTag type="info" round>后端接口</ElTag>
|
||||
</div>
|
||||
<div class="list-row">
|
||||
<span>
|
||||
<strong>密钥策略</strong>
|
||||
<small>Jenkins token、Gitea token、通知 webhook、LLM key 均不得进入前端。</small>
|
||||
</span>
|
||||
<ElTag type="success" round>前端隔离</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.settings-overview-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
.config-row-main {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.settings-overview-card {
|
||||
min-width: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #d8e2ef;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
.settings-tabs {
|
||||
display: flex;
|
||||
gap: 28px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.settings-overview-card span {
|
||||
display: block;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.settings-overview-card strong {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: #0f172a;
|
||||
font-size: 22px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.settings-overview-card.tone-active {
|
||||
border-color: #bfdbfe;
|
||||
background: #eff6ff;
|
||||
}
|
||||
|
||||
.settings-overview-card.tone-success {
|
||||
border-color: #bbf7d0;
|
||||
background: #f0fdf4;
|
||||
}
|
||||
|
||||
.settings-overview-card.tone-warning {
|
||||
border-color: #fde68a;
|
||||
background: #fffbeb;
|
||||
}
|
||||
|
||||
.settings-overview-card.tone-danger {
|
||||
border-color: #fecaca;
|
||||
background: #fef2f2;
|
||||
}
|
||||
|
||||
.settings-filter-bar {
|
||||
display: grid;
|
||||
grid-template-columns: 180px minmax(260px, 1fr) max-content;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.settings-search-input {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.setting-card dl {
|
||||
display: grid;
|
||||
grid-template-columns: 74px minmax(0, 1fr);
|
||||
gap: 10px 12px;
|
||||
margin: 0;
|
||||
.settings-tabs a {
|
||||
padding: 8px 0 14px;
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
|
||||
.setting-card dt {
|
||||
color: #7b8798;
|
||||
}
|
||||
|
||||
.setting-card dd {
|
||||
margin: 0;
|
||||
color: #172033;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.secret-boundary {
|
||||
margin-bottom: 14px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #dbeafe;
|
||||
border-radius: 8px;
|
||||
background: #eff6ff;
|
||||
color: #25508f;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.agent-config-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(320px, 0.75fr);
|
||||
gap: 18px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.agent-config-form {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.agent-config-summary dl {
|
||||
display: grid;
|
||||
grid-template-columns: 82px minmax(0, 1fr);
|
||||
gap: 10px 12px;
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.agent-config-summary dt {
|
||||
color: #7b8798;
|
||||
}
|
||||
|
||||
.agent-config-summary dd {
|
||||
margin: 0;
|
||||
min-width: 0;
|
||||
color: #172033;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.agent-config-check {
|
||||
margin-top: 12px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #fde68a;
|
||||
border-radius: 8px;
|
||||
background: #fffbeb;
|
||||
color: #8a5a00;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.agent-config-check.ready {
|
||||
border-color: #bbf7d0;
|
||||
background: #f0fdf4;
|
||||
color: #166534;
|
||||
.settings-tabs a[aria-current='page'] {
|
||||
color: var(--accent);
|
||||
border-color: var(--accent);
|
||||
font-weight: 550;
|
||||
}
|
||||
|
||||
.config-list {
|
||||
@@ -1133,10 +973,6 @@ function resetAuditFilters() {
|
||||
}
|
||||
|
||||
@media (max-width: 1080px) {
|
||||
.settings-overview-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.settings-filter-bar {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
@@ -1151,7 +987,6 @@ function resetAuditFilters() {
|
||||
}
|
||||
|
||||
@media (max-width: 680px) {
|
||||
.settings-overview-grid,
|
||||
.settings-filter-bar {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
import { after, beforeEach, test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createServer } from 'vite'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
|
||||
// Vite 使用与应用相同的模块解析,不引入测试框架或浏览器运行时降级。
|
||||
const server = await createServer({ server: { middlewareMode: true }, appType: 'custom' })
|
||||
const { usePlatformStore } = await server.ssrLoadModule('/src/stores/platform.ts')
|
||||
const { useAssistantStore } = await server.ssrLoadModule('/src/stores/assistant.ts')
|
||||
const { useSessionStore } = await server.ssrLoadModule('/src/stores/session.ts')
|
||||
const { http } = await server.ssrLoadModule('/src/services/http.ts')
|
||||
const originalGet = http.get
|
||||
const { devopsApi } = await server.ssrLoadModule('/src/services/devopsApi.ts')
|
||||
const { latestRunsByEnvironment, newestRuns, formatTime } =
|
||||
await server.ssrLoadModule('/src/utils/releases.ts')
|
||||
const storage = new Map()
|
||||
globalThis.localStorage = {
|
||||
getItem: (key) => storage.get(key) ?? null,
|
||||
setItem: (key, value) => storage.set(key, value),
|
||||
removeItem: (key) => storage.delete(key),
|
||||
}
|
||||
const original = { ...devopsApi }
|
||||
after(async () => {
|
||||
Object.assign(devopsApi, original)
|
||||
await server.close()
|
||||
})
|
||||
beforeEach(() => {
|
||||
Object.assign(devopsApi, original)
|
||||
http.get = originalGet
|
||||
setActivePinia(createPinia())
|
||||
})
|
||||
const run = (id, date, status = 'success', environment = 'test') => ({
|
||||
id,
|
||||
version: 1,
|
||||
projectKey: 'project-a',
|
||||
projectName: '项目 A',
|
||||
environment,
|
||||
startedAt: date,
|
||||
status,
|
||||
ref: 'develop',
|
||||
steps: [],
|
||||
})
|
||||
const project = { key: 'project-a', environments: [{ name: 'test' }, { name: 'production' }] }
|
||||
const summary = (runs = []) => ({
|
||||
projects: [project],
|
||||
runs,
|
||||
integrations: [],
|
||||
agentCards: [],
|
||||
settings: [],
|
||||
integrationConfig: { checkedAt: '', integrations: [] },
|
||||
})
|
||||
const deferred = () => {
|
||||
let resolve
|
||||
const promise = new Promise((done) => {
|
||||
resolve = done
|
||||
})
|
||||
return { promise, resolve }
|
||||
}
|
||||
|
||||
test('最近发布按时间与环境聚合,历史失败恢复后不继续报警', () => {
|
||||
const records = [
|
||||
run('old', '2026-10-25', 'failed'),
|
||||
run('prod', '2026-10-26', 'failed', 'production'),
|
||||
run('new', '2026-10-27'),
|
||||
]
|
||||
const latest = latestRunsByEnvironment(records)
|
||||
assert.equal(latest.get('project-a:test').id, 'new')
|
||||
assert.equal(latest.get('project-a:production').id, 'prod')
|
||||
assert.deepEqual(
|
||||
[...latest.values()].filter((item) => item.status === 'failed').map((item) => item.id),
|
||||
['prod'],
|
||||
)
|
||||
assert.equal(records[0].id, 'old')
|
||||
assert.equal(newestRuns(records)[0].id, 'new')
|
||||
assert.equal(formatTime('invalid'), '—')
|
||||
})
|
||||
test('首页只加载核心数据,并合并并发刷新', async () => {
|
||||
const store = usePlatformStore()
|
||||
const pending = deferred()
|
||||
let calls = 0
|
||||
devopsApi.getDashboard = () => {
|
||||
calls += 1
|
||||
return pending.promise
|
||||
}
|
||||
devopsApi.getAuditLogs = () => {
|
||||
throw new Error('首页不应读取审计')
|
||||
}
|
||||
devopsApi.getNotificationOutbox = () => {
|
||||
throw new Error('首页不应读取通知')
|
||||
}
|
||||
const first = store.loadAll()
|
||||
const second = store.loadAll()
|
||||
assert.equal(calls, 1)
|
||||
pending.resolve(summary([run('latest', '2026-10-27')]))
|
||||
await Promise.all([first, second])
|
||||
assert.equal(store.loading, false)
|
||||
assert.equal(store.projects[0].environments[0].lastRunId, 'latest')
|
||||
assert.ok(store.lastLoadedAt)
|
||||
})
|
||||
test('请求失败保留上次数据与真实错误,重试成功后恢复', async () => {
|
||||
const store = usePlatformStore()
|
||||
devopsApi.getDashboard = async () => summary([run('old', '2026-10-26')])
|
||||
await store.loadAll()
|
||||
const loadedAt = store.lastLoadedAt
|
||||
devopsApi.getDashboard = async () => {
|
||||
throw new Error('API unavailable')
|
||||
}
|
||||
await assert.rejects(store.loadAll(), /API unavailable/)
|
||||
assert.equal(store.runs[0].id, 'old')
|
||||
assert.equal(store.loadError, 'API unavailable')
|
||||
assert.equal(store.lastLoadedAt, loadedAt)
|
||||
assert.equal(store.loading, false)
|
||||
devopsApi.getDashboard = async () => summary([])
|
||||
await store.loadAll()
|
||||
assert.equal(store.loadError, '')
|
||||
})
|
||||
test('退出后忽略未完成的首页请求,避免跨账号残留', async () => {
|
||||
const store = usePlatformStore()
|
||||
const pending = deferred()
|
||||
devopsApi.getDashboard = () => pending.promise
|
||||
const request = store.loadAll()
|
||||
store.reset()
|
||||
pending.resolve(summary([run('private', '2026-10-27')]))
|
||||
await request
|
||||
assert.deepEqual(store.runs, [])
|
||||
assert.deepEqual(store.projects, [])
|
||||
assert.equal(store.lastLoadedAt, '')
|
||||
})
|
||||
test('切换账号时延迟的版本请求不能写回新会话', async () => {
|
||||
const store = usePlatformStore()
|
||||
const pending = deferred()
|
||||
devopsApi.getProjectRefs = () => pending.promise
|
||||
const request = store.loadProjectRefs('project-a')
|
||||
store.reset()
|
||||
pending.resolve({ source: 'gitea', branches: [{ name: 'private' }], tags: [] })
|
||||
await request
|
||||
assert.deepEqual(store.projectRefs, {})
|
||||
})
|
||||
test('同步较早记录不会覆盖同环境的最新发布摘要', async () => {
|
||||
const store = usePlatformStore()
|
||||
devopsApi.getDashboard = async () =>
|
||||
summary([run('new', '2026-10-27'), run('old', '2026-10-25', 'running')])
|
||||
await store.loadAll()
|
||||
devopsApi.syncJenkinsRun = async () => run('old', '2026-10-25', 'failed')
|
||||
await store.syncJenkinsRun(store.runs[1])
|
||||
assert.equal(store.runs[0].id, 'new')
|
||||
assert.equal(store.projects[0].environments[0].status, 'success')
|
||||
})
|
||||
test('普通成员不能触发管理数据读取', async () => {
|
||||
const session = useSessionStore()
|
||||
session.role = 'member'
|
||||
devopsApi.getIntegrationConfigStatus = () => {
|
||||
throw new Error('不应读取')
|
||||
}
|
||||
await usePlatformStore().loadAdminData()
|
||||
})
|
||||
|
||||
test('真实 dashboard 适配器默认只请求三个核心接口', async () => {
|
||||
const paths = []
|
||||
http.get = async (path) => {
|
||||
paths.push(path)
|
||||
return {
|
||||
data: path === '/health' ? { status: 'ok', checkedAt: '2026-10-27', dependencies: {} } : [],
|
||||
}
|
||||
}
|
||||
await devopsApi.getDashboard()
|
||||
assert.deepEqual(paths.sort(), ['/deploy-runs', '/health', '/projects'])
|
||||
})
|
||||
test('自动刷新迟到的旧版本不能回退刚完成的取消操作', async () => {
|
||||
const store = usePlatformStore()
|
||||
devopsApi.getDashboard = async () => summary([run('active', '2026-10-27', 'running')])
|
||||
await store.loadAll()
|
||||
const pending = deferred()
|
||||
devopsApi.getRuns = () => pending.promise
|
||||
const refreshing = store.refreshRuns()
|
||||
devopsApi.cancelDeployRun = async () => ({
|
||||
...run('active', '2026-10-27', 'canceled'),
|
||||
version: 2,
|
||||
})
|
||||
await store.cancelDeployRun(store.runs[0])
|
||||
pending.resolve([run('active', '2026-10-27', 'running')])
|
||||
await refreshing
|
||||
assert.equal(store.runs[0].status, 'canceled')
|
||||
assert.equal(store.runs[0].version, 2)
|
||||
})
|
||||
|
||||
test('刷新中的旧列表不能移除刚创建的发布单', async () => {
|
||||
const store = usePlatformStore()
|
||||
devopsApi.getDashboard = async () => summary([run('old', '2026-10-26')])
|
||||
await store.loadAll()
|
||||
const pending = deferred()
|
||||
devopsApi.getRuns = () => pending.promise
|
||||
const refreshing = store.refreshRuns()
|
||||
devopsApi.createDeployRun = async () => run('new', '2026-10-27', 'queued')
|
||||
await store.createDeployRun({ projectKey: 'project-a', environment: 'test', ref: 'develop' })
|
||||
pending.resolve([run('old', '2026-10-26')])
|
||||
await refreshing
|
||||
assert.equal(store.runs[0].id, 'new')
|
||||
assert.equal(store.projects[0].environments[0].lastRunId, 'new')
|
||||
})
|
||||
|
||||
test('助手只保留有界短上下文,重复点击不会创建并发请求', async () => {
|
||||
const assistant = useAssistantStore()
|
||||
const pending = deferred()
|
||||
let calls = 0
|
||||
devopsApi.askAgent = () => { calls += 1; return pending.promise }
|
||||
const first = assistant.ask('最近部署怎么样')
|
||||
await assistant.ask('重复点击')
|
||||
assert.equal(calls, 1)
|
||||
pending.resolve({ id: 'answer-1', status: 'success', resultMarkdown: '已查询', sources: [] })
|
||||
await first
|
||||
let largestHistory = 0
|
||||
devopsApi.askAgent = async payload => {
|
||||
largestHistory = Math.max(largestHistory, JSON.stringify(payload.history).length)
|
||||
assert.ok(payload.history.length <= 4)
|
||||
assert.ok(payload.history.every(item => item.content.length <= 1400))
|
||||
return { id: 'answer-next', status: 'success', resultMarkdown: 'a'.repeat(8000), sources: [] }
|
||||
}
|
||||
for (let i = 0; i < 8; i += 1) await assistant.ask('追问')
|
||||
assert.ok(assistant.messages.length <= 12)
|
||||
assert.ok(largestHistory < 6100)
|
||||
})
|
||||
test('退出时清空助手,迟到的回答不能回填新会话', async () => {
|
||||
const assistant = useAssistantStore()
|
||||
const pending = deferred()
|
||||
devopsApi.askAgent = () => pending.promise
|
||||
const asking = assistant.ask('私有项目情况')
|
||||
assistant.reset()
|
||||
pending.resolve({ id: 'old-answer', status: 'success', resultMarkdown: '上一个账号的数据' })
|
||||
await asking
|
||||
assert.deepEqual(assistant.messages, [])
|
||||
assert.equal(assistant.pending, false)
|
||||
assert.equal(assistant.isOpen, false)
|
||||
})
|
||||
Reference in New Issue
Block a user