79 lines
1.9 KiB
TypeScript
79 lines
1.9 KiB
TypeScript
import { ref } from 'vue';
|
|
import { defineStore } from 'pinia';
|
|
import { api } from 'src/boot/axios';
|
|
import { PaginationResult } from 'src/types';
|
|
import { WorkflowTemplate, WorkflowTemplatePayload } from './types';
|
|
import { Status } from '../types';
|
|
|
|
export const useWorkflowTemplate = defineStore('workflow-store', () => {
|
|
const data = ref<WorkflowTemplate[]>([]);
|
|
const page = ref<number>(1);
|
|
const pageMax = ref<number>(1);
|
|
const pageSize = ref<number>(30);
|
|
|
|
async function getWorkflowTemplate(id: string) {
|
|
const res = await api.get<WorkflowTemplate>(`/workflow-template/${id}`);
|
|
|
|
if (res.status >= 400) return null;
|
|
|
|
return res.data;
|
|
}
|
|
|
|
async function getWorkflowTemplateList(params?: {
|
|
page?: number;
|
|
pageSize?: number;
|
|
query?: string;
|
|
status?: Status;
|
|
activeOnly?: boolean;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}) {
|
|
const res = await api.get<PaginationResult<WorkflowTemplate>>(
|
|
'/workflow-template',
|
|
{ params },
|
|
);
|
|
|
|
if (res.status >= 400) return null;
|
|
|
|
return res.data;
|
|
}
|
|
|
|
async function creatWorkflowTemplate(data: WorkflowTemplatePayload) {
|
|
const res = await api.post<WorkflowTemplate>('/workflow-template', data);
|
|
if (res.status >= 400) return null;
|
|
return res;
|
|
}
|
|
|
|
async function editWorkflowTemplate(
|
|
data: WorkflowTemplatePayload & { id: string },
|
|
) {
|
|
const res = await api.put<WorkflowTemplate>(
|
|
`/workflow-template/${data.id}`,
|
|
{
|
|
...data,
|
|
id: undefined,
|
|
},
|
|
);
|
|
if (res.status >= 400) return null;
|
|
return res;
|
|
}
|
|
|
|
async function deleteWorkflowTemplate(id: string) {
|
|
const res = await api.delete<WorkflowTemplate>(`/workflow-template/${id}`);
|
|
if (res.status >= 400) return null;
|
|
return res;
|
|
}
|
|
|
|
return {
|
|
data,
|
|
page,
|
|
pageSize,
|
|
pageMax,
|
|
|
|
getWorkflowTemplate,
|
|
getWorkflowTemplateList,
|
|
creatWorkflowTemplate,
|
|
editWorkflowTemplate,
|
|
deleteWorkflowTemplate,
|
|
};
|
|
});
|