wujingjing
2025-01-13 50f171cf1cf0f3e4447b8e72b11a70c156466463
queryString
已修改2个文件
22 ■■■■■ 文件已修改
src/utils/sse/SSEClient.ts 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/sse/index.ts 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/sse/SSEClient.ts
@@ -38,8 +38,8 @@
        this.options = {
            retries: 3,
            retryDelay: 1000,
            timeout: 30000,
            autoReconnect: true,
            timeout: Infinity,
            autoReconnect: false,
            ...options,
        };
    }
@@ -53,7 +53,7 @@
        try {
            // 构建 URL 和参数
            const queryString = params ? `?${new URLSearchParams(params).toString()}` : '';
            const queryString = params && Object.values(params).length ? `?${new URLSearchParams(params).toString()}` : '';
            const fullUrl = `${this.url}${queryString}`;
            // 创建 AbortController 用于超时控制
src/utils/sse/index.ts
@@ -1,16 +1,12 @@
import { onMounted, onUnmounted } from 'vue';
import { SSEClient } from './SSEClient';
import { MAIN_URL } from '/@/constants';
// 创建实例
const sseClient = new SSEClient(
    '/events',
    {
        retries: 3,
        retryDelay: 1000,
        timeout: 30000,
        autoReconnect: true,
    `${MAIN_URL}events`,
    },
    {},
    {
        onMessage: (data) => {
            console.log('Received message:', data);
@@ -33,10 +29,8 @@
// 在 Vue 组件中使用
export function useSSE() {
    // 建立连接
    sseClient.connect({
        userId: 'xxx',
        sessionId: 'xxx',
    });
    sseClient.connect({});
    // onMounted(() => {
    //     // 建立连接