2024-06-18 17:05:56 +08:00
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
import { ref } from 'vue';
|
2025-05-09 00:51:22 +08:00
|
|
|
import { fetchGetJobList, fetchGetWorkflowNameList } from '@/service/api';
|
2024-09-20 12:14:20 +08:00
|
|
|
import { SetupStoreId } from '@/enum';
|
2024-06-18 17:05:56 +08:00
|
|
|
|
2024-09-20 12:14:20 +08:00
|
|
|
export const useWorkflowStore = defineStore(SetupStoreId.Workflow, () => {
|
2024-06-18 17:05:56 +08:00
|
|
|
const id = ref<string>();
|
|
|
|
const type = ref<number>();
|
|
|
|
const groupName = ref<string>();
|
|
|
|
const jobList = ref<Pick<Api.Job.Job, 'id' | 'jobName'>[]>([]);
|
2025-05-09 00:51:22 +08:00
|
|
|
const workflowList = ref<Pick<Api.Workflow.Workflow, 'id' | 'workflowName'>[]>([]);
|
2024-06-18 17:05:56 +08:00
|
|
|
|
|
|
|
function setId(value: string) {
|
|
|
|
id.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setType(value: number) {
|
|
|
|
type.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setJobList(value: string) {
|
|
|
|
groupName.value = value;
|
|
|
|
const { data, error } = await fetchGetJobList({ groupName: value });
|
|
|
|
if (!error) {
|
|
|
|
jobList.value = data.map(item => {
|
|
|
|
return {
|
|
|
|
id: item.id!,
|
|
|
|
jobName: item.jobName
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-09 00:51:22 +08:00
|
|
|
async function setWorkflowList(value: string) {
|
|
|
|
groupName.value = value;
|
|
|
|
const { data, error } = await fetchGetWorkflowNameList({ groupName: value });
|
|
|
|
if (!error) {
|
|
|
|
workflowList.value = data.map(item => {
|
|
|
|
return {
|
|
|
|
id: item.id!,
|
|
|
|
workflowName: item.workflowName
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 17:05:56 +08:00
|
|
|
function clear() {
|
|
|
|
id.value = undefined;
|
|
|
|
type.value = undefined;
|
|
|
|
groupName.value = undefined;
|
|
|
|
jobList.value = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
groupName,
|
|
|
|
jobList,
|
2025-05-09 00:51:22 +08:00
|
|
|
workflowList,
|
2024-06-18 17:05:56 +08:00
|
|
|
setJobList,
|
2025-05-09 00:51:22 +08:00
|
|
|
setWorkflowList,
|
2024-06-18 17:05:56 +08:00
|
|
|
setType,
|
|
|
|
setId,
|
|
|
|
clear
|
|
|
|
};
|
|
|
|
});
|