เพิ่มฟัง์ชันและ api การค้นหาหัวข้อปัญหา (support)
This commit is contained in:
parent
12ac44c7c2
commit
7ac8cbc87c
3 changed files with 105 additions and 31 deletions
|
|
@ -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<string>("mdi-account-check");
|
||||
const userId = ref<string | undefined>(keycloak.subject);
|
||||
const userStatus = ref<SupportUserStatus[]>([]);
|
||||
const issue = ref<SupportIssueResponse>();
|
||||
|
|
@ -27,7 +28,7 @@ export const useSupportStore = defineStore("supportServiceStore", () => {
|
|||
const currentIssue = ref<string>("");
|
||||
const currentTitle = ref<string>("");
|
||||
const items = ref<any>([{}, {}, {}, {}, {}, {}, {}]);
|
||||
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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue