Riku
2025-05-14 fac3e813d205f000125eb8f7b2dd4976f4166edf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
  <BaseCard>
    <template #content>
      <div>
        <el-input type="text" v-model="inputVal" />
        <button @click="handleSend">send</button>
        <button @click="handleLink">link</button>
      </div>
      <div>业务状态中控</div>
      <el-scrollbar ref="scrollbarRef" :height="height">
        <div ref="scrollContentRef">
          <div v-for="(item, index) in streams" :key="index">
            <el-text type="primary">{{ item.guid }}</el-text>
            <el-text type="primary">{{ ' | ' + item.status }}</el-text>
            <el-text type="primary">{{ ' | ' + item.startTime }}</el-text>
            <el-text type="primary">{{ ' | ' + item.endTime }}</el-text>
            <el-divider />
          </div>
        </div>
      </el-scrollbar>
    </template>
  </BaseCard>
</template>
<script setup>
/**
 * 动态溯源信息管理
 * 通过websocket方式接收后端推送的异常信息并展示
 */
import { reactive, ref, onMounted, onUnmounted, inject } from 'vue';
import websocket from '@/api/websocket';
 
const height = `60vh`;
 
const scrollContentRef = ref();
const scrollbarRef = ref();
 
function scrollToBottom() {
  const h1 = scrollContentRef.value.clientHeight + 100;
  setTimeout(() => {
    scrollbarRef.value.setScrollTop(h1);
  }, 100);
}
 
const streams = reactive([]);
 
const inputVal = ref('');
const handleSend = () => {
  websocket.send(inputVal.value);
};
 
/**
 * 添加一条工作流信息
 * @param {*} data
 */
const putWorkStream = (data) => {
  const obj = JSON.parse(data);
  streams.push(obj);
  scrollToBottom();
};
 
onMounted(() => {
  websocket.registerReceiveEvent(putWorkStream);
});
onUnmounted(() => {
  websocket.removeReceiveEvent(putWorkStream);
});
</script>