refactor: add map to contact store
This commit is contained in:
parent
f91bb46c6b
commit
05d13e5620
1 changed files with 18 additions and 2 deletions
|
|
@ -1,12 +1,26 @@
|
|||
import axios from 'axios';
|
||||
import { ref } from 'vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { BranchContact, BranchContactCreate } from './types';
|
||||
import { Pagination } from '../types';
|
||||
import { api } from 'src/boot/axios';
|
||||
|
||||
type BranchContactId = string;
|
||||
|
||||
const useBranchContactStore = defineStore('api-branch-contact', () => {
|
||||
const data = ref<Pagination<BranchContact[]>>();
|
||||
const data = ref<Pagination<BranchContact[]>>({
|
||||
result: [],
|
||||
page: 0,
|
||||
pageSize: 0,
|
||||
total: 0,
|
||||
});
|
||||
const map = ref<Record<BranchContactId, BranchContact>>({});
|
||||
|
||||
watch(data, () => {
|
||||
data.value.result.forEach((v) => {
|
||||
map.value[v.id] = v;
|
||||
});
|
||||
});
|
||||
|
||||
async function fetchList(
|
||||
branchId: string,
|
||||
|
|
@ -146,6 +160,8 @@ const useBranchContactStore = defineStore('api-branch-contact', () => {
|
|||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
map,
|
||||
fetchList,
|
||||
create,
|
||||
editById,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue