gtsoft-snail-job-admin/src/store/modules/workflow/index.ts

67 lines
1.5 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
import { ref } from 'vue';
import { fetchGetJobList, fetchGetWorkflowNameList } from '@/service/api';
import { SetupStoreId } from '@/enum';
export const useWorkflowStore = defineStore(SetupStoreId.Workflow, () => {
const id = ref<string>();
const type = ref<number>();
const groupName = ref<string>();
const jobList = ref<Pick<Api.Job.Job, 'id' | 'jobName'>[]>([]);
const workflowList = ref<Pick<Api.Workflow.Workflow, 'id' | 'workflowName'>[]>([]);
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
};
});
}
}
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
};
});
}
}
function clear() {
id.value = undefined;
type.value = undefined;
groupName.value = undefined;
jobList.value = [];
}
return {
id,
type,
groupName,
jobList,
workflowList,
setJobList,
setWorkflowList,
setType,
setId,
clear
};
});