2024-10-10 14:28:46 +08:00
|
|
|
<template>
|
2024-10-25 16:51:36 +08:00
|
|
|
<div class="cert-domains-getter">
|
|
|
|
|
<div>
|
|
|
|
|
<a-tag v-for="item of modelValue" :key="item" type="success" class="m-3">{{ item }}</a-tag>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="helper">{{ errorRef }}</div>
|
|
|
|
|
</div>
|
2024-10-10 14:28:46 +08:00
|
|
|
</template>
|
|
|
|
|
|
2024-09-30 18:00:51 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { inject, ref, watch } from "vue";
|
|
|
|
|
|
2024-10-07 03:21:16 +08:00
|
|
|
defineOptions({
|
2025-04-13 00:10:23 +08:00
|
|
|
name: "CertDomainsGetter",
|
2024-10-07 03:21:16 +08:00
|
|
|
});
|
|
|
|
|
|
2024-09-30 18:00:51 +08:00
|
|
|
const props = defineProps<{
|
|
|
|
|
inputKey?: string;
|
|
|
|
|
modelValue?: string[];
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
"update:modelValue": any;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const pipeline: any = inject("pipeline");
|
|
|
|
|
|
|
|
|
|
function findStepFromPipeline(targetStepId: string) {
|
|
|
|
|
for (const stage of pipeline.value.stages) {
|
|
|
|
|
for (const task of stage.tasks) {
|
|
|
|
|
for (const step of task.steps) {
|
|
|
|
|
if (step.id === targetStepId) {
|
|
|
|
|
return step;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const errorRef = ref("");
|
2024-10-25 17:47:39 +08:00
|
|
|
function getStepIdFromInputKey(inputKey: string) {
|
2024-09-30 18:00:51 +08:00
|
|
|
if (!inputKey) {
|
|
|
|
|
errorRef.value = "请先选择域名证书";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-25 17:47:39 +08:00
|
|
|
return inputKey.split(".")[1];
|
|
|
|
|
}
|
|
|
|
|
function getDomainFromPipeline(inputKey: string) {
|
|
|
|
|
let targetStepId = getStepIdFromInputKey(inputKey);
|
2024-10-25 16:51:36 +08:00
|
|
|
let certStep = findStepFromPipeline(targetStepId);
|
2024-09-30 18:00:51 +08:00
|
|
|
if (!certStep) {
|
|
|
|
|
errorRef.value = "找不到目标步骤,请先选择域名证书";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-04-13 00:10:23 +08:00
|
|
|
|
2025-07-09 14:34:24 +08:00
|
|
|
const firstLevelValue = certStep.input.cert;
|
|
|
|
|
if (firstLevelValue && typeof firstLevelValue === "string" && firstLevelValue.indexOf(".") > 0) {
|
|
|
|
|
targetStepId = getStepIdFromInputKey(firstLevelValue);
|
2024-10-25 17:47:39 +08:00
|
|
|
certStep = findStepFromPipeline(targetStepId);
|
2024-10-25 16:51:36 +08:00
|
|
|
if (!certStep) {
|
|
|
|
|
errorRef.value = "找不到目标步骤,请先选择域名证书";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 18:00:51 +08:00
|
|
|
const domain = certStep.input["domains"];
|
|
|
|
|
emit("update:modelValue", domain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => {
|
|
|
|
|
return props.inputKey;
|
|
|
|
|
},
|
|
|
|
|
(inputKey: string) => {
|
|
|
|
|
getDomainFromPipeline(inputKey);
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-04-13 00:10:23 +08:00
|
|
|
immediate: true,
|
2024-09-30 18:00:51 +08:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less"></style>
|