|
|
@@ -1,71 +1,40 @@
|
|
|
<template>
|
|
|
<a-drawer title="设备告警信息" placement="right" v-model:visible="sVisible" @update:visible="onVisibleChange"
|
|
|
:destroyOnClose="true" :width="800">
|
|
|
- <div class="flex-row flex-align-center" style="margin-bottom: 20px;">
|
|
|
- <div style="width: 240px;">
|
|
|
- <a-range-picker v-model:value="time" format="YYYY-MM-DD" @change="onTimeChange" />
|
|
|
- </div>
|
|
|
- <div class="ml5">
|
|
|
- <a-select style="width: 150px" v-model:value="param.level" @select="onLevelSelect">
|
|
|
- <a-select-option v-for="item in levels" :key="item.label" :value="item.value">
|
|
|
- {{ item.label }}
|
|
|
- </a-select-option>
|
|
|
- </a-select>
|
|
|
- </div>
|
|
|
- <div class="ml5">
|
|
|
- <a-select v-model:value="param.domain" :disabled="!param.children_sn || !param.device_sn" style="width: 150px"
|
|
|
- @select="onDeviceTypeSelect">
|
|
|
- <a-select-option v-for="item in deviceTypes" :key="item.label" :value="item.value">
|
|
|
- {{ item.label }}
|
|
|
- </a-select-option>
|
|
|
- </a-select>
|
|
|
- </div>
|
|
|
- <div class="ml5">
|
|
|
- <a-input-search v-model:value="param.message" placeholder="搜索告警信息" style="width: 200px" @search="getHms" />
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- <a-table :columns="hmsColumns" :scroll="{ x: '100%', y: 600 }" :data-source="hmsData.data"
|
|
|
- :pagination="hmsPaginationProp" @change="refreshHmsData" row-key="hms_id" :rowClassName="rowClassName"
|
|
|
- :loading="loading">
|
|
|
- <template #time="{ record }">
|
|
|
- <div>{{ record.create_time }}</div>
|
|
|
- <div :style="record.update_time ? '' : record.level === EHmsLevel.CAUTION ? 'color: orange;' :
|
|
|
- record.level === EHmsLevel.WARN ? 'color: red;' : 'color: #28d445;'">
|
|
|
- {{ record.update_time ?? 'It is happening...' }}</div>
|
|
|
- </template>
|
|
|
- <template #level="{ text }">
|
|
|
- <div class="flex-row flex-align-center">
|
|
|
- <div :class="text === EHmsLevel.CAUTION ? 'caution' : text === EHmsLevel.WARN ? 'warn' : 'notice'"
|
|
|
- style="width: 10px; height: 10px; border-radius: 50%;"></div>
|
|
|
- <div style="margin-left: 3px;">{{ EHmsLevel[text] }}</div>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- <template v-for="col in ['code', 'message']" #[col]="{ text }" :key="col">
|
|
|
- <a-tooltip :title="text">
|
|
|
- <div>{{ text }}</div>
|
|
|
- </a-tooltip>
|
|
|
- </template>
|
|
|
- <template #domain="{ text }">
|
|
|
- <a-tooltip :title="EDeviceTypeName[text]">
|
|
|
- <div>{{ EDeviceTypeName[text] }}</div>
|
|
|
- </a-tooltip>
|
|
|
- </template>
|
|
|
- </a-table>
|
|
|
- </div>
|
|
|
+ <Search :onClickSearch="onClickSearch" :onClickReset="onClickReset" />
|
|
|
+ <a-table :scroll="{ x: '100%', y: 500 }" rowKey="hms_id" :loading="state.listLoading" :columns="columns"
|
|
|
+ @change="refreshData" :rowClassName="rowClassName" :dataSource="state.list" :pagination="paginationConfig">
|
|
|
+ <template #time="{ record }">
|
|
|
+ <div>{{ record.create_time }}</div>
|
|
|
+ <div :style="record.update_time ? '' : record.level === 1 ? 'color: orange;' :
|
|
|
+ record.level === 2 ? 'color: red;' : 'color: #28d445;'">
|
|
|
+ {{ record.update_time ?? '它正在发生……' }}</div>
|
|
|
+ </template>
|
|
|
+ <template #level="{ text }">
|
|
|
+ <a-tag color="success" v-if="text === 0">
|
|
|
+ 正常
|
|
|
+ </a-tag>
|
|
|
+ <a-tag color="warning" v-else-if="text === 1">
|
|
|
+ 警告
|
|
|
+ </a-tag>
|
|
|
+ <a-tag color="error" v-else-if="text === 2">
|
|
|
+ 危险
|
|
|
+ </a-tag>
|
|
|
+ </template>
|
|
|
+ <template v-for="col in ['code', 'message']" #[col]="{ text }" :key="col">
|
|
|
+ <a-tooltip :title="text">
|
|
|
+ {{ text }}
|
|
|
+ </a-tooltip>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
</a-drawer>
|
|
|
</template>
|
|
|
|
|
|
-<!-- 暂时只抽取该组件 -->
|
|
|
<script lang="ts" setup>
|
|
|
import { reactive, ref, defineProps, defineEmits, watch } from 'vue'
|
|
|
-import { getDeviceHms, HmsQueryBody } from '/@/api/manage'
|
|
|
-import { ColumnProps, TableState } from 'ant-design-vue/lib/table/interface'
|
|
|
+import Search from './components/Search.vue'
|
|
|
import { Device, DeviceHms } from '/@/types/device'
|
|
|
-import { IPage } from '/@/api/http/type'
|
|
|
-import { EDeviceTypeName, EHmsLevel } from '/@/types'
|
|
|
-import { getWorkspaceId } from '/@/utils/index'
|
|
|
-import moment from 'moment'
|
|
|
+import { apis } from '/@/api/custom'
|
|
|
|
|
|
const props = defineProps<{
|
|
|
visible: boolean,
|
|
|
@@ -94,101 +63,84 @@ function setVisible(v: boolean, e?: Event) {
|
|
|
emit('update:visible', v, e)
|
|
|
}
|
|
|
|
|
|
-const loading = ref(false)
|
|
|
+interface State {
|
|
|
+ query: any,
|
|
|
+ listLoading: boolean,
|
|
|
+ list: DeviceHms[],
|
|
|
+};
|
|
|
|
|
|
-const hmsColumns: ColumnProps[] = [
|
|
|
- { title: '告警开始|结束时间', dataIndex: 'create_time', width: '25%', className: 'titleStyle', slots: { customRender: 'time' } },
|
|
|
- { title: '告警等级', dataIndex: 'level', width: '120px', className: 'titleStyle', slots: { customRender: 'level' } },
|
|
|
- { title: '设备', dataIndex: 'domain', width: '12%', className: 'titleStyle', slots: { customRender: 'domain' } },
|
|
|
- { title: '错误码', dataIndex: 'key', width: '20%', className: 'titleStyle', ellipsis: true, slots: { customRender: 'code' } },
|
|
|
- { title: '告警内容', dataIndex: 'message_en', className: 'titleStyle', ellipsis: true, slots: { customRender: 'message' } },
|
|
|
- { title: '解决方案', dataIndex: 'message_zh', className: 'titleStyle', ellipsis: true, slots: { customRender: 'message' } },
|
|
|
-]
|
|
|
-
|
|
|
-interface DeviceHmsData {
|
|
|
- data: DeviceHms[]
|
|
|
-}
|
|
|
-
|
|
|
-const hmsData = reactive<DeviceHmsData>({
|
|
|
- data: []
|
|
|
-})
|
|
|
-
|
|
|
-type Pagination = TableState['pagination']
|
|
|
+const state: State = reactive({
|
|
|
+ query: undefined,
|
|
|
+ listLoading: false,
|
|
|
+ list: [],
|
|
|
+});
|
|
|
|
|
|
-const hmsPaginationProp = reactive({
|
|
|
+const paginationConfig = reactive({
|
|
|
pageSizeOptions: ['20', '50', '100'],
|
|
|
showQuickJumper: true,
|
|
|
showSizeChanger: true,
|
|
|
- pageSize: 50,
|
|
|
+ pageSize: 20,
|
|
|
current: 1,
|
|
|
total: 0
|
|
|
})
|
|
|
|
|
|
-// 获取分页信息
|
|
|
-function getPaginationBody() {
|
|
|
- return {
|
|
|
- page: hmsPaginationProp.current,
|
|
|
- page_size: hmsPaginationProp.pageSize
|
|
|
- } as IPage
|
|
|
+const fetchList = async () => {
|
|
|
+ state.listLoading = true;
|
|
|
+ try {
|
|
|
+ const res = await apis.fetchDeviceHmsList({
|
|
|
+ ...state.query,
|
|
|
+ language: 'zh',
|
|
|
+ page: paginationConfig.current,
|
|
|
+ page_size: paginationConfig.pageSize
|
|
|
+ });
|
|
|
+ if (res.code === 0) {
|
|
|
+ paginationConfig.total = res.data.pagination.total
|
|
|
+ paginationConfig.current = res.data.pagination.page
|
|
|
+ paginationConfig.pageSize = res.data.pagination.page_size
|
|
|
+ }
|
|
|
+ state.list = res.data.list;
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ } finally {
|
|
|
+ state.listLoading = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function showHms() {
|
|
|
+const showHms = async () => {
|
|
|
const dock = props.device
|
|
|
if (!dock) return
|
|
|
- // 先注释掉,这里机场与飞机合并在一起了
|
|
|
- // if (dock.domain === EDeviceTypeName.Dock) {
|
|
|
- // getDeviceHmsBySn(dock.device_sn, dock.children?.[0].device_sn ?? '')
|
|
|
- // }
|
|
|
- // if (dock.domain === EDeviceTypeName.Aircraft) {
|
|
|
- // param.domain = EDeviceTypeName.Aircraft
|
|
|
- // getDeviceHmsBySn('', dock.device_sn)
|
|
|
- // }
|
|
|
-}
|
|
|
-
|
|
|
-function refreshHmsData(page: Pagination) {
|
|
|
- hmsPaginationProp.current = page?.current!
|
|
|
- hmsPaginationProp.pageSize = page?.pageSize!
|
|
|
- getHms()
|
|
|
+ await fetchList()
|
|
|
}
|
|
|
|
|
|
-const param = reactive<HmsQueryBody>({
|
|
|
- sns: [],
|
|
|
- device_sn: '',
|
|
|
- children_sn: '',
|
|
|
- language: 'en',
|
|
|
- begin_time: new Date(new Date().setDate(new Date().getDate() - 7)).setHours(0, 0, 0, 0),
|
|
|
- end_time: new Date().setHours(23, 59, 59, 999),
|
|
|
- domain: -1,
|
|
|
- level: '',
|
|
|
- message: ''
|
|
|
-})
|
|
|
-
|
|
|
-const levels = [
|
|
|
+const columns = [
|
|
|
{
|
|
|
- label: '全部告警等级',
|
|
|
- value: ''
|
|
|
- }, {
|
|
|
- label: EHmsLevel[0],
|
|
|
- value: EHmsLevel.NOTICE
|
|
|
- }, {
|
|
|
- label: EHmsLevel[1],
|
|
|
- value: EHmsLevel.CAUTION
|
|
|
- }, {
|
|
|
- label: EHmsLevel[2],
|
|
|
- value: EHmsLevel.WARN
|
|
|
- }
|
|
|
-]
|
|
|
-
|
|
|
-const deviceTypes = [
|
|
|
+ title: '发生时间',
|
|
|
+ dataIndex: 'create_time',
|
|
|
+ width: 180,
|
|
|
+ slots: { customRender: 'time' }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '告警等级',
|
|
|
+ dataIndex: 'level',
|
|
|
+ width: 100,
|
|
|
+ slots: { customRender: 'level' }
|
|
|
+ },
|
|
|
{
|
|
|
- label: '全部设备',
|
|
|
- value: -1
|
|
|
- }, {
|
|
|
- label: EDeviceTypeName[EDeviceTypeName.Aircraft],
|
|
|
- value: EDeviceTypeName.Aircraft
|
|
|
- }, {
|
|
|
- label: EDeviceTypeName[EDeviceTypeName.Dock],
|
|
|
- value: EDeviceTypeName.Dock
|
|
|
+ title: '设备SN',
|
|
|
+ dataIndex: 'sn',
|
|
|
+ width: 150,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '错误码',
|
|
|
+ dataIndex: 'key',
|
|
|
+ ellipsis: true,
|
|
|
+ slots: { customRender: 'code' }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '告警内容',
|
|
|
+ dataIndex: 'message_zh',
|
|
|
+ ellipsis: true,
|
|
|
+ slots: { customRender: 'message' }
|
|
|
}
|
|
|
]
|
|
|
|
|
|
@@ -197,57 +149,25 @@ const rowClassName = (record: any, index: number) => {
|
|
|
if ((index & 1) === 0) {
|
|
|
className.push('table-striped')
|
|
|
}
|
|
|
- if (record.domain !== EDeviceTypeName.Dock) {
|
|
|
- className.push('child-row')
|
|
|
- }
|
|
|
return className.toString().replaceAll(',', ' ')
|
|
|
}
|
|
|
|
|
|
-const time = ref([moment(param.begin_time), moment(param.end_time)])
|
|
|
-
|
|
|
-function getHms() {
|
|
|
- loading.value = true
|
|
|
- getDeviceHms(param, getWorkspaceId(), getPaginationBody())
|
|
|
- .then(res => {
|
|
|
- hmsPaginationProp.total = res.data.pagination.total
|
|
|
- hmsPaginationProp.current = res.data.pagination.page
|
|
|
- hmsData.data = res.data.list
|
|
|
- hmsData.data.forEach(hms => {
|
|
|
- hms.domain = hms.sn === param.children_sn ? EDeviceTypeName.Aircraft : EDeviceTypeName.Dock
|
|
|
- })
|
|
|
- loading.value = false
|
|
|
- }).catch(_err => {
|
|
|
- loading.value = false
|
|
|
- })
|
|
|
+const refreshData = async (page: any) => {
|
|
|
+ paginationConfig.current = page?.current!
|
|
|
+ paginationConfig.pageSize = page?.pageSize!
|
|
|
+ await fetchList();
|
|
|
}
|
|
|
|
|
|
-function getDeviceHmsBySn(sn: string, childSn: string) {
|
|
|
- param.device_sn = sn
|
|
|
- param.children_sn = childSn
|
|
|
- param.sns = [param.device_sn, param.children_sn]
|
|
|
- getHms()
|
|
|
-}
|
|
|
-
|
|
|
-function onTimeChange(newTime: any[]) {
|
|
|
- param.begin_time = newTime[0].valueOf()
|
|
|
- param.end_time = newTime[1].valueOf()
|
|
|
- getHms()
|
|
|
-}
|
|
|
-
|
|
|
-function onDeviceTypeSelect(val: number) {
|
|
|
- param.sns = [param.device_sn, param.children_sn]
|
|
|
- if (val === EDeviceTypeName.Dock) {
|
|
|
- param.sns = [param.device_sn, '']
|
|
|
- }
|
|
|
- if (val === EDeviceTypeName.Aircraft) {
|
|
|
- param.sns = ['', param.children_sn]
|
|
|
- }
|
|
|
- getHms()
|
|
|
+// 点击搜索
|
|
|
+const onClickSearch = async (query: any) => {
|
|
|
+ state.query = query;
|
|
|
+ await fetchList();
|
|
|
}
|
|
|
|
|
|
-function onLevelSelect(val: number) {
|
|
|
- param.level = val
|
|
|
- getHms()
|
|
|
+// 点击重置
|
|
|
+const onClickReset = async (query: any) => {
|
|
|
+ state.query = query;
|
|
|
+ await fetchList();
|
|
|
}
|
|
|
</script>
|
|
|
|