vue2-client 1.16.33 → 1.16.35
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.
- package/package.json +1 -1
- package/src/base-client/components/common/XTable/XTableWrapper.vue +2 -2
- package/src/base-client/components/common/XWebSocketProgress/README.md +1 -1
- package/src/base-client/components/common/XWebSocketProgress/index.vue +25 -0
- package/src/base-client/components/common/XTable/README.md +0 -243
package/package.json
CHANGED
@@ -211,11 +211,11 @@
|
|
211
211
|
<ellipsis :length="item.slotValue" tooltip>{{ text === '' ? '--' : text }}</ellipsis>
|
212
212
|
</span>
|
213
213
|
<span v-else-if="item.slotType === 'progress'" :key="'progress-' + c_index">
|
214
|
-
<!-- websocket-id (配置名称-字段名称-用户id
|
214
|
+
<!-- websocket-id (配置名称-字段名称-用户id-数据行id) -->
|
215
215
|
<x-web-socket-progress
|
216
216
|
v-if="item.webSocket"
|
217
217
|
:key="`${tableContext.requestParameters?.pageNo || 1}-${item.dataIndex}-${record[tableContext.rowKey] || index}`"
|
218
|
-
:websocket-id="`${queryParamsName}-${item.dataIndex}-${currUser.id}-${
|
218
|
+
:websocket-id="`${queryParamsName}-${item.dataIndex}-${currUser.id}-${record[tableContext.rowKey] || index}`"
|
219
219
|
:initial-value="text || 0"
|
220
220
|
@progress-updated="(data) => handleProgressUpdated(data, record, item.dataIndex)"
|
221
221
|
/>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
{
|
4
4
|
"event": "16", // 进度数据, 取值 0~100
|
5
5
|
"userList": [
|
6
|
-
"ceshiCRUD-t_f_operator_id-419879409793761282-1-18",// 数据webSocket 唯一标识 (配置名称-字段名称-用户id
|
6
|
+
"ceshiCRUD-t_f_operator_id-419879409793761282-1-18",// 数据webSocket 唯一标识 (配置名称-字段名称-用户id-数据行id)
|
7
7
|
"ceshiCRUD-t_f_type-419879409793761282-1-18",
|
8
8
|
"ceshiCRUD-t_f_type-419879409793761282-1-19",
|
9
9
|
"ceshiCRUD-t_f_type-419879409793761282-1-20",
|
@@ -95,6 +95,14 @@ export default {
|
|
95
95
|
initialValue (val) {
|
96
96
|
const num = parseFloat(val)
|
97
97
|
this.progressValue = isNaN(num) ? 0 : Math.max(0, Math.min(100, num))
|
98
|
+
|
99
|
+
// 如果新值 >= 100,断开现有连接
|
100
|
+
if (this.progressValue >= 100) {
|
101
|
+
this.cleanup()
|
102
|
+
this.connectionState.isConnected = false
|
103
|
+
this.connectionState.reconnectAttempts = 0
|
104
|
+
this.$emit('websocket-skipped', { reason: 'initial-value-complete' })
|
105
|
+
}
|
98
106
|
},
|
99
107
|
// 标识变更时,断开旧连接并按新标识重连
|
100
108
|
websocketId (newId, oldId) {
|
@@ -118,6 +126,14 @@ export default {
|
|
118
126
|
return
|
119
127
|
}
|
120
128
|
|
129
|
+
// 如果初始值 >= 100,不建立连接
|
130
|
+
if (this.progressValue >= 100) {
|
131
|
+
this.connectionState.isConnected = false
|
132
|
+
this.connectionState.reconnectAttempts = 0
|
133
|
+
this.$emit('websocket-skipped', { reason: 'initial-value-complete' })
|
134
|
+
return
|
135
|
+
}
|
136
|
+
|
121
137
|
this.websocketUrl = `ws:${window.location.host}/socket/af-system/sendMessage?userId=${this.websocketId}`
|
122
138
|
|
123
139
|
const wsOptions = {
|
@@ -224,6 +240,15 @@ export default {
|
|
224
240
|
value: this.progressValue,
|
225
241
|
originalValue: value
|
226
242
|
})
|
243
|
+
|
244
|
+
// 当进度 >= 100 时,关闭连接
|
245
|
+
if (this.progressValue >= 100) {
|
246
|
+
this.$emit('progress-completed', {
|
247
|
+
value: this.progressValue,
|
248
|
+
originalValue: value
|
249
|
+
})
|
250
|
+
this.cleanup()
|
251
|
+
}
|
227
252
|
}
|
228
253
|
},
|
229
254
|
|
@@ -1,243 +0,0 @@
|
|
1
|
-
# XTable 表格组件使用指南
|
2
|
-
|
3
|
-
## 进度组件使用
|
4
|
-
|
5
|
-
XTable 支持两种类型的进度显示:
|
6
|
-
|
7
|
-
1. **静态进度**: 使用 Ant Design 的 `a-progress` 组件显示静态进度值
|
8
|
-
2. **实时进度**: 使用 `XWebSocketProgress` 组件通过 WebSocket 实时更新进度值
|
9
|
-
|
10
|
-
### 1. 静态进度
|
11
|
-
|
12
|
-
用于显示静态的进度值,不需要实时更新。
|
13
|
-
|
14
|
-
```javascript
|
15
|
-
// 表格列配置
|
16
|
-
const columns = [
|
17
|
-
{
|
18
|
-
title: '任务名称',
|
19
|
-
dataIndex: 'taskName',
|
20
|
-
key: 'taskName'
|
21
|
-
},
|
22
|
-
{
|
23
|
-
title: '进度',
|
24
|
-
dataIndex: 'progress',
|
25
|
-
key: 'progress',
|
26
|
-
slotType: 'progress' // 使用静态进度组件
|
27
|
-
}
|
28
|
-
]
|
29
|
-
|
30
|
-
// 表格数据
|
31
|
-
const tableData = [
|
32
|
-
{
|
33
|
-
taskName: '任务1',
|
34
|
-
progress: 75 // 显示 75% 进度
|
35
|
-
},
|
36
|
-
{
|
37
|
-
taskName: '任务2',
|
38
|
-
progress: 100 // 显示 100% 进度
|
39
|
-
}
|
40
|
-
]
|
41
|
-
```
|
42
|
-
|
43
|
-
### 2. 实时进度
|
44
|
-
|
45
|
-
用于实时更新进度值,通过 WebSocket 连接获取最新的进度信息。
|
46
|
-
|
47
|
-
```javascript
|
48
|
-
// 表格列配置
|
49
|
-
const columns = [
|
50
|
-
{
|
51
|
-
title: '任务名称',
|
52
|
-
dataIndex: 'taskName',
|
53
|
-
key: 'taskName'
|
54
|
-
},
|
55
|
-
{
|
56
|
-
title: '进度',
|
57
|
-
dataIndex: 'progress',
|
58
|
-
key: 'progress',
|
59
|
-
slotType: 'progress',
|
60
|
-
websocketUrl: 'ws://localhost:8080/progress/task1', // WebSocket 连接地址
|
61
|
-
showConnectionStatus: true // 是否显示连接状态
|
62
|
-
}
|
63
|
-
]
|
64
|
-
|
65
|
-
// 表格数据
|
66
|
-
const tableData = [
|
67
|
-
{
|
68
|
-
taskName: '实时任务1',
|
69
|
-
progress: 0 // 初始进度值
|
70
|
-
}
|
71
|
-
]
|
72
|
-
```
|
73
|
-
|
74
|
-
### 3. 混合使用
|
75
|
-
|
76
|
-
可以在同一个表格中混合使用两种进度显示:
|
77
|
-
|
78
|
-
```javascript
|
79
|
-
const columns = [
|
80
|
-
{
|
81
|
-
title: '任务名称',
|
82
|
-
dataIndex: 'taskName',
|
83
|
-
key: 'taskName'
|
84
|
-
},
|
85
|
-
{
|
86
|
-
title: '静态进度',
|
87
|
-
dataIndex: 'staticProgress',
|
88
|
-
key: 'staticProgress',
|
89
|
-
slotType: 'progress' // 使用静态进度
|
90
|
-
},
|
91
|
-
{
|
92
|
-
title: '实时进度',
|
93
|
-
dataIndex: 'realtimeProgress',
|
94
|
-
key: 'realtimeProgress',
|
95
|
-
slotType: 'progress',
|
96
|
-
websocketUrl: 'ws://localhost:8080/progress/realtime', // 使用实时进度
|
97
|
-
showConnectionStatus: true
|
98
|
-
}
|
99
|
-
]
|
100
|
-
```
|
101
|
-
|
102
|
-
## WebSocket 消息格式
|
103
|
-
|
104
|
-
WebSocket 进度组件支持以下消息格式:
|
105
|
-
|
106
|
-
### 1. 标准格式
|
107
|
-
|
108
|
-
```json
|
109
|
-
{
|
110
|
-
"progress": 75
|
111
|
-
}
|
112
|
-
```
|
113
|
-
|
114
|
-
### 2. 自定义字段名
|
115
|
-
|
116
|
-
```json
|
117
|
-
{
|
118
|
-
"percentage": 60
|
119
|
-
}
|
120
|
-
```
|
121
|
-
|
122
|
-
### 3. 包含其他信息
|
123
|
-
|
124
|
-
```json
|
125
|
-
{
|
126
|
-
"progress": 50,
|
127
|
-
"message": "正在处理数据...",
|
128
|
-
"status": "processing"
|
129
|
-
}
|
130
|
-
```
|
131
|
-
|
132
|
-
### 4. 纯数字
|
133
|
-
|
134
|
-
```json
|
135
|
-
80
|
136
|
-
```
|
137
|
-
|
138
|
-
## 事件处理
|
139
|
-
|
140
|
-
WebSocket 进度组件会触发以下事件:
|
141
|
-
|
142
|
-
```javascript
|
143
|
-
// 在表格组件中监听进度更新事件
|
144
|
-
methods: {
|
145
|
-
handleProgressUpdated(data, record, dataIndex) {
|
146
|
-
console.log('进度更新:', {
|
147
|
-
value: data.value,
|
148
|
-
record: record,
|
149
|
-
field: dataIndex
|
150
|
-
})
|
151
|
-
}
|
152
|
-
}
|
153
|
-
```
|
154
|
-
|
155
|
-
## 完整示例
|
156
|
-
|
157
|
-
```vue
|
158
|
-
<template>
|
159
|
-
<x-table
|
160
|
-
:columns="columns"
|
161
|
-
:data="tableData"
|
162
|
-
@progress-updated="handleProgressUpdated"
|
163
|
-
/>
|
164
|
-
</template>
|
165
|
-
|
166
|
-
<script>
|
167
|
-
export default {
|
168
|
-
data() {
|
169
|
-
return {
|
170
|
-
columns: [
|
171
|
-
{
|
172
|
-
title: '任务ID',
|
173
|
-
dataIndex: 'id',
|
174
|
-
key: 'id',
|
175
|
-
width: 80
|
176
|
-
},
|
177
|
-
{
|
178
|
-
title: '任务名称',
|
179
|
-
dataIndex: 'name',
|
180
|
-
key: 'name'
|
181
|
-
},
|
182
|
-
{
|
183
|
-
title: '静态进度',
|
184
|
-
dataIndex: 'staticProgress',
|
185
|
-
key: 'staticProgress',
|
186
|
-
slotType: 'progress'
|
187
|
-
},
|
188
|
-
{
|
189
|
-
title: '实时进度',
|
190
|
-
dataIndex: 'realtimeProgress',
|
191
|
-
key: 'realtimeProgress',
|
192
|
-
slotType: 'progress',
|
193
|
-
websocketUrl: 'ws://localhost:8080/progress',
|
194
|
-
showConnectionStatus: true,
|
195
|
-
progressField: 'percentage'
|
196
|
-
},
|
197
|
-
{
|
198
|
-
title: '状态',
|
199
|
-
dataIndex: 'status',
|
200
|
-
key: 'status',
|
201
|
-
width: 100
|
202
|
-
}
|
203
|
-
],
|
204
|
-
tableData: [
|
205
|
-
{
|
206
|
-
id: 1,
|
207
|
-
name: '数据处理任务',
|
208
|
-
staticProgress: 100,
|
209
|
-
realtimeProgress: 0,
|
210
|
-
status: '进行中'
|
211
|
-
},
|
212
|
-
{
|
213
|
-
id: 2,
|
214
|
-
name: '文件上传任务',
|
215
|
-
staticProgress: 75,
|
216
|
-
realtimeProgress: 0,
|
217
|
-
status: '等待中'
|
218
|
-
}
|
219
|
-
]
|
220
|
-
}
|
221
|
-
},
|
222
|
-
methods: {
|
223
|
-
handleProgressUpdated(data, record, dataIndex) {
|
224
|
-
// 更新表格数据
|
225
|
-
this.$set(record, dataIndex, data.value)
|
226
|
-
|
227
|
-
// 可以在这里添加其他业务逻辑
|
228
|
-
if (data.value === 100) {
|
229
|
-
record.status = '已完成'
|
230
|
-
}
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}
|
234
|
-
</script>
|
235
|
-
```
|
236
|
-
|
237
|
-
## 注意事项
|
238
|
-
|
239
|
-
1. **WebSocket URL**: 确保 WebSocket 服务器地址正确且可访问
|
240
|
-
2. **消息格式**: 确保服务器发送的消息格式符合组件要求
|
241
|
-
3. **性能考虑**: 如果表格数据量大,建议只在需要实时更新的列使用 WebSocket 进度组件
|
242
|
-
4. **错误处理**: WebSocket 连接失败时会自动重连,但建议监听错误事件
|
243
|
-
5. **内存管理**: 组件销毁时会自动断开 WebSocket 连接
|