fix: branch file
This commit is contained in:
parent
a0013bdbe0
commit
57aabf1deb
2 changed files with 32 additions and 32 deletions
|
|
@ -422,6 +422,7 @@ async function fetchBranchById(id: string) {
|
||||||
const resAttachment = await branchStore.fetchListAttachment(res.id);
|
const resAttachment = await branchStore.fetchListAttachment(res.id);
|
||||||
|
|
||||||
if (resAttachment) {
|
if (resAttachment) {
|
||||||
|
|
||||||
currentAttachmentList.value = await Promise.all(
|
currentAttachmentList.value = await Promise.all(
|
||||||
resAttachment.map(async (v) => {
|
resAttachment.map(async (v) => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -2016,6 +2017,7 @@ watch(currentHq, () => {
|
||||||
id="form-attachment"
|
id="form-attachment"
|
||||||
class="q-mb-xl"
|
class="q-mb-xl"
|
||||||
:auto-save="currentId !== ''"
|
:auto-save="currentId !== ''"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
branch
|
branch
|
||||||
v-model="currentAttachmentList"
|
v-model="currentAttachmentList"
|
||||||
@save="
|
@save="
|
||||||
|
|
@ -2368,22 +2370,9 @@ watch(currentHq, () => {
|
||||||
class="q-mb-xl"
|
class="q-mb-xl"
|
||||||
id="info-attachment"
|
id="info-attachment"
|
||||||
branch
|
branch
|
||||||
|
v-model="currentAttachmentList"
|
||||||
|
:readonly="formType === 'view'"
|
||||||
:file="currentAttachmentList"
|
:file="currentAttachmentList"
|
||||||
:tree-file="
|
|
||||||
Object.values(
|
|
||||||
currentAttachmentList.reduce<
|
|
||||||
Record<string, { label: string; file: { label: string }[] }>
|
|
||||||
>((a, b) => {
|
|
||||||
if (b.name && !a[b.name]) {
|
|
||||||
a[b.name] = {
|
|
||||||
label: b.name,
|
|
||||||
file: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}, {}) || {},
|
|
||||||
)
|
|
||||||
"
|
|
||||||
@save="
|
@save="
|
||||||
async (_group, file) => {
|
async (_group, file) => {
|
||||||
if (file) {
|
if (file) {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,10 @@ import { Pagination } from '../types';
|
||||||
import { BankBook, Branch, BranchCreate } from './types';
|
import { BankBook, Branch, BranchCreate } from './types';
|
||||||
import { BranchContact } from '../branch-contact/types';
|
import { BranchContact } from '../branch-contact/types';
|
||||||
import { User } from '../user/types';
|
import { User } from '../user/types';
|
||||||
|
|
||||||
type BranchId = string;
|
type BranchId = string;
|
||||||
|
|
||||||
|
import { manageAttachment } from '../utils';
|
||||||
|
|
||||||
const useBranchStore = defineStore('api-branch', () => {
|
const useBranchStore = defineStore('api-branch', () => {
|
||||||
const flowStore = useFlowStore();
|
const flowStore = useFlowStore();
|
||||||
const data = ref<Pagination<(Branch & { branch?: Branch[] })[]>>({
|
const data = ref<Pagination<(Branch & { branch?: Branch[] })[]>>({
|
||||||
|
|
@ -20,7 +21,7 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
});
|
});
|
||||||
const map = ref<Record<BranchId, Branch & { contact?: BranchContact[] }>>({});
|
const map = ref<Record<BranchId, Branch & { contact?: BranchContact[] }>>({});
|
||||||
const contact: Record<BranchId, BranchContact[]> = {};
|
const contact: Record<BranchId, BranchContact[]> = {};
|
||||||
|
const attachmentManager = manageAttachment(api, 'branch');
|
||||||
watch(data, () => {
|
watch(data, () => {
|
||||||
data.value.result.forEach((v) => {
|
data.value.result.forEach((v) => {
|
||||||
map.value[v.id] = v;
|
map.value[v.id] = v;
|
||||||
|
|
@ -170,7 +171,11 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
fileItem.forEach(async (v) => {
|
fileItem.forEach(async (v) => {
|
||||||
if (v.file === undefined) return;
|
if (v.file === undefined) return;
|
||||||
|
|
||||||
await putAttachment(res.data.id, v.file);
|
await attachmentManager.putAttachment({
|
||||||
|
parentId: res.data.id,
|
||||||
|
name: v.file.name,
|
||||||
|
file: v.file,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -398,34 +403,40 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchListAttachment(branchId: string) {
|
async function fetchListAttachment(branchId: string) {
|
||||||
const res = await api.get<string[]>(`branch/${branchId}/attachment`);
|
const res = await attachmentManager.listAttachment({ parentId: branchId });
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res) {
|
||||||
return res.data;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchByIdAttachment(branchId: string, name: string) {
|
async function fetchByIdAttachment(branchId: string, name: string) {
|
||||||
const res = await api.get<string>(`branch/${branchId}/attachment/${name}`);
|
const res = await attachmentManager.getAttachment({
|
||||||
|
parentId: branchId,
|
||||||
|
name: name,
|
||||||
|
});
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res) {
|
||||||
return res.data;
|
console.log(res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function putAttachment(branchId: string, file: File) {
|
async function putAttachment(branchId: string, file: File) {
|
||||||
await api
|
await attachmentManager.putAttachment({
|
||||||
.put(`branch/${branchId}/attachment/${file.name}`, file, {
|
parentId: branchId,
|
||||||
headers: { 'Content-Type': file.type },
|
name: file.name,
|
||||||
onUploadProgress: (e) => console.log(e),
|
file: file,
|
||||||
})
|
});
|
||||||
.catch((e) => console.error(e));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteByIdAttachment(branchId: string, name: string) {
|
async function deleteByIdAttachment(branchId: string, name: string) {
|
||||||
const res = await api.delete(`branch/${branchId}/attachment/${name}`);
|
const res = await attachmentManager.delAttachment({
|
||||||
|
parentId: branchId,
|
||||||
|
name: name,
|
||||||
|
});
|
||||||
|
|
||||||
if (res.status === 204) {
|
if (res) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue