แก้ไข บัค store , ปรับ component รูปภาพ

This commit is contained in:
Thanit Konmek 2023-08-04 12:29:38 +07:00
parent b663eedb09
commit c53e6b5359
5 changed files with 160 additions and 82 deletions

View file

@ -66,9 +66,9 @@
<div class="row items-center text-dark q-ml-md"> <div class="row items-center text-dark q-ml-md">
<div class="column"> <div class="column">
<div class="text-bold q-pb-xs text-name"> <div class="text-bold q-pb-xs text-name">
{{ props.fullName }} {{ fullname }}
</div> </div>
<div>{{ props.position }}</div> <div>{{ position }}</div>
</div> </div>
</div> </div>
<q-space /> <q-space />
@ -164,22 +164,14 @@
</q-dialog> </q-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
const props = defineProps({ const props = defineProps({
fullName: {
type: String,
default: "ชื่อ สกุล",
required: true,
},
position: {
type: String,
default: "ตำแหน่ง",
required: true,
},
fetchData: { fetchData: {
type: Function, type: Function,
default: () => console.log("not function"), default: () => console.log("not function"),
@ -200,15 +192,33 @@ const props = defineProps({
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { date2Thai, dateToISO, messageError, dialogMessage, success } = mixin; const {
date2Thai,
dateToISO,
messageError,
dialogMessage,
success,
showLoader,
hideLoader,
} = mixin;
const route = useRoute();
const router = useRouter(); const router = useRouter();
const fullname = ref<string>("");
const position = ref<string>("");
const imageUrl = ref<any>(null); const imageUrl = ref<any>(null);
const inputImage = ref<any>(null); const inputImage = ref<any>(null);
const dialogImage = ref<boolean>(false);
const images = ref<any>([]);
const activeImage = ref<any | null>(null); const activeImage = ref<any | null>(null);
const profileId = ref<string>("");
const dialogImage = ref<boolean>(false);
const images = ref<any>([]);
onMounted(async () => {
await fetchData();
});
const closeImage = () => { const closeImage = () => {
dialogImage.value = false; dialogImage.value = false;
@ -218,7 +228,7 @@ const clickImage = async () => {
// *************************************************************************************************** // ***************************************************************************************************
// ****************** fetch data ****************** // ****************** fetch data ******************
// *************************************************************************************************** // ***************************************************************************************************
await fetchAvatarHistory();
dialogImage.value = true; dialogImage.value = true;
}; };
@ -227,14 +237,18 @@ const uploadImage = async (e: any) => {
if (input.length > 0) { if (input.length > 0) {
const formData = new FormData(); const formData = new FormData();
formData.append("FileData", input[0]); formData.append("FileData", input[0]);
await props.fetchUpload(profileId.value, formData).then(async () => { showLoader();
await props.fetchData(); await http
closeImage(); .post(config.API.profileAvatarId(route.params.id.toString()), formData)
}); .then((res) => {})
// *************************************************************************************************** .catch((e) => {
// ****************** function props formData ****************** messageError($q, e);
// ****************** finally fetch data,dialogImage.value = false ****************** })
// *************************************************************************************************** .finally(async () => {
await fetchData();
dialogImage.value = false;
});
return;
} }
}; };
@ -253,7 +267,20 @@ const selectAvatarHistory = async () => {
); );
return; return;
} }
await props.fetchSave(profileId.value); showLoader();
await http
.put(config.API.profileAvatarId(route.params.id.toString()), {
avatar: activeImage.value.avatarId,
})
.then((res) => {
dialogImage.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
// *************************************************************************************************** // ***************************************************************************************************
// ****************** fetch data ID ****************** // ****************** fetch data ID ******************
// *************************************************************************************************** // ***************************************************************************************************
@ -283,14 +310,77 @@ const deletePhoto = async (id: string) => {
}; };
const fetchDataDelete = async (id: string) => { const fetchDataDelete = async (id: string) => {
await props.fetchDelete(id).then(async () => { showLoader();
await props.fetchData(); await http
await clickImage(); .delete(config.API.profileAvatarHistoryId(id))
}); .then((res) => {
// *************************************************************************************************** success($q, "ลบรูปภาพสำเร็จ");
// ****************** fetch delete ****************** })
// ****************** finally fetch data,clickImage() ****************** .catch((e) => {
// *************************************************************************************************** messageError($q, e);
})
.finally(async () => {
await fetchData();
await clickImage();
// dialogImage.value = false;
});
};
const fetchData = async () => {
showLoader();
await http
.get(config.API.profileAvatarId(route.params.id.toString()))
.then((res) => {
const data = res.data.result;
// console.log(data);
fullname.value = data.fullname;
imageUrl.value = data.avatar;
position.value = data.position;
// profileType.value = data.profileType;
// employeeClass.value =
// data.employeeClass == null ? "" : data.employeeClass;
// const reason = reasonOptions.value.filter(
// (r: DataOption) => r.id == data.leaveReason
// );
// if (reason.length > 0) {
// leaveReason.value = ` (: ${reason[0].name})`;
// } else {
// leaveReason.value = "";
// }
// reasonStatus.value = reason.length > 0 ? true : false;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
const fetchAvatarHistory = async () => {
showLoader();
await http
.get(config.API.profileAvatarHistoryId(route.params.id.toString()))
.then((res) => {
const data = res.data.result;
console.log(data);
images.value = [];
data.map((e: any) => {
images.value.push({
id: e.id,
avatar: e.avatar,
avatarId: e.avatarId,
createdDate: new Date(e.createdDate),
isActive: e.isActive,
});
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}; };
const imageClass = (n: any) => { const imageClass = (n: any) => {

View file

@ -115,11 +115,14 @@ import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import type { treeTab } from "@/modules/04_registry/interface/index/Main"; import type { treeTab } from "@/modules/04_registry/interface/index/Main";
import type { ResponseTree } from "@/modules/02_organizational/interface/response/Mapping"; import type { ResponseTree } from "@/modules/02_organizational/interface/response/Mapping";
import { useDataStore } from "@/stores/data";
const dataStore = useDataStore();
const $q = useQuasar(); // show dialog const $q = useQuasar(); // show dialog
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
const { selectedReport2, expandedReport2, changeTreeReport2 } = dataStore;
const { date2Thai, success, dateToISO, modalError, showLoader, hideLoader } = const { date2Thai, success, dateToISO, modalError, showLoader, hideLoader } =
mixin; mixin;
const filter = ref<string>(""); //search data table const filter = ref<string>(""); //search data table
@ -279,14 +282,9 @@ const nodeTree = async () => {
const data = res.data.result; const data = res.data.result;
nodesTree.value = data; nodesTree.value = data;
if (data.length > 0) { if (data.length > 0) {
selected.value = selected.value = selectedReport2 == "" ? data[0].id : selectedReport2;
dataStore.selectedReport2 == ""
? data[0].id
: dataStore.selectedReport2;
expanded.value = expanded.value =
dataStore.expandedReport2.length == 0 expandedReport2.length == 0 ? [data[0].id] : expandedReport2;
? [data[0].id]
: dataStore.expandedReport2;
} }
}) })
.catch((e: any) => {}) .catch((e: any) => {})
@ -301,7 +299,7 @@ const onSelected = async (id: string) => {
}; };
const clickTree = () => { const clickTree = () => {
dataStore.changeTreeReport2(expanded.value, selected.value); changeTreeReport2(expanded.value, selected.value);
}; };
const onHistory = async () => { const onHistory = async () => {

View file

@ -144,11 +144,13 @@ import ProfileTable from "@/modules/04_registry/components/TableProfile.vue";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
// import { jsontoexcel } from "vue-table-to-excel"; import { useDataStore } from "@/stores/data";
const dataStore = useDataStore();
const $q = useQuasar(); const $q = useQuasar();
const store = useProfileDataStore(); const store = useProfileDataStore();
const { profileData, changeProfileColumns } = store; const { profileData, changeProfileColumns } = store;
const { changeTreeRegister, selectedRegister, expandedRegister } = dataStore;
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { date2Thai, messageError, typeRetire, showLoader, hideLoader } = mixin; const { date2Thai, messageError, typeRetire, showLoader, hideLoader } = mixin;
@ -1162,7 +1164,7 @@ const onSelected = async (id: string) => {
}; };
const clickTree = () => { const clickTree = () => {
dataStore.changeTreeRegister(expanded.value, selected.value); changeTreeRegister(expanded.value, selected.value);
}; };
const nodeTree = async () => { const nodeTree = async () => {
@ -1173,14 +1175,9 @@ const nodeTree = async () => {
const data = res.data.result; const data = res.data.result;
nodesTree.value = data; nodesTree.value = data;
if (data.length > 0) { if (data.length > 0) {
selected.value = selected.value = selectedRegister == "" ? data[0].id : selectedRegister;
dataStore.selectedRegister == ""
? data[0].id
: dataStore.selectedRegister;
expanded.value = expanded.value =
dataStore.expandedRegister.length == 0 expandedRegister.length == 0 ? [data[0].id] : expandedRegister;
? [data[0].id]
: dataStore.expandedRegister;
} }
}) })
.catch((e: any) => { .catch((e: any) => {

View file

@ -5,7 +5,12 @@
<Information v-model:statusEdit="statusEdit" :statusAdd="false" /> <Information v-model:statusEdit="statusEdit" :statusAdd="false" />
</div> </div>
<div id="government" name="16" class="row col-12 q-mt-md"> <div id="government" name="16" class="row col-12 q-mt-md">
<Government v-model:statusEdit="statusEdit" :statusAdd="false" /> <Government
v-model:statusEdit="statusEdit"
:statusAdd="false"
profileType="test"
employeeClass="test"
/>
</div> </div>
<div id="address" name="17" class="row col-12 q-mt-md"> <div id="address" name="17" class="row col-12 q-mt-md">
<Address v-model:statusEdit="statusEdit" :statusAdd="false" /> <Address v-model:statusEdit="statusEdit" :statusAdd="false" />
@ -14,7 +19,7 @@
<Family v-model:statusEdit="statusEdit" :statusAdd="false" /> <Family v-model:statusEdit="statusEdit" :statusAdd="false" />
</div> </div>
<div id="certicate" name="15" class="row col-12 q-mt-md"> <div id="certicate" name="15" class="row col-12 q-mt-md">
<Certicate v-model:statusEdit="statusEdit" /> <Certicate v-model:statusEdit="statusEdit" profileType="test" />
</div> </div>
<div id="education" name="2" class="row col-12 q-mt-md"> <div id="education" name="2" class="row col-12 q-mt-md">
<EducationVue v-model:statusEdit="statusEdit" /> <EducationVue v-model:statusEdit="statusEdit" />
@ -70,6 +75,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
import Image from "@/components/information/Image.vue"; import Image from "@/components/information/Image.vue";
import Information from "@/components/information/Information.vue"; import Information from "@/components/information/Information.vue";
import Government from "@/components/information/Government.vue"; import Government from "@/components/information/Government.vue";

View file

@ -282,10 +282,10 @@ const columns2 = ref<QTableProps["columns"]>([
}, },
]); ]);
const openModalTree = (pid: string) => { const openModalTree = (id: string) => {
modalTree.value = true; personalId.value = id;
personalId.value = pid;
personal.value = []; personal.value = [];
modalTree.value = true;
}; };
const closeModalTree = async () => { const closeModalTree = async () => {
@ -293,8 +293,10 @@ const closeModalTree = async () => {
modalTree.value = false; modalTree.value = false;
}; };
const nextPage = (id: string) => { const nextPage = (row: any) => {
router.push(`/receive/${id}`); router.push({
path: `/receive/${row.personalId}`,
});
}; };
</script> </script>
<template> <template>
@ -367,57 +369,42 @@ const nextPage = (id: string) => {
<q-th v-for="col in props.cols" :key="col.name" :props="props"> <q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span> <span class="text-weight-medium">{{ col.label }}</span>
</q-th> </q-th>
<q-th auto-width />
</q-tr> </q-tr>
</template> </template>
<template v-slot:body="props"> <template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td <q-td key="no" :props="props" @click="nextPage(props.row)">
key="no"
:props="props"
@click="nextPage(props.row.personalId)"
>
{{ props.rowIndex + 1 }} {{ props.rowIndex + 1 }}
</q-td> </q-td>
<q-td <q-td
key="fullname" key="fullname"
:props="props" :props="props"
@click="nextPage(props.row.personalId)" @click="nextPage(props.row)"
> >
{{ props.row.fullname }} {{ props.row.fullname }}
</q-td> </q-td>
<q-td <q-td
key="position" key="position"
:props="props" :props="props"
@click="nextPage(props.row.personalId)" @click="nextPage(props.row)"
> >
{{ props.row.position }} {{ props.row.position }}
</q-td> </q-td>
<q-td <q-td
key="positionLevel" key="positionLevel"
:props="props" :props="props"
@click="nextPage(props.row.personalId)" @click="nextPage(props.row)"
> >
{{ props.row.positionLevel }} {{ props.row.positionLevel }}
</q-td> </q-td>
<q-td <q-td key="oc" :props="props" @click="nextPage(props.row)">
key="oc"
:props="props"
@click="nextPage(props.row.personalId)"
>
{{ props.row.oc }} {{ props.row.oc }}
</q-td> </q-td>
<q-td <q-td key="agency" :props="props" @click="nextPage(props.row)">
key="agency"
:props="props"
@click="nextPage(props.row.personalId)"
>
{{ props.row.agency }} {{ props.row.agency }}
</q-td> </q-td>
<q-td <q-td key="status" :props="props" @click="nextPage(props.row)">
key="status"
:props="props"
@click="nextPage(props.row.personalId)"
>
{{ props.row.status }} {{ props.row.status }}
</q-td> </q-td>
<q-td auto-width> <q-td auto-width>