yuang-framework-ui-common 1.0.68 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { getShortUuid } from '../../../lib/utils/uuidUtils';
6
6
  const initFrameworkGroup = ({ frameworkGroupCode }) => {
7
7
  return new Promise((resolve) => {
8
8
  // prettier-ignore
9
- http.post(`${application.gatewayServerBaseUrl}/uims-api/core/framework-group/selectPage`, { code: frameworkGroupCode }).then((res) => {
9
+ http.post(`${application.gatewayServerBaseUrl}/uims-api/core/framework-group/selectPage`, { codeForEqual: frameworkGroupCode }).then((res) => {
10
10
  if (res.data.data.records.length == 0) {
11
11
  const formData = {
12
12
  id: '',
@@ -0,0 +1,135 @@
1
+ export type SseMessageHandler = (data: string, event?: MessageEvent) => void;
2
+ export type SseErrorHandler = (error: Event) => void;
3
+ export type SseOpenHandler = () => void;
4
+
5
+ export class FrameworkSseClient {
6
+ private eventSource: EventSource | null = null;
7
+ private url: string;
8
+ private messageHandler: SseMessageHandler;
9
+ private errorHandler?: SseErrorHandler;
10
+ private openHandler?: SseOpenHandler;
11
+ private reconnectInterval: number;
12
+ private maxReconnectAttempts: number;
13
+ private reconnectAttempts: number = 0;
14
+ private isManualClose: boolean = false;
15
+
16
+ /**
17
+ * 创建 SSE 客户端实例
18
+ * @param url SSE 服务端连接地址
19
+ * @param messageHandler 消息处理回调
20
+ * @param options 可选配置(重连间隔、最大重连次数等)
21
+ */
22
+ constructor(
23
+ url: string,
24
+ messageHandler: SseMessageHandler,
25
+ options?: {
26
+ reconnectInterval?: number;
27
+ maxReconnectAttempts?: number;
28
+ errorHandler?: SseErrorHandler;
29
+ openHandler?: SseOpenHandler;
30
+ }
31
+ ) {
32
+ this.url = url;
33
+ this.messageHandler = messageHandler;
34
+ this.reconnectInterval = options?.reconnectInterval || 3000; // 默认重连间隔 3 秒
35
+ this.maxReconnectAttempts = options?.maxReconnectAttempts || 10; // 默认最大重连 10 次
36
+ this.errorHandler = options?.errorHandler;
37
+ this.openHandler = options?.openHandler;
38
+
39
+ // 初始连接
40
+ this.connect();
41
+ }
42
+
43
+ /**
44
+ * 建立 SSE 连接
45
+ */
46
+ private connect(): void {
47
+ if (this.eventSource) {
48
+ this.eventSource.close();
49
+ }
50
+
51
+ try {
52
+ this.eventSource = new EventSource(this.url);
53
+
54
+ // 处理消息事件
55
+ this.eventSource.onmessage = (event) => {
56
+ this.messageHandler(event.data, event);
57
+ };
58
+
59
+ // 处理连接成功
60
+ this.eventSource.onopen = () => {
61
+ console.log('SSE 连接已建立');
62
+ this.reconnectAttempts = 0; // 重置重连次数
63
+ this.openHandler?.();
64
+ };
65
+
66
+ // 处理错误和重连
67
+ this.eventSource.onerror = (error) => {
68
+ console.error('SSE 连接错误:', error);
69
+ this.errorHandler?.(error);
70
+
71
+ // 不是手动关闭的情况才重连
72
+ if (!this.isManualClose) {
73
+ this.handleReconnect();
74
+ }
75
+ };
76
+ } catch (error) {
77
+ console.error('创建 SSE 连接失败:', error);
78
+ if (!this.isManualClose) {
79
+ this.handleReconnect();
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * 处理重连逻辑
86
+ */
87
+ private handleReconnect(): void {
88
+ if (this.reconnectAttempts >= this.maxReconnectAttempts) {
89
+ console.error(`已达到最大重连次数(${this.maxReconnectAttempts}),停止重连`);
90
+ return;
91
+ }
92
+
93
+ this.reconnectAttempts++;
94
+ console.log(`准备第 ${this.reconnectAttempts} 次重连,间隔 ${this.reconnectInterval}ms`);
95
+
96
+ // 关闭当前连接(如果存在)
97
+ if (this.eventSource) {
98
+ this.eventSource.close();
99
+ this.eventSource = null;
100
+ }
101
+
102
+ // 延迟重连
103
+ setTimeout(() => {
104
+ this.connect();
105
+ }, this.reconnectInterval);
106
+ }
107
+
108
+ /**
109
+ * 手动关闭 SSE 连接
110
+ */
111
+ close(): void {
112
+ this.isManualClose = true;
113
+ if (this.eventSource) {
114
+ this.eventSource.close();
115
+ this.eventSource = null;
116
+ console.log('SSE 连接已手动关闭');
117
+ }
118
+ }
119
+
120
+ /**
121
+ * 强制重连
122
+ */
123
+ reconnect(): void {
124
+ this.isManualClose = false;
125
+ this.connect();
126
+ }
127
+
128
+ /**
129
+ * 检查连接状态
130
+ * @returns 是否处于连接状态
131
+ */
132
+ isConnected(): boolean {
133
+ return this.eventSource?.readyState === EventSource.OPEN;
134
+ }
135
+ }
@@ -8,7 +8,7 @@ import { application } from '../../../lib/config/applicationConfig';
8
8
  */
9
9
  const queryUimsApplicationTreeData = ({ applicationName }) => {
10
10
  return new Promise((resolve, reject) => {
11
- const data = { parentId: '0', name: applicationName };
11
+ const data = { parentIdForEqual: '0', nameForLike: applicationName };
12
12
  // prettier-ignore
13
13
  http.post(`${application.gatewayServerBaseUrl}/uims-api/admin/uims-application/selectPage`, data).then(res=>{
14
14
  const listData = [
@@ -1,5 +1,5 @@
1
1
  import { nextTick } from 'vue';
2
- import { http } from 'yuang-framework-ui-common/lib/config/httpConfig';
2
+ import { http } from '../../../lib/config/httpConfig';
3
3
 
4
4
  /**
5
5
  * 处理机构树默认展开节点,由于树组件的默认展开节点是异步的,所以需要手动处理默认展开节点
@@ -9,7 +9,7 @@ const handleOrganizationTreeDefaultExpandNode = async ({ id, treeId }) => {
9
9
  console.error(`参数[treeId]不存在`);
10
10
  return;
11
11
  }
12
- const res = await http.post('/uims-api/admin/uims-organization/selectAncestorList', { id: id, isReverseAncestorList: true });
12
+ const res = await http.post('/uims-api/admin/uims-organization/selectAncestorList', { idForEqual: id, isReverseAncestorList: true });
13
13
  const ancestorList = res.data.data;
14
14
  expandNodeImpl({ ancestorList, index: 0, treeId });
15
15
  };
@@ -53,11 +53,11 @@ export interface FrameworkBaseQueryParam {
53
53
  // sort?: string;
54
54
  // /** 排序方式, asc升序, desc降序 */
55
55
  // order?: string;
56
- queryFor?: string;
56
+ queryForMode?: string;
57
57
  levelNum?: number;
58
58
 
59
59
  /** 应用id */
60
- uimsApplicationId?: string;
60
+ uimsApplicationIdForEqual?: string;
61
61
  /** 上级id */
62
- parentId?: string;
62
+ parentIdForEqual?: string;
63
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.68",
3
+ "version": "1.0.69",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -56,6 +56,13 @@ const router = createRouter({
56
56
  isSsoExcluded: true
57
57
  }
58
58
  },
59
+ {
60
+ path: '/hooks/framework/framework-sse-client',
61
+ component: () => import('@/views/hooks/framework/framework-sse-client.vue'),
62
+ meta: {
63
+ isSsoExcluded: true
64
+ }
65
+ },
59
66
 
60
67
 
61
68
 
@@ -0,0 +1,43 @@
1
+ <template>
2
+ <div id="messageContainer"></div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { onMounted, ref } from 'vue';
7
+ import { FrameworkSseClient } from '../../../../lib/hooks/framework/frameworkSseClient';
8
+
9
+ // 初始化 SSE 客户端
10
+ const frameworkSseClient = new FrameworkSseClient (
11
+ 'http://localhost:8290/framework-api/web/framework-sse/connect',
12
+ (data) => {
13
+ // 处理接收到的消息
14
+ const container = document.getElementById('messageContainer');
15
+ if (container) {
16
+ const messageDiv = document.createElement('div');
17
+ messageDiv.className = 'message';
18
+ messageDiv.textContent = `[${new Date().toLocaleTimeString()}] ${data}`;
19
+ container.appendChild(messageDiv);
20
+ }
21
+ },
22
+ {
23
+ reconnectInterval: 5000, // 重连间隔 5 秒
24
+ maxReconnectAttempts: 15, // 最大重连 15 次
25
+ openHandler: () => {
26
+ console.log('SSE 连接成功回调');
27
+ },
28
+ errorHandler: (error) => {
29
+ console.error('自定义错误处理:', error);
30
+ }
31
+ }
32
+ );
33
+
34
+ // 页面关闭时手动关闭连接
35
+ window.addEventListener('beforeunload', () => {
36
+ frameworkSseClient.close();
37
+ });
38
+
39
+ </script>
40
+
41
+ <style scoped>
42
+
43
+ </style>