Add default profile button

This commit is contained in:
marzban-dev
2026-04-23 16:08:52 +03:30
parent 476507a7bd
commit 00236c746b
2 changed files with 46 additions and 25 deletions
@@ -12,7 +12,7 @@ type Props = {
};
type Emits = {
"update:modelValue": [value: File];
"update:modelValue": [value: File | null];
"update:isShow": [value: boolean];
};
@@ -59,8 +59,7 @@ const { isPending: updateAccountIsPending } = useUpdateAccount();
// computed
const currentProfile = computed({
get: () =>
!!modelValue.value ? URL.createObjectURL(modelValue.value) : null,
get: () => (!!modelValue.value ? URL.createObjectURL(modelValue.value) : null),
set: (value: File) => emit("update:modelValue", value),
});
@@ -81,6 +80,15 @@ onFileDialogChange((files: any) => {
emit("update:modelValue", file);
resetFileDialog();
});
const resetAvatarFile = async () => {
const response = await fetch("/img/default-avatar.jpeg");
const blob = await response.blob();
const file = new File([blob], "default-avatar.jpeg", { type: blob.type });
emit("update:modelValue", file);
resetFileDialog();
};
</script>
<template>
@@ -92,19 +100,17 @@ onFileDialogChange((files: any) => {
contectClass="w-full max-lg:container lg:!w-[30vw]"
>
<template #trigger>
<button
class="bg-black text-slate-100 rounded-full p-2 flex-center absolute -bottom-0 -right-0"
>
<Icon name="bi:pencil" class="**:fill-slate-100" size="12" />
<button class="bg-black text-slate-100 rounded-full p-2 flex-center absolute -bottom-0 -right-0">
<Icon
name="bi:pencil"
class="**:fill-slate-100"
size="12"
/>
</button>
</template>
<template #content>
<div
class="w-full flex flex-col-reverse items-center justify-between py-10 gap-10 px-4"
>
<div
class="flex items-center justify-center w-full flex-wrap gap-4 max-w-[500px]"
>
<div class="w-full flex flex-col-reverse items-center justify-between py-10 gap-10 px-4">
<div class="flex items-center justify-center w-full flex-wrap gap-4 max-w-[500px]">
<button
v-for="(avatar, index) in avatars"
:key="index"
@@ -143,6 +149,20 @@ onFileDialogChange((files: any) => {
class="!size-24 lg:!size-32"
iconClass="!text-xl lg:!text-2xl"
/>
<div class="flex items-center gap-4">
<Button
class="rounded-full w-[8rem] bg-red-500"
@click="resetAvatarFile"
:loading="updateAccountIsPending"
size="md"
>
<Icon
v-if="updateAccountIsPending"
name="bi:trash"
/>
<span v-else>حذف عکس</span>
</Button>
<Button
class="rounded-full w-[8rem]"
@click="openFileDialog"
@@ -157,6 +177,7 @@ onFileDialogChange((files: any) => {
</Button>
</div>
</div>
</div>
</template>
</Modal>
</template>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB