pull/361/head
xiaojunnuo 2025-03-21 23:40:31 +08:00
parent d558d50102
commit fedf90ea78
6 changed files with 104 additions and 78 deletions

View File

@ -82,7 +82,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
add: {
text: "上传自定义证书",
type: "primary",
show: true,
show: false,
async click() {
await openUploadCreateDialog();
},
@ -116,9 +116,11 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
order: 4,
title: "更新证书",
type: "link",
icon: "ph:upload",
icon: "ion:upload",
async click({ row }) {
await openUpdateCertDialog(row.id);
await openUpdateCertDialog({
id: row.id,
});
},
},
remove: {

View File

@ -2,7 +2,7 @@
<div class="cert-info-updater w-full flex items-center">
<div class="flex-o">
<fs-values-format :model-value="modelValue" :dict="certInfoDict" />
<fs-button v-if="modelValue" type="primary" size="small" class="ml-1" icon="ion:upload" text="更新证书" @click="onUploadClick" />
<fs-button type="primary" size="small" class="ml-1" icon="ion:upload" text="更新证书" @click="onUploadClick" />
</div>
</div>
</template>
@ -24,7 +24,7 @@ const props = defineProps<{
size?: string;
disabled?: boolean;
}>();
const emit = defineEmits(["updated"]);
const emit = defineEmits(["updated", "update:modelValue"]);
const certInfoDict = dict({
value: "id",
@ -42,10 +42,19 @@ const certInfoDict = dict({
const { openUpdateCertDialog } = useCertUpload();
function onUpdated(res: any) {
if (!props.modelValue) {
emit("update:modelValue", res.id);
}
emit("updated", res);
}
const pipeline: any = inject("pipeline");
function onUploadClick() {
openUpdateCertDialog(props.modelValue, onUpdated);
openUpdateCertDialog({
id: props.modelValue,
pipelineId: pipeline.id,
onSubmit: onUpdated,
});
}
</script>
<style lang="less">

View File

@ -161,7 +161,7 @@ export function useCertUpload() {
wrapperRef.value = wrapper;
}
async function openUpdateCertDialog(id: any, onSubmit?: any) {
async function openUpdateCertDialog(opts: { id?: any; onSubmit?: any; pipelineId?: any }) {
function createCrudOptions() {
return {
crudOptions: {
@ -204,14 +204,18 @@ export function useCertUpload() {
title: "更新证书",
saveRemind: false,
},
async afterSubmit() {
notification.success({ message: "更新成功" });
},
async doSubmit({ form }: any) {
const req = {
id: id,
id: opts.id,
pipelineId: opts.pipelineId,
cert: form.cert,
};
const res = await api.UploadCert(req);
if (onSubmit) {
await onSubmit(res);
if (opts.onSubmit) {
await opts.onSubmit(res);
}
},
},

View File

@ -10,7 +10,7 @@ import { doRequest } from "/@/components/plugins/lib";
import { ref, useAttrs, inject } from "vue";
import { useFormWrapper } from "@fast-crud/fast-crud";
import { notification } from "ant-design-vue";
import { merge } from "lodash-es";
import { mergeWith, isArray } from "lodash-es";
defineOptions({
name: "TaskShortcut",
});
@ -112,9 +112,9 @@ const doPluginFormSubmit = async (formData: any) => {
<style lang="less">
.task-shortcut {
width: 25px;
height: 25px;
height: 22px;
border: 1px solid #e3e3e3;
border-radius: 0 0 6px 6px;
border-radius: 0 0 5px 5px;
background: #fff;
display: flex;
justify-content: center;

View File

@ -1091,7 +1091,7 @@ export default defineComponent({
position: relative;
.shortcut {
position: absolute;
bottom: -15px;
bottom: -10px;
left: 20px;
}
}

View File

@ -14,6 +14,7 @@ export type UploadCertReq = {
certReader: CertReader;
fromType?: string;
userId?: number;
pipelineId?: number;
};
export type UpdateCertReq = {
@ -25,6 +26,7 @@ export type UpdateCertReq = {
export type CreateUploadPipelineReq = {
cert: CertInfo;
userId: number;
pipelineId?: number;
pipeline?:{
input?:any;
notifications?:any[]
@ -85,77 +87,84 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
}
const certReader = new CertReader(cert)
return await this.transaction(async (tx:EntityManager)=>{
let pipelineId = body.pipelineId;
const newCertInfo = await this.uploadCert(tx,{
certReader: certReader,
fromType: 'upload',
userId
});
const pipelineTitle = certReader.getAllDomains()[0] +"上传证书自动部署";
const notifications = body.pipeline?.notifications ||[];
if(notifications.length === 0){
notifications.push({
type: "custom",
when: ["error", "turnToSuccess", "success"],
notificationId: 0,
title: "默认通知",
});
}
let pipeline = {
title: pipelineTitle,
runnableType: "pipeline",
stages: [
{
id: nanoid(10),
title: "上传证书解析阶段",
maxTaskCount: 1,
runnableType: "stage",
tasks: [
{
id: nanoid(10),
title: "上传证书解析转换",
runnableType: "task",
steps: [
{
id: nanoid(10),
title: "上传证书解析转换",
runnableType: "step",
input: {
certInfoId: newCertInfo.id,
domains: newCertInfo.domains.split(','),
...body.pipeline?.input
},
strategy: {
runStrategy: 0, // 正常执行
},
type: "CertApplyUpload",
},
],
},
],
},
],
triggers:[],
notifications,
}
const newPipeline = await tx.getRepository(PipelineEntity).save({
userId,
title: pipelineTitle,
type:"cert_upload",
content: JSON.stringify(pipeline),
keepHistory:20,
})
newCertInfo.pipelineId = newPipeline.id;
await tx.getRepository(CertInfoEntity).save({
id: newCertInfo.id,
pipelineId: newPipeline.id
pipelineId
});
if(!pipelineId){
const pipelineTitle = certReader.getAllDomains()[0] +"上传证书自动部署";
const notifications = body.pipeline?.notifications ||[];
if(notifications.length === 0){
notifications.push({
type: "custom",
when: ["error", "turnToSuccess", "success"],
notificationId: 0,
title: "默认通知",
});
}
let pipeline = {
title: pipelineTitle,
runnableType: "pipeline",
stages: [
{
id: nanoid(10),
title: "上传证书解析阶段",
maxTaskCount: 1,
runnableType: "stage",
tasks: [
{
id: nanoid(10),
title: "上传证书解析转换",
runnableType: "task",
steps: [
{
id: nanoid(10),
title: "上传证书解析转换",
runnableType: "step",
input: {
certInfoId: newCertInfo.id,
domains: newCertInfo.domains.split(','),
...body.pipeline?.input
},
strategy: {
runStrategy: 0, // 正常执行
},
type: "CertApplyUpload",
},
],
},
],
},
],
triggers:[],
notifications,
}
const newPipeline = await tx.getRepository(PipelineEntity).save({
userId,
title: pipelineTitle,
type:"cert_upload",
content: JSON.stringify(pipeline),
keepHistory:20,
})
newCertInfo.pipelineId = newPipeline.id;
await tx.getRepository(CertInfoEntity).save({
id: newCertInfo.id,
pipelineId: newPipeline.id
});
pipelineId = newPipeline.id;
}
return {
id:newCertInfo.id,
pipelineId: newPipeline.id,
pipelineId: pipelineId,
domains: newCertInfo.domains.split(','),
fromType: newCertInfo.fromType,
updateTime: newCertInfo.updateTime,
@ -183,7 +192,9 @@ export class CertUploadService extends BaseService<CertInfoEntity> {
bean.domainCount = domains.length;
bean.expiresTime = certReader.expires;
bean.certProvider = certReader.detail.issuer.commonName;
if (req.pipelineId){
bean.pipelineId = req.pipelineId;
}
await tx.getRepository(CertInfoEntity).save(bean);
return bean;