system-clients 4.0.17 → 4.0.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "system-clients",
3
- "version": "4.0.17",
3
+ "version": "4.0.19",
4
4
  "description": "系统基础框架",
5
5
  "main": "src/index.js",
6
6
  "directories": {
@@ -21,6 +21,9 @@
21
21
 
22
22
 
23
23
  <div class="span" style="float:right;margin-top: 6px">
24
+ <button type="button" class="btn-danger btn " style="border-radius: 4px"
25
+ @click="$parent.$parent.batchDelete">批量删除
26
+ </button>
24
27
  <button type="button" class="btn-success btn " style="border-radius: 4px"
25
28
  @click="$parent.$parent.batchRoot('1')">批量启用
26
29
  </button>
@@ -214,6 +217,18 @@
214
217
  infoclose(){
215
218
  this.infoshow=false
216
219
  },
220
+ async batchDelete() {
221
+ let selPos = this.selPos
222
+ console.log('选择的数据', selPos)
223
+ let ids = []
224
+ for (const tmp of selPos) {
225
+ ids.push(tmp.id)
226
+ }
227
+ await this.$resetpost('api/af-system/logic/batchDeletePos', {data: {ids: ids}}, {
228
+ rejectMsg: null,
229
+ resolveMsg: null
230
+ })
231
+ },
217
232
  // 批量操作
218
233
  async batchRoot(val) {
219
234
  let arrs = []
@@ -200,7 +200,8 @@ let createWaterMark = function (userName) {
200
200
  gasbrandIdData: [],
201
201
  showRemind: false,
202
202
  dataRemind: [],
203
- connectNumber:10,
203
+ connectNumber: 0,
204
+ maxReconnectCount: 3,
204
205
  timeout: 1000,
205
206
  timeoutObj: null,
206
207
  serverTimeoutObj: null,
@@ -311,52 +312,117 @@ let createWaterMark = function (userName) {
311
312
  //如果服务端在一定时间内没有收到信息,就认为客户端断开了,服务端就会断开连接
312
313
  // 发送心跳--确保连接有效
313
314
  start () {
314
- // 重置
315
- vue.prototype.$connectNumber = this.connectNumber // 重置重连次数
316
- this.timeoutObj = setTimeout(() => {
317
- this.$socket.send('ping')
318
- console.log('ping!')
319
- this.serverTimeoutObj = setTimeout(() => {
320
- this.$socket.close()
315
+ this.reset()
316
+ // 检查WebSocket连接状态
317
+ if (this.$socket && this.$socket.readyState === WebSocket.OPEN) {
318
+ this.timeoutObj = setTimeout(() => {
319
+ try {
320
+ if (this.$socket && this.$socket.readyState === WebSocket.OPEN) {
321
+ this.$socket.send('ping')
322
+ console.log('发送心跳: ping')
323
+ this.serverTimeoutObj = setTimeout(() => {
324
+ console.log('心跳超时,关闭连接')
325
+ if (this.$socket) {
326
+ this.$socket.close()
327
+ }
328
+ }, this.timeout)
329
+ }
330
+ } catch (e) {
331
+ console.error('发送心跳失败:', e)
332
+ this.reconnect()
333
+ }
321
334
  }, this.timeout)
322
- }, this.timeout)
335
+ }
323
336
  },
324
337
  // 重连
325
338
  reconnect () {
326
- if (this.lockReconnect) return
339
+ console.log('reconnect()被调用,当前状态:', {
340
+ lockReconnect: this.lockReconnect,
341
+ connectNumber: this.connectNumber,
342
+ maxReconnectCount: this.maxReconnectCount
343
+ })
344
+
345
+ if (this.lockReconnect) {
346
+ console.log('重连被锁定,跳过')
347
+ return
348
+ }
349
+
350
+ // 检查重连次数
351
+ this.connectNumber++
352
+ if (this.connectNumber > this.maxReconnectCount) {
353
+ console.log(`重连失败,已达到最大重连次数(${this.maxReconnectCount}),停止重连`)
354
+ this.$showMessage(`WebSocket连接失败,已尝试${this.maxReconnectCount}次重连,请刷新页面或联系管理员`)
355
+ return
356
+ }
357
+
358
+ this.lockReconnect = true
359
+
360
+ // 清理旧连接
361
+ if (this.$socket) {
362
+ this.$socket.close()
363
+ this.$socket = null
364
+ }
365
+
366
+ // 指数退避延迟
367
+ const delay = Math.min(1000 * Math.pow(2, this.connectNumber - 1), 30000)
368
+ console.log(`连接异常,${delay/1000}秒后进行第${this.connectNumber}次重连...`)
369
+
327
370
  setTimeout(() => {
328
- console.log('连接异常,尝试重新连接。。。。')
329
371
  this.initWebSocket()
330
372
  this.lockReconnect = false
331
- }, 1000 * 60)
373
+ }, delay)
332
374
  },
333
375
  // 初始化
334
376
  initWebSocket () {
335
- let path = `ws://${location.host}/ws?token=${this.$login.f.id}`
377
+ // 清理旧连接
378
+ if (this.$socket) {
379
+ this.$socket.close()
380
+ this.$socket = null
381
+ }
382
+
383
+ // 自动检测协议
384
+ let protocol = location.protocol === 'https:' ? 'wss:' : 'ws:'
385
+ let path = `${protocol}//${location.host}/ws?token=${this.$login.f.id}`
386
+
336
387
  try {
337
388
  if ('WebSocket' in window) {
338
- // 创建对象
389
+ console.log(`正在连接WebSocket: ${path}`)
339
390
  vue.prototype.$socket = new WebSocket(path)
391
+
392
+ // 检查WebSocket是否创建成功
393
+ if (this.$socket) {
394
+ this.$socket.onopen = this.onOpen // 连接成功
395
+ this.$socket.onmessage = this.onMessage // 收到消息时回调
396
+ this.$socket.onclose = this.onClose // 连接关闭时回调
397
+ this.$socket.onerror = this.onError // 通讯异常
398
+ } else {
399
+ console.error('WebSocket创建失败: $socket为null')
400
+ this.reconnect()
401
+ }
340
402
  } else {
341
- this.$showMessage('您的浏览器不支持websocket的协议,建议使用新版谷歌浏览器,请勿使用IE浏览器,360浏览器请使用极速模式,不要使用兼容模式!"')
403
+ console.error('浏览器不支持WebSocket')
404
+ this.$showMessage('您的浏览器不支持websocket的协议,建议使用新版谷歌浏览器,请勿使用IE浏览器,360浏览器请使用极速模式,不要使用兼容模式!')
342
405
  }
343
406
  } catch (e) {
407
+ console.error('WebSocket创建失败:', e)
408
+ // 确保$socket被清空
409
+ vue.prototype.$socket = null
344
410
  this.reconnect()
345
411
  }
346
-
347
- this.$socket.onopen = this.onOpen // 连接成功
348
- this.$socket.onmessage = this.onMessage // 收到消息时回调
349
- this.$socket.onclose = this.onClose // 连接关闭时回调
350
- this.$socket.onerror = this.onError // 通讯异常
351
412
  },
352
413
  // 通讯异常
353
- onError () {
354
- console.log('通讯异常')
355
- this.reconnect()
414
+ onError (error) {
415
+ console.log('WebSocket通讯异常:', error)
416
+ // 只有在还没达到最大重连次数时才重连
417
+ if (this.connectNumber < this.maxReconnectCount) {
418
+ this.reconnect()
419
+ }
356
420
  },
357
421
  // 连接成功
358
422
  onOpen () {
359
- console.log('webSocket连接成功')
423
+ console.log('WebSocket连接成功')
424
+ // 重置重连计数
425
+ this.connectNumber = 0
360
426
  this.start()//每十秒发送心跳包,确保连接状态有效
361
427
  },
362
428
  // 收到消息时回调函数
@@ -381,10 +447,14 @@ let createWaterMark = function (userName) {
381
447
  }
382
448
  },
383
449
  // 关闭连接时回调函数
384
- onClose () {
385
- console.log('webSocket连接断开')
450
+ onClose (event) {
451
+ console.log('WebSocket连接断开, code:', event.code, 'reason:', event.reason)
386
452
  this.reset()
387
- this.reconnect() // 重连
453
+
454
+ // 只有在非正常关闭且未达到最大重连次数时才重连
455
+ if (event.code !== 1000 && this.connectNumber < this.maxReconnectCount) {
456
+ this.reconnect()
457
+ }
388
458
  },
389
459
  getOrderList(){
390
460
  let times = this.config.times * 60 * 1000
@@ -660,6 +730,26 @@ let createWaterMark = function (userName) {
660
730
  })
661
731
  }
662
732
  },
733
+ beforeDestroy() {
734
+ // 清理定时器
735
+ if (this.interval) {
736
+ clearInterval(this.interval)
737
+ this.interval = null
738
+ }
739
+ if (this.intervaltx) {
740
+ clearInterval(this.intervaltx)
741
+ this.intervaltx = null
742
+ }
743
+
744
+ // 清理WebSocket相关
745
+ this.reset()
746
+ if (this.$socket) {
747
+ this.$socket.close(1000, '页面关闭')
748
+ this.$socket = null
749
+ }
750
+
751
+ console.log('组件销毁,已清理所有资源')
752
+ },
663
753
  computed: {
664
754
  orgpathnames(){
665
755
  let names = this.$login.f.name