长城汽车软件包管理平台
whychdw
2025-05-06 4a867727d81b9513e675ad396903368c6a293dca
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<script setup lang="ts">
import getLabelByValue from "@/utils/getLabelByValue";
 
defineOptions({
  name: "DeviceReal",
  inheritAttrs: false,
});
import useWebSocket from "@/hooks/useWebSocket";
import { SearchParams } from "@/api/software";
 
const { eventBus, sendData } = useWebSocket("devState");
const loading = ref(false);
const queryParams = reactive<SearchParams>({
  pageNum: 1,
  pageSize: 20,
});
const total = ref(0);
const listRef = ref();
 
eventBus.on("onopen", () => {
  handleQuery();
});
const errorList = [
  {
    label: "---",
    value: 0,
  },
  {
    label: "文件未找到",
    value: 1,
  },
  {
    label: "参数错误",
    value: 2,
  },
  {
    label: "文件发送超时",
    value: 3,
  },
  {
    label: "远程停止",
    value: 4,
  },
];
eventBus.on("message", (res) => {
  let rs = JSON.parse(res as string);
  if (rs.code === 1) {
    total.value = rs.data.total;
    listRef.value = rs.data.list.map((item: any) => {
      item.fullStationName =
        item.stationProvince +
        "-" +
        item.stationCity +
        "-" +
        item.stationCounty +
        "-" +
        item.stationName +
        "-" +
        item.devName;
      item.updatePercent =
        item.dfuDataBlockLen === 0 ? 0 : (item.dfuDataBlockNum / item.dfuDataBlockLen) * 100;
      item.updatePercent = item.updatePercent.toFixed(2);
      item.errorCodeText = getLabelByValue(item.errorCode, errorList, { label: "未知", value: -1 });
      return item;
    });
  } else {
    queryParams.pageNum = 1;
    total.value = 0;
  }
});
 
function handleQuery() {
  sendData(JSON.stringify(queryParams));
}
 
const format = (percentage: number) => (percentage === 100 ? "升级完成" : `${percentage}%`);
</script>
 
<template>
  <div class="app-container">
    <el-card shadow="never">
      <el-table v-loading="loading" :data="listRef">
        <el-table-column
          show-overflow-tooltip
          label="机房名称"
          min-width="320"
          align="center"
          prop="fullStationName"
        />
        <el-table-column
          show-overflow-tooltip
          label="序列号"
          min-width="180"
          align="center"
          prop="serialNumber"
        />
        <el-table-column
          show-overflow-tooltip
          label="SN码"
          min-width="180"
          align="center"
          prop="snCode"
        />
        <el-table-column
          show-overflow-tooltip
          label="版本号"
          min-width="180"
          align="center"
          prop="version"
        />
        <el-table-column label="升级进度" min-width="180" align="center" prop="updatePercent">
          <template #default="{ row }">
            <el-progress :percentage="row.updatePercent" :format="format" />
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          label="错误代码"
          min-width="180"
          align="center"
          prop="errorCodeText"
        />
        <el-table-column
          show-overflow-tooltip
          label="数据更新时间"
          min-width="180"
          align="center"
          prop="recordTime"
        />
      </el-table>
      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery"
      />
    </el-card>
  </div>
</template>
 
<style scoped lang="scss"></style>