AlarmHistoryTable.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 deviceTypeOptions = ref(getDictItemsByCode('safetySensorAlarm'));
  59. const dataTypeName = ref('');
  60. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({});
  61. async function getDeviceList() {
  62. let result;
  63. const res = await getDeviceListApi({ devicetype: props.deviceType, filterParams: { dataTypeName: dataTypeName.value }, pageSize: 10000 });
  64. if (res['records'] && res['records'].length > 0) {
  65. result = res['records'];
  66. } else if (res['msgTxt'] && res['msgTxt'][0] && res['msgTxt'][0]['datalist']) {
  67. result = res['msgTxt'][0]['datalist'];
  68. }
  69. if (result && result.length > 0) {
  70. deviceOptions.value = [];
  71. deviceOptions.value = result.map((item, index) => {
  72. return {
  73. label: item['strinstallpos'],
  74. value: item['id'] || item['deviceID'],
  75. strtype: item['strtype'] || item['deviceType'],
  76. strinstallpos: item['strinstallpos'],
  77. devicekind: item['devicekind'],
  78. stationtype: item['stationtype'],
  79. };
  80. });
  81. } else {
  82. deviceOptions.value = [];
  83. }
  84. await getForm().setFieldsValue({ deviceId: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '' });
  85. }
  86. watch(
  87. () => {
  88. return props.columnsType;
  89. },
  90. async (newVal) => {
  91. if (!newVal) return;
  92. let column;
  93. column = getTableHeaderColumns('safetymonitor_warning');
  94. if (!column || column.length < 1) {
  95. column = getTableHeaderColumns(newVal + '_history');
  96. }
  97. if (column && column.length < 1) {
  98. const arr = newVal.split('_');
  99. const columnKey = arr.reduce((prev, cur, index) => {
  100. if (index !== arr.length - 2) {
  101. return prev + '_' + cur;
  102. } else {
  103. return prev;
  104. }
  105. });
  106. columns.value = getTableHeaderColumns(arr[0] + '_history');
  107. } else {
  108. columns.value = column;
  109. }
  110. if (alarmHistory.value) reload();
  111. },
  112. {
  113. immediate: true,
  114. }
  115. );
  116. watch(
  117. () => props.deviceType,
  118. async () => {
  119. if (alarmHistory.value) getForm().resetFields();
  120. dataTypeName.value = deviceTypeOptions.value[0] ? deviceTypeOptions.value[0]['value'] : '';
  121. await getDeviceList();
  122. }
  123. );
  124. watch(
  125. () => props.scroll.y,
  126. (newVal) => {
  127. if (newVal) {
  128. tableScroll.value = { y: newVal - 100 };
  129. } else {
  130. tableScroll.value = {};
  131. }
  132. }
  133. );
  134. // 列表页面公共参数、方法
  135. const { tableContext, onExportXls } = useListPage({
  136. tableProps: {
  137. api: safetyList,
  138. columns: props.columnsType ? columns : (props.columns as any[]),
  139. canResize: false,
  140. showTableSetting: false,
  141. showActionColumn: false,
  142. bordered: false,
  143. showIndexColumn: true,
  144. size: 'small',
  145. scroll: tableScroll,
  146. formConfig: {
  147. labelAlign: 'left',
  148. showAdvancedButton: false,
  149. // autoAdvancedCol: 2,
  150. actionColOptions: {
  151. xs: 4, // <576px
  152. sm: 14, // ≥576px
  153. md: 4, // ≥768px
  154. lg: 4, // ≥992px
  155. xl: 4, // ≥1200px
  156. xxl: 4, // ≥1600px
  157. style: { textAlign: 'left' },
  158. },
  159. schemas: [
  160. {
  161. field: 'startTime',
  162. label: '开始时间',
  163. component: 'DatePicker',
  164. defaultValue: dayjs().startOf('date'),
  165. required: true,
  166. componentProps: {
  167. showTime: true,
  168. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  169. getPopupContainer: getAutoScrollContainer,
  170. },
  171. colProps: {
  172. span: 4,
  173. },
  174. },
  175. {
  176. field: 'endTime',
  177. label: '结束时间',
  178. component: 'DatePicker',
  179. defaultValue: dayjs(),
  180. required: true,
  181. componentProps: {
  182. showTime: true,
  183. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  184. getPopupContainer: getAutoScrollContainer,
  185. },
  186. colProps: {
  187. span: 4,
  188. },
  189. },
  190. {
  191. label: '设备类型',
  192. field: 'dataTypeName',
  193. component: 'Select',
  194. defaultValue: deviceTypeOptions.value[0] ? deviceTypeOptions.value[0]['value'] : '',
  195. componentProps: {
  196. options: deviceTypeOptions.value,
  197. onChange: async (e, option) => {
  198. dataTypeName.value = e;
  199. await getDeviceList();
  200. },
  201. },
  202. colProps: {
  203. span: 4,
  204. },
  205. },
  206. {
  207. label: '查询设备',
  208. field: 'deviceId',
  209. component: 'Select',
  210. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  211. componentProps: {
  212. showSearch: true,
  213. filterOption: (input: string, option: any) => {
  214. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  215. },
  216. options: deviceOptions,
  217. },
  218. colProps: {
  219. span: 4,
  220. },
  221. },
  222. ],
  223. },
  224. fetchSetting: {
  225. listField: 'records',
  226. },
  227. pagination: {
  228. current: 1,
  229. pageSize: 10,
  230. pageSizeOptions: ['10', '30', '50', '100'],
  231. },
  232. // beforeFetch(params) {
  233. // params.devicetype = props.deviceType + '*';
  234. // if (props.sysId) {
  235. // params.sysId = props.sysId;
  236. // }
  237. // },
  238. },
  239. exportConfig: {
  240. name: '预警历史列表',
  241. url: '/safety/ventanalyAlarmLog/exportXls',
  242. },
  243. });
  244. //注册table数据
  245. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  246. onMounted(async () => {
  247. dataTypeName.value = deviceTypeOptions.value[0] ? deviceTypeOptions.value[0]['value'] : '';
  248. await getDeviceList();
  249. });
  250. defineExpose({ setLoading });
  251. </script>
  252. <style scoped lang="less">
  253. @ventSpace: zxm;
  254. :deep(.ventSpace-table-body) {
  255. height: auto !important;
  256. }
  257. :deep(.zxm-picker) {
  258. height: 30px !important;
  259. }
  260. .alarm-history-table {
  261. width: 100%;
  262. :deep(.jeecg-basic-table-form-container) {
  263. .@{ventSpace}-form {
  264. padding: 0 !important;
  265. border: none !important;
  266. margin-bottom: 0 !important;
  267. .@{ventSpace}-picker,
  268. .@{ventSpace}-select-selector {
  269. width: 100% !important;
  270. background: #00000017;
  271. border: 1px solid #b7b7b7;
  272. input,
  273. .@{ventSpace}-select-selection-item,
  274. .@{ventSpace}-picker-suffix {
  275. color: #fff;
  276. }
  277. .@{ventSpace}-select-selection-placeholder {
  278. color: #ffffffaa;
  279. }
  280. }
  281. }
  282. .@{ventSpace}-table-title {
  283. min-height: 0 !important;
  284. }
  285. }
  286. }
  287. </style>