<script setup lang="ts">
/**
* PipelineConfigCardï¼šæµæ°´çº¿é…置区å—(CARD-DEP-01,J-DEP-07ï¼›pipeline 页ç¾åŒºå— A)。
* 纯 UIï¼šåªæ”¶ propsã€åªå‘ create/copy/trigger/edit/remove/retryï¼›Guard 确认ã€å‰ªè´´æ¿ä¸Žè¯·æ±‚都在容器。
* åˆ—è¡¨åˆ—ï¼ˆé‡æŽ’ 7 列):åç§°/分支/编译节点/自动部署/å¯ç”¨/æ›´æ–°æ—¶é—´/æ“ä½œï¼›æ— Idã€Tokenã€Secretã€DeployNodeIdsã€TraceId 列(盘点éšè—清å•)。
* 空æ€ä¸¤åˆ†æ”¯ï¼šæ— 部署集由容器整å¡å…œåº•;这里åªå¤„ç†ã€Œéƒ¨ç½²é›†å˜åœ¨ä½†æ— æµæ°´çº¿ã€â†’ã€Œè¿˜æ²¡æœ‰æµæ°´çº¿ã€+ã€Œåˆ›å»ºæµæ°´çº¿ã€å¼•导(è£å®š #9)。
*/
import { ref } from 'vue';
import Btn from './Btn.vue';
import Card from './Card.vue';
import KIcon from './KIcon.vue';
import Tag from './Tag.vue';
import { H3, TD, TH } from './deployView.styles.ts';
import { fmtPipelineTime } from './pipelineConfig.logic.ts';
import type { PipelineRow } from './pipelineConfig.logic.ts';
const props = defineProps<{
rows: PipelineRow[];
/** åˆ—è¡¨åŠ è½½å¤±è´¥ï¼ˆè¿”å›ž null) */
failed: boolean;
/** 行æ“作进行ä¸çš„ key:copy:{id} / trigger:{id} / del:{id} / save */
busyKey: string;
}>();
const emit = defineEmits<{
create: [];
copy: [row: PipelineRow];
trigger: [row: PipelineRow];
/** 指定分支/æäº¤è§¦å‘。branch/commit ç•™ç©ºè¡¨ç¤ºä½¿ç”¨æµæ°´çº¿åˆ†æ”¯æœ€æ–°æäº¤ */
'trigger-advanced': [row: PipelineRow, params: { branch: string; commit: string }];
edit: [row: PipelineRow];
remove: [row: PipelineRow];
retry: [];
}>();
// 指定分支/æäº¤è§¦å‘(默认路径ä¸å˜ï¼šç›´æŽ¥ç‚¹ã€Œå¯åЍã€= 分支最新)
const advOpen = ref(false);
const advRow = ref<PipelineRow | null>(null);
const advBranch = ref('');
const advCommit = ref('');
function openAdvanced(row: PipelineRow): void {
if (!row.enable || props.busyKey) return;
advRow.value = row;
advBranch.value = '';
advCommit.value = '';
advOpen.value = true;
}
function submitAdvanced(): void {
const row = advRow.value;
if (!row) return;
advOpen.value = false;
emit('trigger-advanced', row, { branch: advBranch.value.trim(), commit: advCommit.value.trim() });
}
function busyOf(kind: 'copy' | 'trigger' | 'del', id: number): boolean {
return props.busyKey === `${kind}:${id}`;
}
</script>
<template>
<Card
padding="none"
data-spec="pipeline-config"
>
<div class="px-[18px] pb-2 pt-4">
<div class="flex flex-wrap items-center gap-3">
<h3 :class="H3">
æµæ°´çº¿é…ç½®
<span class="text-[11.5px] font-normal text-[var(--el-text-color-secondary)]">绑定分支与节点,Webhook 或手动触å‘编译部署</span>
</h3>
<span class="flex-1" />
<Btn
size="sm"
variant="primary"
:disabled="!!busyKey"
data-spec="pipeline-config-create"
@click="emit('create')"
>
<template #icon>
<KIcon
name="Plus"
:size="12"
/>
</template>
åˆ›å»ºæµæ°´çº¿
</Btn>
</div>
</div>
<div
v-if="failed"
class="flex items-center gap-3 px-[18px] pb-4 text-[12.5px] text-[var(--el-color-danger)]"
data-spec="pipeline-config-failed"
>
æµæ°´çº¿é…ç½®åŠ è½½å¤±è´¥
<Btn
size="sm"
data-spec="pipeline-config-retry"
@click="emit('retry')"
>
é‡è¯•
</Btn>
</div>
<div
v-else-if="!rows.length"
class="flex flex-wrap items-center gap-3 px-[18px] pb-4 text-[12.5px] text-[var(--el-text-color-secondary)]"
data-spec="pipeline-config-empty"
>
è¿˜æ²¡æœ‰æµæ°´çº¿
<Btn
size="sm"
variant="default"
:disabled="!!busyKey"
data-spec="pipeline-config-empty-create"
@click="emit('create')"
>
åˆ›å»ºæµæ°´çº¿
</Btn>
</div>
<table
v-else
class="w-full border-collapse"
>
<thead>
<tr>
<th :class="TH">
åç§°
</th>
<th :class="TH">
分支
</th>
<th :class="TH">
编译节点
</th>
<th :class="TH">
自动部署
</th>
<th :class="TH">
å¯ç”¨
</th>
<th :class="TH">
æ›´æ–°æ—¶é—´
</th>
<th :class="[TH, 'text-right']">
æ“作
</th>
</tr>
</thead>
<tbody>
<tr
v-for="r in rows"
:key="r.id"
data-spec="pipeline-config-row"
class="group"
>
<td :class="TD">
<b class="font-medium text-[var(--el-text-color-primary)]">{{ r.name }}</b>
</td>
<td
:class="[TD, 'font-mono text-[11.5px] text-[var(--el-text-color-secondary)]']"
>
{{ r.branch || '—' }}
</td>
<td
:class="[TD, 'text-[var(--el-text-color-secondary)]']"
>
{{ r.buildNodeId > 0 ? `#${r.buildNodeId}` : '—' }}
</td>
<td :class="TD">
<Tag :tone="r.autoDeploy ? 'ok' : 'default'">
{{ r.autoDeploy ? '自动' : '手动' }}
</Tag>
</td>
<td :class="TD">
<span :class="r.enable ? 'text-[var(--el-color-success)]' : 'text-[var(--el-text-color-placeholder)]'">{{ r.enable ? '是' : 'å¦' }}</span>
</td>
<td
:class="[TD, 'font-mono tabular-nums text-[var(--el-text-color-secondary)]']"
>
{{ fmtPipelineTime(r.updateTime) }}
</td>
<td :class="[TD, 'text-right']">
<span class="inline-flex justify-end gap-1">
<Btn
size="sm"
variant="ghost"
:disabled="!!busyKey"
:title="busyOf('copy', r.id) ? 'å¤åˆ¶ä¸â€¦' : 'å¤åˆ¶ WebHook 触å‘地å€'"
data-spec="pipeline-config-copywebhook"
@click="emit('copy', r)"
>
<template #icon>
<span :class="busyOf('copy', r.id) ? 'inline-flex animate-spin' : 'inline-flex'">
<KIcon
name="Copy"
:size="12"
/>
</span>
</template>
{{ busyOf('copy', r.id) ? 'å¤åˆ¶ä¸â€¦' : 'å¤åˆ¶ WebHook' }}
</Btn>
<Btn
size="sm"
variant="ghost"
:disabled="!r.enable || !!busyKey"
:title="!r.enable ? 'æµæ°´çº¿æœªå¯ç”¨ï¼Œå…ˆç¼–辑打开「å¯ç”¨ã€' : busyOf('trigger', r.id) ? '触å‘ä¸â€¦' : '手动触å‘一次è¿è¡Œï¼ˆä½¿ç”¨å½“å‰åˆ†æ”¯æœ€æ–°æäº¤ï¼‰'"
data-spec="pipeline-config-trigger"
@click="emit('trigger', r)"
>
<template #icon>
<span :class="busyOf('trigger', r.id) ? 'inline-flex animate-spin' : 'inline-flex'">
<KIcon
name="Play"
:size="12"
/>
</span>
</template>
{{ busyOf('trigger', r.id) ? '触å‘ä¸â€¦' : 'å¯åЍ' }}
</Btn>
<Btn
size="sm"
variant="ghost"
:disabled="!r.enable || !!busyKey"
:title="!r.enable ? 'æµæ°´çº¿æœªå¯ç”¨ï¼Œå…ˆç¼–辑打开「å¯ç”¨ã€' : '指定分支或æäº¤è§¦å‘(留空则用分支最新)'"
data-spec="pipeline-config-trigger-advanced"
@click="openAdvanced(r)"
>
指定æäº¤
</Btn>
<Btn
size="sm"
variant="ghost"
:disabled="!!busyKey"
data-spec="pipeline-config-edit"
@click="emit('edit', r)"
>
编辑
</Btn>
<Btn
size="sm"
variant="ghost"
:disabled="!!busyKey"
:title="busyOf('del', r.id) ? 'åˆ é™¤ä¸â€¦' : 'åˆ é™¤è¯¥æµæ°´çº¿é…ç½®'"
data-spec="pipeline-config-remove"
@click="emit('remove', r)"
>
{{ busyOf('del', r.id) ? 'åˆ é™¤ä¸â€¦' : 'åˆ é™¤' }}
</Btn>
</span>
</td>
</tr>
</tbody>
</table>
<el-dialog
v-model="advOpen"
title="指定分支或æäº¤è§¦å‘"
width="420px"
append-to-body
data-spec="pipeline-trigger-advanced-dialog"
>
<div class="flex flex-col gap-3">
<el-input
v-model="advBranch"
size="small"
clearable
placeholder="分支(留空 = æµæ°´çº¿åˆ†æ”¯ï¼‰"
data-spec="pipeline-trigger-branch"
/>
<el-input
v-model="advCommit"
size="small"
clearable
placeholder="æäº¤ SHA(留空 = 分支最新)"
data-spec="pipeline-trigger-commit"
/>
</div>
<template #footer>
<div class="flex justify-end gap-2">
<Btn
size="sm"
@click="advOpen = false"
>
å–æ¶ˆ
</Btn>
<Btn
size="sm"
variant="primary"
data-spec="pipeline-trigger-advanced-confirm"
@click="submitAdvanced"
>
触å‘
</Btn>
</div>
</template>
</el-dialog>
</Card>
</template>
|