AlarmHistoryTable.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="alarm-history-table">
  3. <BasicTable ref="alarmHistory" @register="registerTable">
  4. <template #form-onExportXls>
  5. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls()"> 导出</a-button>
  6. </template>
  7. </BasicTable>
  8. </div>
  9. </template>
  10. <script lang="ts" name="safetyAlarm" setup>
  11. //ts语法
  12. import { watch, ref, defineExpose, inject, onMounted } from 'vue';
  13. import { BasicTable } from '/@/components/Table';
  14. import { useListPage } from '/@/hooks/system/useListPage';
  15. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  16. import { defHttp } from '/@/utils/http/axios';
  17. import dayjs from 'dayjs';
  18. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  19. import { safetyDeviceList, safetyList } from '../safetyMonitor/safety.api';
  20. import { getDictItemsByCode } from '/@/utils/dict';
  21. const props = defineProps({
  22. columnsType: {
  23. type: String,
  24. required: true,
  25. },
  26. columns: {
  27. type: Array,
  28. // required: true,
  29. default: () => [],
  30. },
  31. deviceType: {
  32. type: String,
  33. required: true,
  34. },
  35. deviceListApi: {
  36. type: Function,
  37. },
  38. designScope: {
  39. type: String,
  40. },
  41. sysId: {
  42. type: String,
  43. },
  44. scroll: {
  45. type: Object,
  46. default: { y: 0 },
  47. },
  48. list: {
  49. type: Function,
  50. default: (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params }),
  51. },
  52. });
  53. const getDeviceListApi = (params) => defHttp.post({ url: '/monitor/device', params });
  54. const globalConfig = inject('globalConfig');
  55. const alarmHistory = ref();
  56. const columns = ref([]);
  57. const deviceOptions = ref([]);
  58. const dataTypeName = ref('');
  59. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  60. async function getDeviceList() {
  61. let result;
  62. const res = await getDeviceListApi({ devicetype: props.deviceType, filterParams: { dataTypeName: dataTypeName.value }, pageSize: 10000 });
  63. if (res['records'] && res['records'].length > 0) {
  64. result = res['records'];
  65. } else if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
  66. result = res['msgTxt'][0]['datalist'];
  67. }
  68. if (result && result.length > 0) {
  69. deviceOptions.value = [];
  70. deviceOptions.value = result.map((item, index) => {
  71. return {
  72. label: item['strinstallpos'],
  73. value: item['id'] || item['deviceID'],
  74. strtype: item['strtype'] || item['deviceType'],
  75. strinstallpos: item['strinstallpos'],
  76. devicekind: item['devicekind'],
  77. stationtype: item['stationtype'],
  78. };
  79. });
  80. } else {
  81. deviceOptions.value = [];
  82. }
  83. await getForm().setFieldsValue({ deviceId: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '' });
  84. }
  85. watch(
  86. () => {
  87. return props.columnsType;
  88. },
  89. async (newVal) => {
  90. if (!newVal) return;
  91. let column;
  92. column = getTableHeaderColumns('safetymonitor_warning');
  93. if (!column || column.length < 1) {
  94. column = getTableHeaderColumns(newVal + '_history');
  95. }
  96. if (column && column.length < 1) {
  97. const arr = newVal.split('_');
  98. const columnKey = arr.reduce((prev, cur, index) => {
  99. if (index !== arr.length - 2) {
  100. return prev + '_' + cur;
  101. } else {
  102. return prev;
  103. }
  104. });
  105. columns.value = getTableHeaderColumns(arr[0] + '_history');
  106. } else {
  107. columns.value = column;
  108. }
  109. if (alarmHistory.value) reload();
  110. },
  111. {
  112. immediate: true,
  113. }
  114. );
  115. watch(
  116. () => props.deviceType,
  117. async () => {
  118. if (alarmHistory.value) getForm().resetFields();
  119. await getDeviceList();
  120. }
  121. );
  122. watch(
  123. () => props.scroll.y,
  124. (newVal) => {
  125. if (newVal) {
  126. tableScroll.value = { y: newVal - 100 };
  127. } else {
  128. tableScroll.value = {};
  129. }
  130. }
  131. );
  132. // 列表页面公共参数、方法
  133. const { tableContext, onExportXls } = useListPage({
  134. tableProps: {
  135. api: safetyList,
  136. columns: props.columnsType ? columns : (props.columns as any[]),
  137. canResize: false,
  138. showTableSetting: false,
  139. showActionColumn: false,
  140. bordered: false,
  141. showIndexColumn: true,
  142. size: 'small',
  143. scroll: tableScroll,
  144. formConfig: {
  145. labelAlign: 'left',
  146. showAdvancedButton: false,
  147. // autoAdvancedCol: 2,
  148. actionColOptions: {
  149. xs: 4, // <576px
  150. sm: 14, // ≥576px
  151. md: 4, // ≥768px
  152. lg: 4, // ≥992px
  153. xl: 4, // ≥1200px
  154. xxl: 4, // ≥1600px
  155. style: { textAlign: 'left' },
  156. },
  157. schemas: [
  158. {
  159. field: 'startTime',
  160. label: '开始时间',
  161. component: 'DatePicker',
  162. defaultValue: dayjs().add(-30, 'day').format('YYYY-MM-DD HH:mm:ss'),
  163. required: true,
  164. componentProps: {
  165. showTime: true,
  166. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  167. getPopupContainer: getAutoScrollContainer,
  168. },
  169. colProps: {
  170. span: 4,
  171. },
  172. },
  173. {
  174. field: 'endTime',
  175. label: '结束时间',
  176. component: 'DatePicker',
  177. defaultValue: dayjs(),
  178. required: true,
  179. componentProps: {
  180. showTime: true,
  181. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  182. getPopupContainer: getAutoScrollContainer,
  183. },
  184. colProps: {
  185. span: 4,
  186. },
  187. },
  188. {
  189. label: '设备类型',
  190. field: 'dataTypeName',
  191. component: 'ApiSelect',
  192. componentProps: {
  193. api: getDictItemsByCode.bind(null, 'safetySensorAlarm'),
  194. onChange: async (e, option) => {
  195. dataTypeName.value = e;
  196. await getDeviceList();
  197. },
  198. },
  199. colProps: {
  200. span: 4,
  201. },
  202. },
  203. {
  204. label: '查询设备',
  205. field: 'deviceId',
  206. component: 'Select',
  207. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  208. componentProps: {
  209. showSearch: true,
  210. filterOption: (input: string, option: any) => {
  211. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  212. },
  213. options: deviceOptions,
  214. },
  215. colProps: {
  216. span: 4,
  217. },
  218. },
  219. ],
  220. },
  221. fetchSetting: {
  222. listField: 'records',
  223. },
  224. pagination: {
  225. current: 1,
  226. pageSize: 10,
  227. pageSizeOptions: ['10', '30', '50', '100'],
  228. },
  229. // beforeFetch(params) {
  230. // params.devicetype = props.deviceType + '*';
  231. // if (props.sysId) {
  232. // params.sysId = props.sysId;
  233. // }
  234. // },
  235. },
  236. exportConfig: {
  237. name: '预警历史列表',
  238. url: '/safety/ventanalyAlarmLog/exportXls',
  239. },
  240. });
  241. //注册table数据
  242. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  243. onMounted(async () => {
  244. await getDeviceList();
  245. });
  246. defineExpose({ setLoading });
  247. </script>
  248. <style scoped lang="less">
  249. @ventSpace: zxm;
  250. :deep(.ventSpace-table-body) {
  251. height: auto !important;
  252. }
  253. :deep(.zxm-picker) {
  254. height: 30px !important;
  255. }
  256. .alarm-history-table {
  257. width: 100%;
  258. :deep(.jeecg-basic-table-form-container) {
  259. .@{ventSpace}-form {
  260. padding: 0 !important;
  261. border: none !important;
  262. margin-bottom: 0 !important;
  263. .@{ventSpace}-picker,
  264. .@{ventSpace}-select-selector {
  265. width: 100% !important;
  266. background: #00000017;
  267. border: 1px solid #b7b7b7;
  268. input,
  269. .@{ventSpace}-select-selection-item,
  270. .@{ventSpace}-picker-suffix {
  271. color: #fff;
  272. }
  273. .@{ventSpace}-select-selection-placeholder {
  274. color: #ffffffaa;
  275. }
  276. }
  277. }
  278. .@{ventSpace}-table-title {
  279. min-height: 0 !important;
  280. }
  281. }
  282. }
  283. </style>