Merge branch 'develop'
This commit is contained in:
commit
815e88d475
4 changed files with 67 additions and 0 deletions
|
|
@ -1,4 +1,10 @@
|
|||
<script setup lang="ts">
|
||||
import { useSocketStore } from "@/stores/socket";
|
||||
import { onMounted } from "vue";
|
||||
|
||||
onMounted(() => {
|
||||
useSocketStore();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
7
src/api/socket.ts
Normal file
7
src/api/socket.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import env from "./index";
|
||||
|
||||
const socket = `${env.API_URI}/backup-socket`;
|
||||
|
||||
export default {
|
||||
socket,
|
||||
};
|
||||
|
|
@ -46,6 +46,9 @@ import command from "./api/05_command/api.command";
|
|||
/** API Webservices*/
|
||||
import webservices from "./api/06_webservices/api.webservices";
|
||||
|
||||
/** socket */
|
||||
import socket from "./api/socket";
|
||||
|
||||
// environment variables
|
||||
export const compettitivePanel = import.meta.env.VITE_COMPETITIVE_EXAM_PANEL;
|
||||
export const qualifyDisableExamPanel = import.meta.env
|
||||
|
|
@ -117,6 +120,9 @@ const API = {
|
|||
...command,
|
||||
/** webservices*/
|
||||
...webservices,
|
||||
|
||||
/** socket*/
|
||||
...socket,
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
|
|||
48
src/stores/socket.ts
Normal file
48
src/stores/socket.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { Notify } from "quasar";
|
||||
|
||||
import { io, Socket } from "socket.io-client";
|
||||
|
||||
import config from "@/app.config";
|
||||
import { getToken } from "@/plugins/auth";
|
||||
|
||||
interface sockeBackup {
|
||||
message: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
export const useSocketStore = defineStore("socket", () => {
|
||||
let socket: Socket;
|
||||
|
||||
async function init() {
|
||||
socket = io(new URL(config.API.socket).origin, {
|
||||
auth: { token: await getToken() },
|
||||
path: "/api/v1/backup-socket",
|
||||
});
|
||||
socket.on("backup-notification", (payload) => {
|
||||
let body: sockeBackup = JSON.parse(payload);
|
||||
notifyStatus(body.message, body.success);
|
||||
});
|
||||
}
|
||||
|
||||
function notifyStatus(message: string, success: boolean) {
|
||||
Notify.create({
|
||||
group: false,
|
||||
type: success ? "positive" : "negative",
|
||||
message: `${message}`,
|
||||
position: "top",
|
||||
timeout: 0,
|
||||
actions: [
|
||||
{
|
||||
icon: "close",
|
||||
color: "white",
|
||||
round: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
return {};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue