zhitong.yu
8 天以前 378d781e6f35f89652aa36e079a8b7fc44cea77e
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<template>
  <el-table :data="tableData" :show-overflow-tooltip="true" class="alarmTable" :row-style="rowStyle">
    <el-table-column prop="" :label="t('')" align="center" width="30" />
    <el-table-column :label="t('')" width="40">
      <!-- 使用 scoped slot 自定义列内容 -->
      <template #default="scope">
        <!-- 显示图片 -->
        <img :src="scope.row.icon" :alt="scope.row.icon" style="width: 20px; height: 20px; object-fit: cover" />
      </template>
    </el-table-column>
    <el-table-column :label="t('dayCount.alarmType')" width="190">
      <!-- 使用 scoped slot 自定义列内容 -->
      <template #default="scope">
        <span @click="showDetailDialog(scope.row.title)">&nbsp;&nbsp;{{ getTranslatedTitle(scope.row.title) }}</span>
      </template>
    </el-table-column>
 
    <el-table-column :label="t('dayCount.count')" width="110">
      <!-- 使用 scoped slot 自定义列内容 -->
      <template #default="scope">
        <span>{{ scope.row.num }} </span>
      </template>
    </el-table-column>
  </el-table>
  <!-- 在线人员 - 离线人员 -->
  <el-dialog v-model="dialogVisible" width="45%" style="height: 620px; background-size: 100% 100%">
    <template #header="">
      <div class="my-header" style="font-weight: bold; color: white; text-align: center">
        {{ dialogTitle }}
      </div>
    </template>
    <el-input
      v-model="searchTextPerson"
      :placeholder="t('dayCount.searchPlaceholder')"
      clearable
      style="float: left; margin-left: 0"
      @input="handleSearch"
    >
      <template #prefix>
        <el-icon><Search /></el-icon>
      </template>
    </el-input>
    <el-table
      :data="filteredTableDataPerson"
      :show-overflow-tooltip="true"
      class="alarmTable"
      :row-style="rowStyle"
      style="height: 500px"
    >
      <!-- 原有列定义保持不变 -->
      <el-table-column :label="t('Person.name')" align="center">
        <template #default="scope">
          {{ getSafeValue(scope.row.pname) }}
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.tagid')" align="center">
        <template #default="scope">
          <span style="height: 100px">{{ getSafeValue(scope.row.ptagid) }} </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.status')" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.ponline === '1' ? '' : 'danger'">
            {{ getSafeValue(scope.row.ponline === "1" ? t("status.online") : t("status.offline")) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.power')" align="center">
        <template #default="scope">
          <span>{{ getSafeValue(scope.row.ppower) }}% </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.department')" align="center">
        <template #default="scope">
          <span>{{ getSafeValue(scope.row.pdepartment) }} </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('dayCount.type')" align="center">
        <template #default="scope">
          <span>{{ getSafeValue(scope.row.baoliu19) }} </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.company')" align="center">
        <template #default="scope">
          <el-tag hit style="font-size: 14px; font-weight: bold">{{ getSafeValue(scope.row.company) }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
 
  <!-- 告警详情对话框 -->
  <el-dialog v-model="dialogVisibleWarning" width="45%" style="height: 620px; overflow-y: hidden; background-size: 100% 100%">
    <template #header="">
      <div class="my-header" style="margin-left: 10px; font-weight: bold; color: white; text-align: center">
        {{ dialogTitle }}
      </div>
    </template>
    <el-input
      v-model="searchTextWarning"
      :placeholder="t('dayCount.searchPlaceholder')"
      clearable
      style="float: left; margin-left: 0"
      @input="handleSearchWarning"
    ></el-input>
    <el-table
      :data="filteredTableDataWarning"
      :show-overflow-tooltip="true"
      class="alarmTable"
      :row-style="rowStyle"
      style="height: 500px"
    >
      <el-table-column :label="t('dayCount.alarmType')" align="center">
        <!-- 使用 scoped slot 自定义列内容 -->
        <template #default="scope">
          <template v-if="scope.row.type === 'SOS'">
            <el-image style="width: 20px; height: 20px; margin-top: 0" :src="sos" />{{ t("warningTypes.sos") }}
          </template>
          <template v-else-if="scope.row.type === '进入告警'">
            <el-image style="width: 20px; height: 20px; margin-top: 0" :src="jinru" />{{ t("warningTypes.enter") }}
          </template>
          <template v-else-if="scope.row.type === '出去告警'">
            <el-image style="width: 20px; height: 20px; margin-top: 0" :src="chuqu" /> {{ t("warningTypes.exit") }}
          </template>
          <template v-else-if="scope.row.type === '聚集告警'">
            <el-image style="width: 20px; height: 20px; margin-top: 0" :src="juji" />{{ t("warningTypes.gather") }}
          </template>
          <template v-else>
            {{ scope.row.type }}
          </template>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.name')" align="center">
        <!-- 使用 scoped slot 自定义列内容 -->
        <template #default="scope">
          <span>{{ scope.row.baoliu2 }} </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('Person.tagid')" align="center">
        <!-- 使用 scoped slot 自定义列内容 -->
        <template #default="scope">
          <span>{{ scope.row.objectid }} </span>
        </template>
      </el-table-column>
      <el-table-column :label="t('Config.time')" align="center">
        <!-- 使用 scoped slot 自定义列内容 -->
        <template #default="scope">
          <span>{{ scope.row.time.split("-")[1] }}-{{ scope.row.time.split("-")[2] }} </span>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
 
<script lang="ts">
import { defineComponent, onMounted, reactive, ref, toRefs, nextTick, onUnmounted, computed } from "vue";
import { FindDayCountInfo, FindWarningInfoType } from "@/api/modules/hxzk/statistics/warncount";
import trBackground from "../images/map/trbackground.png";
import infoBack from "@/views/hxzk/images/map/infoBack.png";
import { Search } from "@element-plus/icons-vue"; // 导入搜索图标
import { getSafeValue } from "@/views/hxzk/utils/common";
import { useI18n } from "vue-i18n";
 
export default defineComponent({
  setup() {
    const { t } = useI18n({ useScope: "global" });
 
    // 表格的数据类型
    interface tableType {
      name: string;
      money: number;
    }
    const data = reactive({
      tableData: [] as Array<tableType>,
      tableDataWarning: [] as Array<tableType>,
      tableDataPerson: [] as Array<tableType>,
      currentPage: 1,
      pageSize: 6,
      tableDom: {} as HTMLElement,
      dialogVisible: false, // 控制对话框显示
      dialogVisibleWarning: false, // 控制对话框显示
      selectedTitle: "", // 选中的告警类型
      dialogTitle: t("dayCount.alarmDetails") // 对话框标题
    });
    let timeInterval: NodeJS.Timer; // 定时器的对象
    let tableScroll = ref(false); // 是否需要滚动
 
    // 定时器 ID,用于在组件卸载时清除定时器
    let intervalId: number | null = null;
 
    onMounted(() => {
      // 初始化表格的数据
      list();
      // 每秒执行一次 list 函数
      intervalId = setInterval(list, 10000);
      scrollTable();
    });
 
    onUnmounted(() => {
      clearInterval(timeInterval);
      // 组件卸载时清除定时器,避免内存泄漏
      if (intervalId) {
        clearInterval(intervalId);
      }
    });
    const baseUrl = import.meta.env.VITE_IP;
    const sos = ref(`${baseUrl}/uploads/warn/Tongji/sosimage.png`);
    const jinru = ref(`${baseUrl}/uploads/warn/Tongji/jinruimage.png`);
    const chuqu = ref(`${baseUrl}/uploads/warn/Tongji/yujie.png`);
    const juji = ref(`${baseUrl}/uploads/warn/Tongji/jujiimage.png`);
    const searchTextPerson = ref("");
    const searchTextWarning = ref("");
 
    // 获取翻译后的标题
    const getTranslatedTitle = (title: string) => {
      const titleMap: Record<string, string> = {
        在线人员: t("dayCount.onlinePersonnel"),
        离线人员: t("dayCount.offlinePersonnel"),
        SOS报警: t("warningTypes.sos"),
        进入报警: t("warningTypes.enter"),
        越界报警: t("warningTypes.exit"),
        聚集报警: t("warningTypes.gather")
      };
      return titleMap[title] || title;
    };
 
    // 初始化表格的数据
    const list = () => {
      const tableList = {
        pageNum: 1,
        pageSize: 1000
      };
      const params = {
        tableList
      };
      FindDayCountInfo(params).then(dt => {
        for (let i = 0; i < dt.length; i++) {
          dt[i].icon = `${baseUrl}/uploads/warn/Tongji/` + dt[i].icon;
        }
        data.tableData = dt;
      });
    };
    // 计算属性:过滤后的表格数据 --- 在线 - 离线人员
    const filteredTableDataPerson = computed(() => {
      if (!searchTextPerson.value) {
        return data.tableDataPerson;
      }
      const searchText1 = searchTextPerson.value.toLowerCase();
      return data.tableDataPerson.filter(item => {
        return (
          (item.pname && item.pname.toLowerCase().includes(searchText1)) ||
          (item.ptagid && item.ptagid.toLowerCase().includes(searchText1)) ||
          (item.pdepartment && item.pdepartment.toLowerCase().includes(searchText1)) ||
          (item.company && item.company.toLowerCase().includes(searchText1)) ||
          (item.baoliu19 && item.baoliu19.toLowerCase().includes(searchText1))
        );
      });
    });
 
    // 计算属性:过滤后的表格数据 --- 告警
    const filteredTableDataWarning = computed(() => {
      if (!searchTextWarning.value) {
        return data.tableDataWarning;
      }
      const searchText1 = searchTextWarning.value.toLowerCase();
      return data.tableDataWarning.filter(item => {
        return (
          (item.baoliu4 && item.baoliu4.toLowerCase().includes(searchText1)) ||
          (item.objectid && item.objectid.toLowerCase().includes(searchText1)) ||
          (item.baoliu3 && item.baoliu3.toLowerCase().includes(searchText1))
        );
      });
    });
    // 搜索处理函数
    const handleSearch = () => {
      // 计算属性会自动更新,无需额外操作
    };
    // 搜索处理函数
    const handleSearchWarning = () => {
      // 计算属性会自动更新,无需额外操作
    };
    // 显示详情对话框
    const showDetailDialog = (title: string) => {
      data.selectedTitle = title;
      if (title == "在线人员" || title == "离线人员") {
        data.dialogTitle = getTranslatedTitle(title);
        data.dialogVisible = true;
        const tableList = {
          pageNum: 1,
          pageSize: 1000
        };
        const params = {
          tableList,
          warning: {
            type: title
          }
        };
        FindWarningInfoType(params).then(dt => {
          console.log(dt);
          data.tableDataPerson = dt.data.list;
        });
      } else {
        data.dialogTitle = getTranslatedTitle(title);
        data.dialogVisibleWarning = true;
        const tableList = {
          pageNum: 1,
          pageSize: 1000
        };
        const params = {
          tableList,
          warning: {
            type: title
          }
        };
        FindWarningInfoType(params).then(dt => {
          console.log(dt);
          data.tableDataWarning = dt.data.list;
        });
      }
    };
 
    // 表格的数据滚动
    const scrollTable = () => {
      nextTick(() => {
        // 获取当前表格内容的dom
        let table = document.getElementsByClassName("alarmTable")[0];
        data.tableDom = table.getElementsByClassName("el-scrollbar__wrap")[0]! as HTMLElement;
        // 鼠标放在表格内容,暂停滚动
        data.tableDom.addEventListener("mouseover", () => {
          tableScroll.value = false;
        });
        // 鼠标移出表格内容,继续滚动
        // data.tableDom.addEventListener("mouseout", () => {
        //   tableScroll.value = true;
        // });
        //
        timeInterval = setInterval(() => {
          if (tableScroll.value) {
            // 每次内容滚动的距离
            data.tableDom.scrollTop += 1;
            if (data.tableDom.clientHeight + data.tableDom.scrollTop == data.tableDom.scrollHeight) {
              data.tableDom.scrollTop = 0;
            }
          }
        }, 10);
      });
    };
 
    const rowStyle = ({}) => {
      // 设置统一的背景图片,这里假设图片路径为 'path/to/your-background-image.jpg'
      // 可以根据实际情况修改图片路径
      return {
        backgroundImage: `url('${trBackground}')`,
        backgroundSize: "100% 150%", // 可根据需求调整背景图片的显示方式
        backgroundRepeat: "no-repeat",
        height: "50px"
      };
    };
 
    return {
      ...toRefs(data),
      rowStyle,
      showDetailDialog,
      infoBack,
      filteredTableDataPerson,
      handleSearch,
      handleSearchWarning,
      filteredTableDataWarning,
      Search,
      searchTextWarning,
      searchTextPerson,
      sos,
      jinru,
      chuqu,
      juji,
      getSafeValue,
      t,
      getTranslatedTitle
    };
  }
});
</script>
<style lang="scss" scoped>
el-table {
  border: 1px solid rgb(33 0 99) !important;
}
.alarmTable {
  height: 100%;
  padding: 0 0 22px;
  margin-top: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: bolder;
  text-shadow:
    -1px -1px 0 #000000,
    1px -1px 0 #000000,
    -1px 1px 0 #000000,
    1px 1px 0 #000000;
  scroll-behavior: smooth;
}
:deep(.el-input__wrapper) {
  background-color: transparent !important;
  border: 1px solid#14637F;
  box-shadow: none !important;
}
</style>