2025-04-12 23:59:03 +08:00
|
|
|
|
import { defineStore } from "pinia";
|
|
|
|
|
|
import * as api from "./api.plugin";
|
2025-08-27 18:23:24 +08:00
|
|
|
|
import { DynamicType, FormItemProps, useMerge } from "@fast-crud/fast-crud";
|
2025-06-28 23:57:01 +08:00
|
|
|
|
import { i18n } from "/src/locales/i18n";
|
2025-08-27 18:23:24 +08:00
|
|
|
|
import { cloneDeep } from "lodash-es";
|
2025-04-12 23:59:03 +08:00
|
|
|
|
interface PluginState {
|
|
|
|
|
|
group?: PluginGroups;
|
2025-08-28 00:58:17 +08:00
|
|
|
|
originGroup?: PluginGroups;
|
2025-04-12 23:59:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export type PluginGroup = {
|
|
|
|
|
|
key: string;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
desc?: string;
|
|
|
|
|
|
order: number;
|
|
|
|
|
|
icon: string;
|
|
|
|
|
|
plugins: any[];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export type PluginDefine = {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
desc?: string;
|
|
|
|
|
|
shortcut: any;
|
|
|
|
|
|
input: {
|
|
|
|
|
|
[key: string]: DynamicType<FormItemProps>;
|
|
|
|
|
|
};
|
|
|
|
|
|
output: {
|
|
|
|
|
|
[key: string]: any;
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export class PluginGroups {
|
|
|
|
|
|
groups!: { [key: string]: PluginGroup };
|
|
|
|
|
|
map!: { [key: string]: PluginDefine };
|
2025-06-28 23:57:01 +08:00
|
|
|
|
t: any;
|
2025-08-27 18:23:24 +08:00
|
|
|
|
mergeSetting?: boolean;
|
|
|
|
|
|
constructor(groups: { [key: string]: PluginGroup }, opts?: { mergeSetting?: boolean }) {
|
2025-04-12 23:59:03 +08:00
|
|
|
|
this.groups = groups;
|
2025-06-28 23:57:01 +08:00
|
|
|
|
this.t = i18n.global.t;
|
2025-08-27 18:23:24 +08:00
|
|
|
|
this.mergeSetting = opts?.mergeSetting ?? false;
|
2025-04-12 23:59:03 +08:00
|
|
|
|
this.initGroup(groups);
|
|
|
|
|
|
this.initMap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private initGroup(groups: { [p: string]: PluginGroup }) {
|
2025-08-27 18:23:24 +08:00
|
|
|
|
const { merge } = useMerge();
|
2025-04-12 23:59:03 +08:00
|
|
|
|
const all: PluginGroup = {
|
|
|
|
|
|
key: "all",
|
2025-06-28 23:57:01 +08:00
|
|
|
|
title: this.t("certd.all"),
|
2025-04-12 23:59:03 +08:00
|
|
|
|
order: 0,
|
|
|
|
|
|
plugins: [],
|
|
|
|
|
|
icon: "material-symbols:border-all-rounded",
|
|
|
|
|
|
};
|
|
|
|
|
|
for (const key in groups) {
|
2025-08-27 18:23:24 +08:00
|
|
|
|
if (this.mergeSetting) {
|
|
|
|
|
|
for (const plugin of groups[key].plugins) {
|
|
|
|
|
|
if (plugin.sysSetting) {
|
2025-08-28 00:58:17 +08:00
|
|
|
|
merge(plugin.input, plugin.sysSetting.metadata?.input || {});
|
2025-08-27 18:23:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-12 23:59:03 +08:00
|
|
|
|
all.plugins.push(...groups[key].plugins);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.groups = {
|
|
|
|
|
|
all,
|
|
|
|
|
|
...groups,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initMap() {
|
|
|
|
|
|
const map: { [key: string]: PluginDefine } = {};
|
|
|
|
|
|
for (const key in this.groups) {
|
|
|
|
|
|
const group = this.groups[key];
|
|
|
|
|
|
for (const plugin of group.plugins) {
|
|
|
|
|
|
map[plugin.name] = plugin;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.map = map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getGroups() {
|
|
|
|
|
|
return this.groups;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get(name: string) {
|
|
|
|
|
|
return this.map[name];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getPreStepOutputOptions({ pipeline, currentStageIndex, currentTaskIndex, currentStepIndex, currentTask }: any) {
|
|
|
|
|
|
const steps = this.collectionPreStepOutputs({
|
|
|
|
|
|
pipeline,
|
|
|
|
|
|
currentStageIndex,
|
|
|
|
|
|
currentTaskIndex,
|
|
|
|
|
|
currentStepIndex,
|
|
|
|
|
|
currentTask,
|
|
|
|
|
|
});
|
|
|
|
|
|
const options: any[] = [];
|
|
|
|
|
|
for (const step of steps) {
|
|
|
|
|
|
const stepDefine = this.get(step.type);
|
|
|
|
|
|
for (const key in stepDefine?.output) {
|
2025-07-09 14:34:24 +08:00
|
|
|
|
const inputDefine = stepDefine.output[key];
|
2025-04-12 23:59:03 +08:00
|
|
|
|
options.push({
|
|
|
|
|
|
value: `step.${step.id}.${key}`,
|
2025-07-09 14:34:24 +08:00
|
|
|
|
label: `${inputDefine.title}【from:${step.title}】`,
|
2025-04-12 23:59:03 +08:00
|
|
|
|
type: step.type,
|
2025-07-09 14:34:24 +08:00
|
|
|
|
valueType: inputDefine.type,
|
|
|
|
|
|
key: key,
|
2025-04-12 23:59:03 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return options;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
collectionPreStepOutputs({ pipeline, currentStageIndex, currentTaskIndex, currentStepIndex, currentTask }: any) {
|
|
|
|
|
|
const steps: any[] = [];
|
|
|
|
|
|
// 开始放step
|
|
|
|
|
|
for (let i = 0; i < currentStageIndex; i++) {
|
|
|
|
|
|
const stage = pipeline.stages[i];
|
|
|
|
|
|
for (const task of stage.tasks) {
|
|
|
|
|
|
for (const step of task.steps) {
|
|
|
|
|
|
steps.push(step);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//当前阶段之前的task
|
|
|
|
|
|
const currentStage = pipeline.stages[currentStageIndex];
|
|
|
|
|
|
for (let i = 0; i < currentTaskIndex; i++) {
|
|
|
|
|
|
const task = currentStage.tasks[i];
|
|
|
|
|
|
for (const step of task.steps) {
|
|
|
|
|
|
steps.push(step);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//放当前任务下的step
|
|
|
|
|
|
for (let i = 0; i < currentStepIndex; i++) {
|
|
|
|
|
|
const step = currentTask.steps[i];
|
|
|
|
|
|
steps.push(step);
|
|
|
|
|
|
}
|
|
|
|
|
|
return steps;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const usePluginStore = defineStore({
|
|
|
|
|
|
id: "app.plugin",
|
|
|
|
|
|
state: (): PluginState => ({
|
|
|
|
|
|
group: null,
|
2025-08-27 18:23:24 +08:00
|
|
|
|
originGroup: null,
|
2025-04-12 23:59:03 +08:00
|
|
|
|
}),
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
async reload() {
|
|
|
|
|
|
const groups = await api.GetGroups({});
|
2025-08-27 18:23:24 +08:00
|
|
|
|
this.group = new PluginGroups(groups, { mergeSetting: true });
|
|
|
|
|
|
this.originGroup = new PluginGroups(cloneDeep(groups));
|
|
|
|
|
|
console.log("group", this.group);
|
|
|
|
|
|
console.log("originGroup", this.originGroup);
|
2025-04-12 23:59:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
async init() {
|
|
|
|
|
|
if (!this.group) {
|
|
|
|
|
|
await this.reload();
|
|
|
|
|
|
}
|
|
|
|
|
|
return this.group;
|
|
|
|
|
|
},
|
|
|
|
|
|
async getGroups(): Promise<PluginGroups> {
|
|
|
|
|
|
await this.init();
|
|
|
|
|
|
return this.group as PluginGroups;
|
|
|
|
|
|
},
|
|
|
|
|
|
async clear() {
|
|
|
|
|
|
this.group = null;
|
2025-08-28 00:58:17 +08:00
|
|
|
|
this.originGroup = null
|
2025-04-12 23:59:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
async getList(): Promise<PluginDefine[]> {
|
|
|
|
|
|
await this.init();
|
|
|
|
|
|
return this.group.groups.all.plugins;
|
|
|
|
|
|
},
|
|
|
|
|
|
async getPluginDefine(name: string): Promise<PluginDefine> {
|
|
|
|
|
|
await this.init();
|
|
|
|
|
|
return this.group.get(name);
|
|
|
|
|
|
},
|
2025-08-27 18:23:24 +08:00
|
|
|
|
async getPluginDefineFromOrigin(name: string): Promise<PluginDefine> {
|
|
|
|
|
|
await this.init();
|
|
|
|
|
|
return this.originGroup.get(name);
|
|
|
|
|
|
},
|
2025-04-12 23:59:03 +08:00
|
|
|
|
async getPluginConfig(query: any) {
|
|
|
|
|
|
return await api.GetPluginConfig(query);
|
|
|
|
|
|
},
|
2025-06-19 18:17:35 +08:00
|
|
|
|
getPluginDefineSync(name: string) {
|
|
|
|
|
|
return this.group.get(name);
|
|
|
|
|
|
},
|
2025-04-12 23:59:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|