index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="page">
  3. <el-card shadow="nover">
  4. <el-form :model="tableData.param" ref="queryRef" inline label-width="68px">
  5. <el-form-item label="创建时间" prop="dateRange">
  6. <el-date-picker v-model="tableData.param.dateRange" style="width: 240px" value-format="YYYY-MM-DD" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  7. </el-form-item>
  8. <el-form-item label="告警状态" prop="status" style="width: 200px;">
  9. <el-select v-model="tableData.param.status" placeholder="告警状态" clearable style="width: 240px">
  10. <el-option label="未处理" :value="0" />
  11. <el-option label="已处理" :value="1" />
  12. <el-option label="已忽略" :value="2" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" class="ml10" @click="typeList">
  17. <el-icon>
  18. <ele-Search />
  19. </el-icon>
  20. 查询
  21. </el-button>
  22. <el-button @click="resetQuery(queryRef)">
  23. <el-icon>
  24. <ele-Refresh />
  25. </el-icon>
  26. 重置
  27. </el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-table :data="tableData.data" style="width: 100%" v-loading="tableData.loading" max-height="calc(100vh - 255px)">
  31. <el-table-column label="ID" align="center" prop="id" width="100" v-col="'ID'" />
  32. <el-table-column label="告警类型" prop="type" width="120" show-overflow-tooltip v-col="'type'">
  33. <template #default="scope">
  34. <span v-if="scope.row.type == 1">规则告警</span>
  35. <span v-else-if="scope.row.type == 2">设备自主告警</span>
  36. <span v-else-if="scope.row.type == 3">规侧告警升级</span>
  37. <span v-else>设备自主告警</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="规则级别" prop="alarmLevel.name" width="100" align="center" show-overflow-tooltip v-col="'alarmLevel'"></el-table-column>
  41. <el-table-column label="规则名称" prop="ruleName" show-overflow-tooltip v-col="'ruleName'" />
  42. <el-table-column label="产品标识" prop="productKey" show-overflow-tooltip v-col="'productKey'" />
  43. <el-table-column label="设备标识" prop="deviceKey" show-overflow-tooltip v-col="'deviceKey'" />
  44. <el-table-column prop="status" label="告警状态" width="100" align="center" v-col="'status'">
  45. <template #default="scope">
  46. <el-tag type="danger" size="small" v-if="scope.row.status == 0">未处理</el-tag>
  47. <el-tag type="success" size="small" v-if="scope.row.status == 1">已处理</el-tag>
  48. <el-tag type="info" size="small" v-if="scope.row.status == 2">已忽略</el-tag>
  49. </template>
  50. </el-table-column>
  51. <el-table-column prop="createdAt" label="告警时间" align="center" width="160" v-col="'createdAt'"></el-table-column>
  52. <el-table-column label="操作" width="140" align="center" fixed="right" v-col="'handle'">
  53. <template #default="scope">
  54. <el-button size="small" text type="primary" @click="onOpenDetailDic(scope.row)" v-auth="'detail'">详情</el-button>
  55. <el-button size="small" text type="warning" @click="onOpenEditDic(scope.row)" v-if="scope.row.status == 0" v-auth="'edit'">处理</el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="typeList" />
  60. <EditDic ref="editDicRef" @dataList="typeList" />
  61. <DetailDic ref="detailRef" @dataList="typeList" />
  62. </el-card>
  63. </div>
  64. </template>
  65. <script lang="ts">
  66. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  67. import { FormInstance } from 'element-plus';
  68. import api from '/@/api/alarm';
  69. import EditDic from './component/edit.vue';
  70. import DetailDic from './component/detail.vue';
  71. // 定义接口来定义对象的类型
  72. interface TableDataRow {
  73. id: number;
  74. name: string;
  75. deviceType: string;
  76. status: number;
  77. desc: string;
  78. createBy: string;
  79. }
  80. interface TableDataState {
  81. ids: number[];
  82. tableData: {
  83. data: Array<TableDataRow>;
  84. total: number;
  85. loading: boolean;
  86. param: {
  87. pageNum: number;
  88. pageSize: number;
  89. dateRange: string[];
  90. status: string;
  91. };
  92. };
  93. }
  94. export default defineComponent({
  95. name: 'log',
  96. components: { EditDic, DetailDic },
  97. setup() {
  98. const addDicRef = ref();
  99. const editDicRef = ref();
  100. const detailRef = ref();
  101. const queryRef = ref();
  102. const state = reactive<TableDataState>({
  103. ids: [],
  104. tableData: {
  105. data: [],
  106. total: 0,
  107. loading: false,
  108. param: {
  109. pageNum: 1,
  110. pageSize: 20,
  111. status: '',
  112. dateRange: [],
  113. },
  114. },
  115. });
  116. // 初始化表格数据
  117. const initTableData = () => {
  118. typeList();
  119. };
  120. const typeList = () => {
  121. state.tableData.loading = true;
  122. api.log
  123. .getList(state.tableData.param)
  124. .then((res: any) => {
  125. state.tableData.data = res.list;
  126. state.tableData.total = res.Total;
  127. })
  128. .finally(() => (state.tableData.loading = false));
  129. };
  130. //打开详情页
  131. const onOpenDetailDic = (row: TableDataRow) => {
  132. detailRef.value.openDialog(row);
  133. };
  134. // 打开新增产品弹窗
  135. const onOpenAddDic = () => {
  136. editDicRef.value.openDialog();
  137. };
  138. // 打开修改产品弹窗
  139. const onOpenEditDic = (row: TableDataRow) => {
  140. editDicRef.value.openDialog(row);
  141. };
  142. // 页面加载时
  143. onMounted(() => {
  144. initTableData();
  145. });
  146. /** 重置按钮操作 */
  147. const resetQuery = (formEl: FormInstance | undefined) => {
  148. if (!formEl) return;
  149. formEl.resetFields();
  150. typeList();
  151. };
  152. // 多选框选中数据
  153. const handleSelectionChange = (selection: TableDataRow[]) => {
  154. state.ids = selection.map((item) => item.id);
  155. };
  156. return {
  157. addDicRef,
  158. editDicRef,
  159. queryRef,
  160. detailRef,
  161. onOpenDetailDic,
  162. onOpenAddDic,
  163. onOpenEditDic,
  164. typeList,
  165. resetQuery,
  166. handleSelectionChange,
  167. ...toRefs(state),
  168. };
  169. },
  170. });
  171. </script>