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([]); const page = ref(1); const pageMax = ref(1); const pageSize = ref(30); async function getWorkflowTemplate(id: string) { const res = await api.get(`/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>( '/workflow-template', { params }, ); if (res.status >= 400) return null; return res.data; } async function creatWorkflowTemplate(data: WorkflowTemplatePayload) { const res = await api.post('/workflow-template', data); if (res.status >= 400) return null; return res; } async function editWorkflowTemplate( data: WorkflowTemplatePayload & { id: string }, ) { const res = await api.put( `/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(`/workflow-template/${id}`); if (res.status >= 400) return null; return res; } return { data, page, pageSize, pageMax, getWorkflowTemplate, getWorkflowTemplateList, creatWorkflowTemplate, editWorkflowTemplate, deleteWorkflowTemplate, }; });