Merge branch 'dev/net' into develop

This commit is contained in:
Net 2024-04-09 15:46:44 +07:00
commit 92a3d03cde

View file

@ -2,17 +2,19 @@ import { ref } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { Pagination } from '../types'; import { Pagination } from '../types';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { Branch, BranchCreate } from './types'; import { Branch, BranchCreate, BranchWithChildren } from './types';
const useBranchStore = defineStore('api-branch', () => { const useBranchStore = defineStore('api-branch', () => {
const data = ref<Pagination<Branch[]>>(); const data = ref<Pagination<Branch[]>>();
async function fetchList( async function fetchList<T extends Branch>(
opts?: { opts?: {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
zipCode?: string; zipCode?: string;
query?: string; query?: string;
tree?: boolean;
filter?: 'head' | 'sub';
}, },
flow?: { flow?: {
sessionId: string; sessionId: string;
@ -28,10 +30,11 @@ const useBranchStore = defineStore('api-branch', () => {
if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`); if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`);
if (opts?.zipCode) params.append('zipCode', opts.zipCode); if (opts?.zipCode) params.append('zipCode', opts.zipCode);
if (opts?.query) params.append('query', opts.query); if (opts?.query) params.append('query', opts.query);
if (opts?.tree) params.append('tree', 'true');
const query = params.toString(); const query = params.toString();
const res = await api.get<Pagination<Branch[]>>( const res = await api.get<Pagination<T[]>>(
`/branch${(params && '?'.concat(query)) || ''}`, `/branch${(params && '?'.concat(query)) || ''}`,
{ {
headers: { headers: {
@ -44,7 +47,7 @@ const useBranchStore = defineStore('api-branch', () => {
if (res && res.status === 200) { if (res && res.status === 200) {
data.value = res.data; data.value = res.data;
return data.value; return data.value as Pagination<T[]>;
} }
return false; return false;
} }