GUI chat
This commit is contained in:
parent
f25a439804
commit
0a98d96d38
9 changed files with 6862 additions and 9 deletions
|
|
@ -1,10 +1,86 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { io } from "socket.io-client";
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import type {
|
||||
SupportMessageResponse,
|
||||
SupportIssueResponse,
|
||||
} from "@/modules/00_support/interface/index/Main";
|
||||
import keycloak from "@/plugins/keycloak";
|
||||
|
||||
export const useEvalutuonStore = defineStore("supportServiceStore", () => {
|
||||
const index = ref<number>(0);
|
||||
export const useSupportStore = defineStore("supportServiceStore", () => {
|
||||
const socket = io("http://192.168.1.10:3000/", {
|
||||
auth: { token: keycloak.token },
|
||||
});
|
||||
|
||||
socket.on("users", (users) => {
|
||||
// console.log(users);
|
||||
});
|
||||
|
||||
socket.on("message", (r) => {
|
||||
console.log(r);
|
||||
});
|
||||
const { showLoader, hideLoader } = useCounterMixin();
|
||||
|
||||
const userId = ref<string>(keycloak.subject);
|
||||
const issue = ref<SupportIssueResponse>();
|
||||
const message = ref<SupportMessageResponse>();
|
||||
const items = ref<string>([{}, {}, {}, {}, {}, {}, {}]);
|
||||
const scrollTargetRef = ref();
|
||||
|
||||
function sendMessage(content: string, to: string) {
|
||||
console.log(content);
|
||||
console.log(to);
|
||||
socket.emit("message", { to, content });
|
||||
}
|
||||
|
||||
async function fetchMessage(issueId: string) {
|
||||
showLoader();
|
||||
const res = await http
|
||||
.get(config.API.supportMessage(issueId))
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
if (res && res.data) {
|
||||
message.value = res.data;
|
||||
|
||||
console.log(res.data);
|
||||
socket.emit("join-issue", { issueId });
|
||||
socket.emit("mark-read", { issueId });
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchIssue() {
|
||||
showLoader();
|
||||
|
||||
const res = await http
|
||||
.get(config.API.supportIssue)
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
|
||||
if (res && res.data) {
|
||||
issue.value = res.data;
|
||||
console.log(JSON.stringify(res.data, null, -2));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
index,
|
||||
userId,
|
||||
issue,
|
||||
message,
|
||||
fetchIssue,
|
||||
fetchMessage,
|
||||
sendMessage,
|
||||
scrollTargetRef,
|
||||
items,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue