feat: add signature api function
This commit is contained in:
parent
ee8bd14f48
commit
5d7129b858
2 changed files with 31 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ import {
|
|||
import axios from 'axios';
|
||||
import useBranchStore from '../branch';
|
||||
import { Branch } from '../branch/types';
|
||||
import { getSignature, setSignature } from './signature';
|
||||
|
||||
const branchStore = useBranchStore();
|
||||
|
||||
|
|
@ -327,6 +328,9 @@ const useUserStore = defineStore('api-user', () => {
|
|||
addAttachment,
|
||||
deleteAttachment,
|
||||
|
||||
getSignature,
|
||||
setSignature,
|
||||
|
||||
typeStats,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
27
src/stores/user/signature.ts
Normal file
27
src/stores/user/signature.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { api } from 'src/boot/axios';
|
||||
import { getUserId } from 'src/services/keycloak';
|
||||
|
||||
export async function getSignature() {
|
||||
const userId = getUserId();
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
const response = await api.get<Blob>('/user/' + userId + '/signature', {
|
||||
responseType: 'blob',
|
||||
});
|
||||
|
||||
return await new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('error', reject);
|
||||
reader.addEventListener('load', () => resolve(reader.result as string));
|
||||
reader.readAsDataURL(response.data);
|
||||
});
|
||||
}
|
||||
|
||||
export async function setSignature(image: string) {
|
||||
const userId = getUserId();
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
return await api.put('/user/' + userId + '/signature', { data: image });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue