|
|
@@ -122,30 +122,40 @@
|
|
|
<ElDialog
|
|
|
v-loading="diaLogLoading"
|
|
|
v-model="showPipelineEditModal"
|
|
|
- :before-close="(done) => {
|
|
|
- jsonValid=true;
|
|
|
- done();
|
|
|
- }"
|
|
|
destroy-on-close
|
|
|
>
|
|
|
<template #title>
|
|
|
<span>编辑流水线配置</span>
|
|
|
- <span class="button-group">
|
|
|
- <ElButton type="text">脚本教程</ElButton>
|
|
|
- </span>
|
|
|
</template>
|
|
|
- <ElInput
|
|
|
- type="textarea"
|
|
|
- :rows="16"
|
|
|
- placeholder="请输入流水线配置"
|
|
|
- @input="lintJson"
|
|
|
- v-model="pipelineConfig">
|
|
|
- ></ElInput>
|
|
|
- <pre v-if="!jsonValid" :innerText="hint"></pre>
|
|
|
+ <ElSteps :active="activeStep">
|
|
|
+ <ElStep
|
|
|
+ v-for="(config, index) in pipelineConfig"
|
|
|
+ :key="index"
|
|
|
+ :title="getStage(config.name).title"
|
|
|
+ :description="getStage(config.name).description"
|
|
|
+ >
|
|
|
+ </ElStep>
|
|
|
+ </ElSteps>
|
|
|
+ <div class="edit-pipeline-form" v-for="(config, index) in pipelineConfig" :key="index" v-show="activeStep === index">
|
|
|
+ <ElForm label-width="160px">
|
|
|
+ <div style="margin: 20px 0 20px 160px;">
|
|
|
+ <ElCheckbox
|
|
|
+ :disabled="!getStage(config.name).skippable"
|
|
|
+ v-model="config.active"
|
|
|
+ >启用该阶段</ElCheckbox>
|
|
|
+ </div>
|
|
|
+ <ElFormItem v-for="(val, key) in config.configs" :key="key" :label="key">
|
|
|
+ <ElInput
|
|
|
+ :disabled="!getStage(config.name).configs.find((config) => config.name === key).editable"
|
|
|
+ v-model="config.configs[key]"
|
|
|
+ ></ElInput>
|
|
|
+ </ElFormItem>
|
|
|
+ </ElForm>
|
|
|
+ </div>
|
|
|
<template #footer>
|
|
|
- <span class="dialog-footer">
|
|
|
- <el-button type="primary" @click="handlePipelineUpdateConfirm" :disabled="!jsonValid">确 定</el-button>
|
|
|
- </span>
|
|
|
+ <ElButton :disabled="activeStep == 0" @click="() => activeStep -= 1">上一步</ElButton>
|
|
|
+ <ElButton :disabled="isLastStep" @click="() => activeStep += 1">下一步</ElButton>
|
|
|
+ <ElButton type="primary" :disabled="!isLastStep" @click="handlePipelineUpdateConfirm">确定</ElButton>
|
|
|
</template>
|
|
|
</ElDialog>
|
|
|
<ElDialog
|
|
|
@@ -250,10 +260,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import jsonlint from '@/utils/jsonlint';
|
|
|
-
|
|
|
import { PipelineAPI } from '@/api';
|
|
|
-import debounce from '@/utils/debounce';
|
|
|
|
|
|
import { formatter } from '@/utils/time';
|
|
|
|
|
|
@@ -280,13 +287,34 @@ export default {
|
|
|
name: '',
|
|
|
template: '',
|
|
|
},
|
|
|
+ stages: [],
|
|
|
+ activeStep: 0,
|
|
|
};
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ isLastStep() {
|
|
|
+ return this.activeStep === this.stages.length - 1;
|
|
|
+ },
|
|
|
+ stageConfigsBase() {
|
|
|
+ return this.stages.map((stage) => ({
|
|
|
+ name: stage.name,
|
|
|
+ active: true,
|
|
|
+ configs: stage.configs.map(({ name, value, editable }) => ({
|
|
|
+ [name]: value,
|
|
|
+ editable,
|
|
|
+ })).reduce((prev, curr) => Object.assign(prev, curr), {}),
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ stageConfigs() {
|
|
|
+ return this.stageConfigsBase;
|
|
|
+ },
|
|
|
+ },
|
|
|
async mounted() {
|
|
|
this.loading = true;
|
|
|
this.pipelines = await PipelineAPI.getPipelinesByProjectId(this.$store.state.workspace.currentProjectId);
|
|
|
this.productions = await PipelineAPI.getDeploymentsByProjectId(this.$store.state.workspace.currentProjectId);
|
|
|
this.templates = await PipelineAPI.getPipelineTemplates();
|
|
|
+ this.stages = await PipelineAPI.getStages();
|
|
|
this.loading = false;
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -328,10 +356,11 @@ export default {
|
|
|
this.showPipelineEditModal = true;
|
|
|
this.dialogLoading = true;
|
|
|
this.editingPipelineId = id;
|
|
|
- this.pipelineConfig = await PipelineAPI.getPipeline({
|
|
|
+ const config = (await PipelineAPI.getPipeline({
|
|
|
projectId: this.$store.state.workspace.currentProjectId,
|
|
|
pipelineId: id,
|
|
|
- }).configJson || '{}';
|
|
|
+ })).configJson;
|
|
|
+ this.pipelineConfig = JSON.parse(config || '{}');
|
|
|
this.dialogLoading = false;
|
|
|
break;
|
|
|
}
|
|
|
@@ -349,23 +378,12 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- // eslint-disable-next-line func-names
|
|
|
- lintJson: debounce(function (value) {
|
|
|
- this.jsonValid = true;
|
|
|
- try {
|
|
|
- const result = jsonlint.parse(value);
|
|
|
- this.pipelineConfig = JSON.stringify(result, null, ' ');
|
|
|
- } catch (e) {
|
|
|
- this.jsonValid = false;
|
|
|
- this.hint = `${value}\n${e}`;
|
|
|
- }
|
|
|
- }, 500),
|
|
|
async handlePipelineUpdateConfirm() {
|
|
|
this.confirmLoading = true;
|
|
|
await PipelineAPI.updatePipeline({
|
|
|
projectId: this.$store.state.workspace.currentProjectId,
|
|
|
pipelineId: this.editingPipelineId,
|
|
|
- configJson: JSON.stringify(JSON.parse(this.pipelineConfig)),
|
|
|
+ configJson: JSON.stringify(this.pipelineConfig),
|
|
|
});
|
|
|
this.confirmLoading = false;
|
|
|
this.showPipelineEditModal = false;
|
|
|
@@ -393,6 +411,9 @@ export default {
|
|
|
await PipelineAPI.deleteInstance(id);
|
|
|
this.loading = false;
|
|
|
},
|
|
|
+ getStage(stageName) {
|
|
|
+ return this.stages.find((stage) => stage.name === stageName);
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
@@ -414,6 +435,9 @@ export default {
|
|
|
width: 60%;
|
|
|
margin: 0 auto;
|
|
|
}
|
|
|
+.edit-pipeline-form {
|
|
|
+ margin-top: 20px;
|
|
|
+}
|
|
|
.button-group {
|
|
|
margin-left: 40px;
|
|
|
}
|