AlarmNumTable.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div class="alarm-history-table">
  3. <BasicTable ref="alarmHistory" @register="registerTable" :data-source="dataSource">
  4. <template #bodyCell="{ column, record }">
  5. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : 'red'">{{
  6. record.warnFlag == '0' ? '正常' : '报警'
  7. }}</a-tag>
  8. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  9. record.netStatus == '0' ? '断开' : '连接'
  10. }}</a-tag>
  11. <template v-if="column.dataIndex === 'nwartype'">
  12. <!-- 除了 101(蓝色预警)其他都是红色字体 -->
  13. <span :class="{ 'color-#ff3823': ['102', '103', '104', '201', '1001'].includes(record.nwartype) }">
  14. {{ render.renderDictText(record.nwartype, 'leveltype') || '-' }}
  15. </span>
  16. </template>
  17. <slot name="filterCell" v-bind="{ column, record }"></slot>
  18. </template>
  19. </BasicTable>
  20. </div>
  21. </template>
  22. <script lang="ts" name="system-user" setup>
  23. //ts语法
  24. import { watch, ref, defineExpose, onMounted } from 'vue';
  25. import { BasicTable } from '/@/components/Table';
  26. import { useListPage } from '/@/hooks/system/useListPage';
  27. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  28. import { defHttp } from '/@/utils/http/axios';
  29. import dayjs from 'dayjs';
  30. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  31. import { usePermission } from '/@/hooks/web/usePermission';
  32. const props = defineProps({
  33. columnsType: {
  34. type: String,
  35. required: true,
  36. },
  37. columns: {
  38. type: Array,
  39. // required: true,
  40. default: () => [],
  41. },
  42. deviceType: {
  43. type: String,
  44. required: true,
  45. },
  46. deviceListApi: {
  47. type: Function,
  48. },
  49. designScope: {
  50. type: String,
  51. },
  52. sysId: {
  53. type: String,
  54. },
  55. deviceId: {
  56. type: String,
  57. default: '',
  58. },
  59. scroll: {
  60. type: Object,
  61. default: { y: 0 },
  62. },
  63. list: {
  64. type: Function,
  65. default: (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params }),
  66. },
  67. });
  68. const { hasPermission } = usePermission();
  69. const getAlarmLogNumApi = (params) => defHttp.post({ url: '/safety/ventanalyAlarmLog/queryAlarmLogNumByType', params });
  70. const alarmHistory = ref();
  71. const columns = ref([]);
  72. const dataSource = ref([]);
  73. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  74. async function getDeviceList() {
  75. const formData = getForm().getFieldsValue();
  76. const params = {
  77. deviceType: 'windrect_ds',
  78. starttime: formData['createTime_begin'],
  79. endtime: formData['createTime_end'],
  80. };
  81. const res = await getAlarmLogNumApi(params);
  82. const flattenedData = res.result.map((item) => {
  83. return {
  84. deviceid: item.deviceid,
  85. devicename: item.devicename,
  86. ...item.alarmTypeCounts,
  87. };
  88. });
  89. dataSource.value = flattenedData;
  90. }
  91. watch(
  92. () => {
  93. return props.columnsType;
  94. },
  95. async (newVal) => {
  96. if (!newVal) return;
  97. const column = getTableHeaderColumns(props.deviceType + '_alarmNum');
  98. columns.value = column;
  99. // if (alarmHistory.value) reload();
  100. },
  101. {
  102. immediate: true,
  103. }
  104. );
  105. watch(
  106. () => props.deviceType,
  107. async () => {
  108. await getDeviceList();
  109. }
  110. );
  111. watch(
  112. () => props.scroll.y,
  113. (newVal) => {
  114. if (newVal) {
  115. tableScroll.value = { y: newVal - 100 };
  116. } else {
  117. tableScroll.value = {};
  118. }
  119. }
  120. );
  121. // 列表页面公共参数、方法
  122. const { tableContext } = useListPage({
  123. tableProps: {
  124. // api: props.list,
  125. columns: props.columnsType ? columns : (props.columns as any[]),
  126. canResize: true,
  127. showTableSetting: false,
  128. showActionColumn: !hasPermission('ventanalyAlarmAnalysis:noShow'),
  129. bordered: false,
  130. size: 'small',
  131. scroll: tableScroll,
  132. showIndexColumn: true,
  133. formConfig: {
  134. labelAlign: 'left',
  135. showAdvancedButton: false,
  136. // autoAdvancedCol: 2,
  137. schemas: [
  138. {
  139. field: 'createTime_begin',
  140. label: '开始时间',
  141. component: 'DatePicker',
  142. defaultValue: dayjs().add(-30, 'day').format('YYYY-MM-DD HH:mm:ss'),
  143. required: true,
  144. componentProps: {
  145. showTime: true,
  146. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  147. getPopupContainer: getAutoScrollContainer,
  148. },
  149. colProps: {
  150. span: 4,
  151. },
  152. },
  153. {
  154. field: 'createTime_end',
  155. label: '结束时间',
  156. component: 'DatePicker',
  157. defaultValue: dayjs(),
  158. required: true,
  159. componentProps: {
  160. showTime: true,
  161. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  162. getPopupContainer: getAutoScrollContainer,
  163. },
  164. colProps: {
  165. span: 4,
  166. },
  167. },
  168. ],
  169. // fieldMapToTime: [['createTime', ['createTime_begin', 'createTime_end'], '']],
  170. },
  171. // fetchSetting: {
  172. // listField: 'records',
  173. // },
  174. pagination: {
  175. current: 1,
  176. pageSize: 10,
  177. pageSizeOptions: ['10', '30', '50', '100'],
  178. },
  179. beforeFetch(params) {
  180. params.devicetype = props.deviceType + '*';
  181. if (props.sysId) {
  182. params.sysId = props.sysId;
  183. }
  184. },
  185. },
  186. });
  187. //注册table数据
  188. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  189. onMounted(async () => {
  190. await getDeviceList();
  191. });
  192. defineExpose({ setLoading });
  193. </script>
  194. <style scoped lang="less">
  195. @ventSpace: zxm;
  196. :deep(.ventSpace-table-body) {
  197. height: auto !important;
  198. }
  199. :deep(.zxm-picker) {
  200. height: 30px !important;
  201. }
  202. .alarm-history-table {
  203. width: 100%;
  204. :deep(.jeecg-basic-table-form-container) {
  205. .@{ventSpace}-form {
  206. padding: 0 !important;
  207. border: none !important;
  208. margin-bottom: 0 !important;
  209. .@{ventSpace}-picker,
  210. .@{ventSpace}-select-selector {
  211. width: 100% !important;
  212. background: #00000017;
  213. border: 1px solid #b7b7b7;
  214. input,
  215. .@{ventSpace}-select-selection-item,
  216. .@{ventSpace}-picker-suffix {
  217. color: #fff;
  218. }
  219. .@{ventSpace}-select-selection-placeholder {
  220. color: #ffffffaa;
  221. }
  222. }
  223. }
  224. .@{ventSpace}-table-title {
  225. min-height: 0 !important;
  226. }
  227. }
  228. }
  229. </style>