chore: sse配置文件关闭

This commit is contained in:
dap 2024-12-19 11:27:23 +08:00
parent 6183d22b20
commit d304e8a2a3
6 changed files with 28 additions and 13 deletions

View File

@ -21,5 +21,5 @@ VITE_GLOB_RSA_PRIVATE_KEY=MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAmc3CuP
# 客户端id
VITE_GLOB_APP_CLIENT_ID=e5cd7e4891bf95d1d19206ce24a7b32e
# 开启WEBSOCKET
VITE_GLOB_WEBSOCKET_ENABLE=false
# 开启SSE
VITE_GLOB_SSE_ENABLE=true

View File

@ -27,6 +27,6 @@ VITE_GLOB_RSA_PRIVATE_KEY=MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAmc3CuP
# 客户端id
VITE_GLOB_APP_CLIENT_ID=e5cd7e4891bf95d1d19206ce24a7b32e
# 开启WEBSOCKET
VITE_GLOB_WEBSOCKET_ENABLE=false
# 开启SSE
VITE_GLOB_SSE_ENABLE=true

View File

@ -4,7 +4,10 @@ import { useAppConfig } from '@vben/hooks';
import { requestClient } from '#/api/request';
const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD);
const { clientId, sseEnable } = useAppConfig(
import.meta.env,
import.meta.env.PROD,
);
export namespace AuthApi {
/**
@ -96,6 +99,12 @@ export function doLogout() {
* @returns void
*/
export function seeConnectionClose() {
/**
* sse
*/
if (!sseEnable) {
return;
}
return requestClient.get<void>('/resource/sse/close');
}

View File

@ -12,7 +12,7 @@ import { notification } from 'ant-design-vue';
import dayjs from 'dayjs';
import { defineStore } from 'pinia';
const { apiURL, clientId } = useAppConfig(
const { apiURL, clientId, sseEnable } = useAppConfig(
import.meta.env,
import.meta.env.PROD,
);
@ -40,6 +40,12 @@ export const useNotifyStore = defineStore(
* sse消息
*/
function startListeningMessage() {
/**
*
*/
if (!sseEnable) {
return;
}
const accessStore = useAccessStore();
const token = accessStore.accessToken;

View File

@ -21,7 +21,7 @@ export function useAppConfig(
VITE_GLOB_ENABLE_ENCRYPT,
VITE_GLOB_RSA_PRIVATE_KEY,
VITE_GLOB_RSA_PUBLIC_KEY,
VITE_GLOB_WEBSOCKET_ENABLE,
VITE_GLOB_SSE_ENABLE,
} = config;
return {
@ -34,7 +34,7 @@ export function useAppConfig(
rsaPrivateKey: VITE_GLOB_RSA_PRIVATE_KEY,
// RSA公钥
rsaPublicKey: VITE_GLOB_RSA_PUBLIC_KEY,
// 是否开启websocket
websocketEnable: VITE_GLOB_WEBSOCKET_ENABLE === 'true',
// 是否开启sse
sseEnable: VITE_GLOB_SSE_ENABLE === 'true',
};
}

View File

@ -18,8 +18,8 @@ export interface VbenAdminProAppConfigRaw {
VITE_GLOB_RSA_PRIVATE_KEY: string;
// RSA请求加密公钥
VITE_GLOB_RSA_PUBLIC_KEY: string;
// 是否开启websocket 注意从配置文件获取的类型为string
VITE_GLOB_WEBSOCKET_ENABLE: string;
// 是否开启sse 注意从配置文件获取的类型为string
VITE_GLOB_SSE_ENABLE: string;
}
export interface ApplicationConfig {
@ -33,8 +33,8 @@ export interface ApplicationConfig {
rsaPrivateKey: string;
// RSA请求加密公钥
rsaPublicKey: string;
// 是否开启websocket
websocketEnable: boolean;
// 是否开启sse
sseEnable: boolean;
}
declare global {