From 7ac8cbc87c9794c9f5c2a982e50cea4aaa8b48af Mon Sep 17 00:00:00 2001 From: puri-ph4tt Date: Mon, 5 Feb 2024 17:57:41 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=9F=E0=B8=B1=E0=B8=87=E0=B9=8C=E0=B8=8A=E0=B8=B1=E0=B8=99?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B8=B0=20api=20=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=AB=E0=B8=B1?= =?UTF-8?q?=E0=B8=A7=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=9B=E0=B8=B1=E0=B8=8D?= =?UTF-8?q?=E0=B8=AB=E0=B8=B2=20(support)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/support/api.support.ts | 14 ++++- src/modules/00_support/store/Main.ts | 49 +++++++++------ src/modules/00_support/views/MainPage.vue | 73 +++++++++++++++++++---- 3 files changed, 105 insertions(+), 31 deletions(-) diff --git a/src/api/support/api.support.ts b/src/api/support/api.support.ts index e7308ed..a17161e 100644 --- a/src/api/support/api.support.ts +++ b/src/api/support/api.support.ts @@ -4,9 +4,21 @@ const support = `${env.API_URL_SUPPORT}`; export default { supportMessageStatus: (id: string) => `${support}/issue/${id}/message-status`, + supportMessage: (id: string, pageSize: number = 999, page: number = 1) => `${support}/issue/${id}/message?pageSize=${pageSize}&page=${page}`, + supportIssueUserId: (userId: string) => `${support}/issue?userId=${userId}`, - supportIssue: `${support}/issue`, + + supportIssue: (pageSize: number = 999, page: number = 1) => + `${support}/issue?pageSize=${pageSize}&page=${page}`, + + supportSearchIssue: ( + search: string, + pageSize: number = 999, + page: number = 1 + ) => `${support}/issue?pageSize=${pageSize}&page=${page}&search=${search}`, + supportIssueCategory: `${support}/issue-category`, + supportNewIssue: `${support}/issue`, }; diff --git a/src/modules/00_support/store/Main.ts b/src/modules/00_support/store/Main.ts index e0aa050..57e8ed4 100644 --- a/src/modules/00_support/store/Main.ts +++ b/src/modules/00_support/store/Main.ts @@ -18,6 +18,7 @@ import { useCounterMixin } from "@/stores/mixin"; export const useSupportStore = defineStore("supportServiceStore", () => { const { showLoader, hideLoader, messageError } = useCounterMixin(); const $q = useQuasar(); + const icon = ref("mdi-account-check"); const userId = ref(keycloak.subject); const userStatus = ref([]); const issue = ref(); @@ -27,7 +28,7 @@ export const useSupportStore = defineStore("supportServiceStore", () => { const currentIssue = ref(""); const currentTitle = ref(""); const items = ref([{}, {}, {}, {}, {}, {}, {}]); - const scrollTargetRef = ref(); + const scrollContainer = ref(); const socket = io("http://192.168.1.10:3000/", { auth: { token: keycloak.token }, @@ -67,26 +68,16 @@ export const useSupportStore = defineStore("supportServiceStore", () => { }); socket.on("message", (r) => { - message.value?.result.message.push({ - id: r.id, - fromUserId: r.fromUserId, - fromUserName: r.fromUserName, - createdAt: r.createdAt, - updatedAt: r.updatedAt, - content: r.content, - read: r.read, - issueId: r.issueId, - }); - socket.emit("mark-read", { issueId: currentIssue.value }); + message.value?.result.message.push(r); + if (issue.value) { issue.value.result = issue.value.result.map((v) => { - if (v.id === r.issueId) { - v.lastMessage = r.content; - } + if (v.id === r.issueId) v.lastMessage = r.content; return v; }); } - + socket.emit("mark-read", { issueId: currentIssue.value }); + scrollToEnd(); // console.log(r.id); // console.log(message.value?.result.message); }); @@ -101,10 +92,17 @@ export const useSupportStore = defineStore("supportServiceStore", () => { // console.log("event(read):", messageStatus.value); }); + function scrollToEnd(position: Number = 1) { + setTimeout(() => { + scrollContainer.value?.setScrollPercentage("vertical", position); + }, 150); + } + function sendMessage(content: string, to: string) { // console.log(content); // console.log(to); socket.emit("message", { to, content }); + scrollToEnd(); } async function fetchMessageStatus(issueId: string) { @@ -138,6 +136,7 @@ export const useSupportStore = defineStore("supportServiceStore", () => { message.value?.result.message.reverse(); socket.emit("join-issue", { issueId }); socket.emit("mark-read", { issueId }); + scrollToEnd(); } } @@ -186,7 +185,7 @@ export const useSupportStore = defineStore("supportServiceStore", () => { }; const res = await http - .post(config.API.supportIssue, requestBody) + .post(config.API.supportNewIssue, requestBody) .catch((err) => { messageError($q, err); }) @@ -200,6 +199,18 @@ export const useSupportStore = defineStore("supportServiceStore", () => { } } + async function searchIssue(searchData: string) { + const res = await http + .get(config.API.supportSearchIssue(searchData)) + .catch((err) => { + messageError($q, err); + }); + if (res && res.data) { + issue.value = res.data; + // console.log(issue.value); + } + } + return { userId, issue, @@ -215,8 +226,10 @@ export const useSupportStore = defineStore("supportServiceStore", () => { fetchMessage, sendMessage, newIssue, - scrollTargetRef, + searchIssue, items, socket, + scrollContainer, + icon, }; }); diff --git a/src/modules/00_support/views/MainPage.vue b/src/modules/00_support/views/MainPage.vue index 26a8aa1..1471c1c 100644 --- a/src/modules/00_support/views/MainPage.vue +++ b/src/modules/00_support/views/MainPage.vue @@ -1,13 +1,31 @@