[user] Fixed avatar upload
This commit is contained in:
parent
7d914d065e
commit
fc35e2ecec
|
@ -135,7 +135,7 @@ export default defineComponent({
|
||||||
|
|
||||||
const password = ref('');
|
const password = ref('');
|
||||||
const newPassword = ref('');
|
const newPassword = ref('');
|
||||||
const avatar = ref<string[]>([]);
|
const avatar = ref<File | FileList | string[]>();
|
||||||
const userModel = ref(props.user);
|
const userModel = ref(props.user);
|
||||||
|
|
||||||
const canSetRoles = computed(() => hasPermission('users_set_roles'));
|
const canSetRoles = computed(() => hasPermission('users_set_roles'));
|
||||||
|
@ -157,7 +157,7 @@ export default defineComponent({
|
||||||
progress: true,
|
progress: true,
|
||||||
actions: [{ icon: 'mdi-close', color: 'white' }],
|
actions: [{ icon: 'mdi-close', color: 'white' }],
|
||||||
});
|
});
|
||||||
avatar.value = [];
|
avatar.value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
@ -174,8 +174,10 @@ export default defineComponent({
|
||||||
|
|
||||||
emit('update:user', changed);
|
emit('update:user', changed);
|
||||||
|
|
||||||
if (avatar.value && (avatar.value.length > 0 || avatar.value instanceof File))
|
if (avatar.value)
|
||||||
userStore.uploadAvatar(changed, avatar.value[0]).catch((response: Response) => {
|
userStore
|
||||||
|
.uploadAvatar(changed, avatar.value instanceof File ? avatar.value : avatar.value[0])
|
||||||
|
.catch((response: Response) => {
|
||||||
if (response && response.status == 400) {
|
if (response && response.status == 400) {
|
||||||
onAvatarRejected();
|
onAvatarRejected();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ export const useUserStore = defineStore({
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async uploadAvatar(user: FG.User, file: string) {
|
async uploadAvatar(user: FG.User, file: string | File) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
await api.post(`/users/${user.userid}/avatar`, formData, {
|
await api.post(`/users/${user.userid}/avatar`, formData, {
|
||||||
|
|
Loading…
Reference in New Issue