Fixed issue with avatar upload
This commit is contained in:
parent
7612ccde7b
commit
0b7c6feeb3
|
@ -1,8 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<q-form
|
<q-form @submit="save" @reset="reset">
|
||||||
@submit="save"
|
|
||||||
@reset="reset"
|
|
||||||
>
|
|
||||||
<q-card-section class="fit row justify-start content-center items-center">
|
<q-card-section class="fit row justify-start content-center items-center">
|
||||||
<q-input
|
<q-input
|
||||||
class="col-xs-12 col-sm-6 q-pa-sm"
|
class="col-xs-12 col-sm-6 q-pa-sm"
|
||||||
|
@ -69,10 +66,7 @@
|
||||||
@rejected="onAvatarRejected"
|
@rejected="onAvatarRejected"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<q-icon
|
<q-icon name="mdi-file-image" @click.stop />
|
||||||
name="mdi-file-image"
|
|
||||||
@click.stop
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</q-file>
|
</q-file>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -109,15 +103,8 @@
|
||||||
/>
|
/>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-actions align="right">
|
<q-card-actions align="right">
|
||||||
<q-btn
|
<q-btn label="Reset" type="reset" />
|
||||||
label="Reset"
|
<q-btn color="primary" type="submit" label="Speichern" />
|
||||||
type="reset"
|
|
||||||
/>
|
|
||||||
<q-btn
|
|
||||||
color="primary"
|
|
||||||
type="submit"
|
|
||||||
label="Speichern"
|
|
||||||
/>
|
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
</q-form>
|
</q-form>
|
||||||
</template>
|
</template>
|
||||||
|
@ -127,7 +114,7 @@ import {
|
||||||
computed,
|
computed,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
ref,
|
ref,
|
||||||
onBeforeMount,
|
onBeforeMount
|
||||||
} from '@vue/composition-api';
|
} from '@vue/composition-api';
|
||||||
import { Store } from 'vuex';
|
import { Store } from 'vuex';
|
||||||
import { StateInterface } from 'src/store';
|
import { StateInterface } from 'src/store';
|
||||||
|
@ -145,17 +132,17 @@ export default defineComponent({
|
||||||
components: { IsoDateInput: IsoDateInput },
|
components: { IsoDateInput: IsoDateInput },
|
||||||
props: {
|
props: {
|
||||||
user: {
|
user: {
|
||||||
required: true,
|
required: true
|
||||||
},
|
},
|
||||||
newUser: {
|
newUser: {
|
||||||
default: false,
|
default: false
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
setup(props: Props, { root, emit }) {
|
setup(props: Props, { root, emit }) {
|
||||||
const store = <Store<StateInterface>>root.$store;
|
const store = <Store<StateInterface>>root.$store;
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
store.dispatch('user/getRoles', false).catch((error) => {
|
store.dispatch('user/getRoles', false).catch(error => {
|
||||||
console.warn(error);
|
console.warn(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -169,7 +156,7 @@ export default defineComponent({
|
||||||
const oldUser = computed(() => {
|
const oldUser = computed(() => {
|
||||||
if (isCurrentUser.value) return <FG.User>store.state.user.currentUser;
|
if (isCurrentUser.value) return <FG.User>store.state.user.currentUser;
|
||||||
else
|
else
|
||||||
return store.state.user.users.filter((user) => {
|
return store.state.user.users.filter(user => {
|
||||||
user.userid === props.user?.userid;
|
user.userid === props.user?.userid;
|
||||||
})[0];
|
})[0];
|
||||||
});
|
});
|
||||||
|
@ -182,13 +169,13 @@ export default defineComponent({
|
||||||
message: 'Datei zu groß oder keine gültige Bilddatei.',
|
message: 'Datei zu groß oder keine gültige Bilddatei.',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
progress: true,
|
progress: true,
|
||||||
actions: [{ icon: 'mdi-close', color: 'white' }],
|
actions: [{ icon: 'mdi-close', color: 'white' }]
|
||||||
});
|
});
|
||||||
avatar.value = [];
|
avatar.value = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const allRoles = computed(() =>
|
const allRoles = computed(() =>
|
||||||
store.state.user.roles.map((role) => role.name)
|
store.state.user.roles.map(role => role.name)
|
||||||
);
|
);
|
||||||
const password = ref('');
|
const password = ref('');
|
||||||
const new_password = ref('');
|
const new_password = ref('');
|
||||||
|
@ -199,20 +186,24 @@ export default defineComponent({
|
||||||
if (typeof changed.birthday === 'string')
|
if (typeof changed.birthday === 'string')
|
||||||
changed.birthday = new Date(changed.birthday);
|
changed.birthday = new Date(changed.birthday);
|
||||||
changed = Object.assign(changed, {
|
changed = Object.assign(changed, {
|
||||||
password: password.value,
|
password: password.value
|
||||||
});
|
});
|
||||||
if (new_password.value != '') {
|
if (new_password.value != '') {
|
||||||
changed = Object.assign(changed, {
|
changed = Object.assign(changed, {
|
||||||
new_password: new_password.value,
|
new_password: new_password.value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
emit('update:user', changed);
|
emit('update:user', changed);
|
||||||
if (avatar.value && avatar.value.length > 0)
|
|
||||||
|
if (
|
||||||
|
avatar.value &&
|
||||||
|
(avatar.value.length > 0 || avatar.value instanceof File)
|
||||||
|
)
|
||||||
store
|
store
|
||||||
.dispatch('user/uploadAvatar', {
|
.dispatch('user/uploadAvatar', {
|
||||||
user: changed,
|
user: changed,
|
||||||
file: avatar.value,
|
file: avatar.value
|
||||||
})
|
})
|
||||||
.catch((response: Response) => {
|
.catch((response: Response) => {
|
||||||
if (response && response.status == 400) {
|
if (response && response.status == 400) {
|
||||||
|
@ -270,8 +261,8 @@ export default defineComponent({
|
||||||
notEmpty,
|
notEmpty,
|
||||||
isUseridUsed,
|
isUseridUsed,
|
||||||
save,
|
save,
|
||||||
reset,
|
reset
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -34,7 +34,6 @@ const mutations: MutationTree<UserStateInterface> = {
|
||||||
setCurrentUser(state, data: FG.User) {
|
setCurrentUser(state, data: FG.User) {
|
||||||
if (typeof data.birthday === 'string')
|
if (typeof data.birthday === 'string')
|
||||||
data.birthday = new Date(data.birthday);
|
data.birthday = new Date(data.birthday);
|
||||||
console.warn(data.birthday);
|
|
||||||
SessionStorage.set('currentUser', data);
|
SessionStorage.set('currentUser', data);
|
||||||
state.currentUser = data;
|
state.currentUser = data;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue