fix(01): edit image profile
This commit is contained in:
parent
e9db12c3cb
commit
e34f100138
1 changed files with 34 additions and 43 deletions
|
|
@ -23,7 +23,6 @@ import FormBranchInformation from 'components/01_branch-management/FormBranchInf
|
||||||
import FormLocation from 'components/01_branch-management/FormLocation.vue';
|
import FormLocation from 'components/01_branch-management/FormLocation.vue';
|
||||||
import FormQr from 'components/01_branch-management/FormQr.vue';
|
import FormQr from 'components/01_branch-management/FormQr.vue';
|
||||||
import FormBranchContact from 'components/01_branch-management/FormBranchContact.vue';
|
import FormBranchContact from 'components/01_branch-management/FormBranchContact.vue';
|
||||||
import FormImage from 'components/01_branch-management/FormImage.vue';
|
|
||||||
import DrawerInfo from 'components/DrawerInfo.vue';
|
import DrawerInfo from 'components/DrawerInfo.vue';
|
||||||
import InfoForm from 'components/02_personnel-management/InfoForm.vue';
|
import InfoForm from 'components/02_personnel-management/InfoForm.vue';
|
||||||
import TreeCompoent from 'src/components/TreeCompoent.vue';
|
import TreeCompoent from 'src/components/TreeCompoent.vue';
|
||||||
|
|
@ -103,32 +102,14 @@ const formMenuIcon = ref<{ icon: string; color: string; bgColor: string }[]>([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const refImageUpload = ref();
|
||||||
const isImageEdit = ref(false);
|
const isImageEdit = ref(false);
|
||||||
const profileFileImg = ref<File | null>(null);
|
const profileFileImg = ref<File | undefined>(undefined);
|
||||||
const imageUrl = ref<string | null>('');
|
const imageUrl = ref<string>('');
|
||||||
|
const prevImageUrl = ref<string>('');
|
||||||
const currentNode = ref<BranchWithChildren>();
|
const currentNode = ref<BranchWithChildren>();
|
||||||
const imageDialog = ref(false);
|
const imageDialog = ref(false);
|
||||||
|
|
||||||
const inputFileImg = (() => {
|
|
||||||
const element = document.createElement('input');
|
|
||||||
element.type = 'file';
|
|
||||||
element.accept = 'image/*';
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.addEventListener('load', () => {
|
|
||||||
if (typeof reader.result === 'string') imageUrl.value = reader.result;
|
|
||||||
});
|
|
||||||
|
|
||||||
element.addEventListener('change', () => {
|
|
||||||
profileFileImg.value = element.files?.[0];
|
|
||||||
if (profileFileImg.value) {
|
|
||||||
reader.readAsDataURL(profileFileImg.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return element;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const profileFile = ref<File | undefined>(undefined);
|
const profileFile = ref<File | undefined>(undefined);
|
||||||
const qrCodeimageUrl = ref<string | null>('');
|
const qrCodeimageUrl = ref<string | null>('');
|
||||||
|
|
||||||
|
|
@ -311,6 +292,7 @@ async function fetchBranchById(id: string) {
|
||||||
if (res) {
|
if (res) {
|
||||||
qrCodeimageUrl.value = res.qrCodeImageUrl;
|
qrCodeimageUrl.value = res.qrCodeImageUrl;
|
||||||
imageUrl.value = res.imageUrl;
|
imageUrl.value = res.imageUrl;
|
||||||
|
prevImageUrl.value = res.imageUrl;
|
||||||
|
|
||||||
formData.value = {
|
formData.value = {
|
||||||
headOfficeId: res.headOfficeId,
|
headOfficeId: res.headOfficeId,
|
||||||
|
|
@ -337,7 +319,7 @@ async function fetchBranchById(id: string) {
|
||||||
|
|
||||||
function clearData() {
|
function clearData() {
|
||||||
formData.value = structuredClone(defaultFormData);
|
formData.value = structuredClone(defaultFormData);
|
||||||
imageUrl.value = null;
|
imageUrl.value = '';
|
||||||
qrCodeimageUrl.value = null;
|
qrCodeimageUrl.value = null;
|
||||||
currentEdit.value = {
|
currentEdit.value = {
|
||||||
id: '',
|
id: '',
|
||||||
|
|
@ -348,6 +330,7 @@ function clearData() {
|
||||||
|
|
||||||
async function undo() {
|
async function undo() {
|
||||||
formType.value = 'view';
|
formType.value = 'view';
|
||||||
|
imageUrl.value = prevImageUrl.value;
|
||||||
formData.value = prevFormData.value;
|
formData.value = prevFormData.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -493,8 +476,8 @@ async function onSubmit() {
|
||||||
);
|
);
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
|
if (!imageDialog.value) modalDrawer.value = false;
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
modalDrawer.value = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
|
|
@ -567,16 +550,16 @@ function handleHold(node: BranchWithChildren) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function openImageDialog(isEdit?: boolean) {
|
async function handleImageUpload(file: File | null, url: string | null) {
|
||||||
if (isEdit) isImageEdit.value = true;
|
if (formType.value === 'view') {
|
||||||
else isImageEdit.value = false;
|
formType.value = 'edit';
|
||||||
imageDialog.value = true;
|
await onSubmit();
|
||||||
}
|
formType.value = 'view';
|
||||||
|
}
|
||||||
function handleImageUpload(file: File | null, url: string | null) {
|
if (formType.value === 'edit') {
|
||||||
imageUrl.value = url;
|
await onSubmit();
|
||||||
|
}
|
||||||
imageDialog.value = false;
|
imageDialog.value = false;
|
||||||
// profileFileImg = file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -1448,21 +1431,25 @@ watch(currentHq, () => {
|
||||||
onSubmit();
|
onSubmit();
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:close="() => ((modal = false), (profileFileImg = null))"
|
:close="
|
||||||
|
() => (
|
||||||
|
(modal = false), (profileFileImg = undefined), (isImageEdit = false)
|
||||||
|
)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div class="q-mx-lg q-mt-lg">
|
<div class="q-mx-lg q-mt-lg">
|
||||||
<!-- title="บริษัทจ๊อบส์ เวิร์คเกอร์ เซอร์วิส จำกัด"
|
<!-- title="บริษัทจ๊อบส์ เวิร์คเกอร์ เซอร์วิส จำกัด"
|
||||||
caption="Jobs Worker Service Co., Ltd." -->
|
caption="Jobs Worker Service Co., Ltd." -->
|
||||||
<ProfileBanner
|
<ProfileBanner
|
||||||
active
|
active
|
||||||
|
v-model:cover-url="imageUrl"
|
||||||
:hideFade="imageUrl === '' || imageUrl === null"
|
:hideFade="imageUrl === '' || imageUrl === null"
|
||||||
:img="imageUrl || null"
|
:img="imageUrl || null"
|
||||||
:cover="imageUrl || null"
|
|
||||||
icon="mdi-office-building-outline"
|
icon="mdi-office-building-outline"
|
||||||
color="hsla(var(--pink-6-hsl)/1)"
|
color="hsla(var(--pink-6-hsl)/1)"
|
||||||
bgColor="hsla(var(--pink-6-hsl)/0.15)"
|
bgColor="hsla(var(--pink-6-hsl)/0.15)"
|
||||||
@view="openImageDialog"
|
@view="imageDialog = true"
|
||||||
@edit="inputFileImg.click()"
|
@edit="refImageUpload && refImageUpload.browse()"
|
||||||
:menu="formMenuIcon"
|
:menu="formMenuIcon"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1596,14 +1583,17 @@ watch(currentHq, () => {
|
||||||
:editData="() => drawerEdit()"
|
:editData="() => drawerEdit()"
|
||||||
:submit="() => onSubmit()"
|
:submit="() => onSubmit()"
|
||||||
:delete-data="() => triggerDelete(currentEdit.id)"
|
:delete-data="() => triggerDelete(currentEdit.id)"
|
||||||
:close="() => ((modalDrawer = false), flowStore.rotate())"
|
:close="
|
||||||
|
() => ((modalDrawer = false), flowStore.rotate(), (isImageEdit = false))
|
||||||
|
"
|
||||||
:statusBranch="formData.status"
|
:statusBranch="formData.status"
|
||||||
>
|
>
|
||||||
<InfoForm>
|
<InfoForm>
|
||||||
<div class="q-mx-lg q-mt-lg">
|
<div class="q-mx-lg q-mt-lg">
|
||||||
<ProfileBanner
|
<ProfileBanner
|
||||||
active
|
active
|
||||||
hideFade
|
v-model:cover-url="imageUrl"
|
||||||
|
:hideFade="imageUrl === '' || imageUrl === null"
|
||||||
:img="imageUrl || null"
|
:img="imageUrl || null"
|
||||||
:cover="imageUrl || null"
|
:cover="imageUrl || null"
|
||||||
:title="formData.name"
|
:title="formData.name"
|
||||||
|
|
@ -1611,8 +1601,8 @@ watch(currentHq, () => {
|
||||||
icon="mdi-office-building-outline"
|
icon="mdi-office-building-outline"
|
||||||
color="hsla(var(--pink-6-hsl)/1)"
|
color="hsla(var(--pink-6-hsl)/1)"
|
||||||
bgColor="hsla(var(--pink-6-hsl)/0.15)"
|
bgColor="hsla(var(--pink-6-hsl)/0.15)"
|
||||||
@view="openImageDialog"
|
@view="imageDialog = true"
|
||||||
@edit="inputFileImg.click()"
|
@edit="refImageUpload && refImageUpload.browse()"
|
||||||
:readonly="formType === 'view'"
|
:readonly="formType === 'view'"
|
||||||
:menu="formMenuIcon"
|
:menu="formMenuIcon"
|
||||||
/>
|
/>
|
||||||
|
|
@ -1872,8 +1862,9 @@ watch(currentHq, () => {
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
|
||||||
<ImageUploadDialog
|
<ImageUploadDialog
|
||||||
|
ref="refImageUpload"
|
||||||
v-model:dialogState="imageDialog"
|
v-model:dialogState="imageDialog"
|
||||||
v-model:file="profileFileImg"
|
v-model:file="profileFileImg as File"
|
||||||
v-model:image-url="imageUrl"
|
v-model:image-url="imageUrl"
|
||||||
:hiddenFooter="!isImageEdit"
|
:hiddenFooter="!isImageEdit"
|
||||||
clearButton
|
clearButton
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue