AlarmHistoryTable.vue 8.4 KB

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