AlarmHistoryTable.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. const column = getTableHeaderColumns(newVal + '_history');
  91. if (column && column.length < 1) {
  92. const arr = newVal.split('_');
  93. const columnKey = arr.reduce((prev, cur, index) => {
  94. if (index !== arr.length - 2) {
  95. return prev + '_' + cur;
  96. } else {
  97. return prev;
  98. }
  99. });
  100. columns.value = getTableHeaderColumns(arr[0] + '_history');
  101. } else {
  102. columns.value = column;
  103. }
  104. if (alarmHistory.value) reload();
  105. },
  106. {
  107. immediate: true,
  108. }
  109. );
  110. watch(
  111. () => props.deviceType,
  112. async () => {
  113. if (alarmHistory.value) getForm().resetFields();
  114. await getDeviceList();
  115. }
  116. );
  117. watch(
  118. () => props.scroll.y,
  119. (newVal) => {
  120. if (newVal) {
  121. tableScroll.value = { y: newVal - 100 };
  122. } else {
  123. tableScroll.value = {};
  124. }
  125. }
  126. );
  127. // 列表页面公共参数、方法
  128. const { tableContext, onExportXls } = useListPage({
  129. tableProps: {
  130. api: safetyList,
  131. columns: props.columnsType ? columns : (props.columns as any[]),
  132. canResize: true,
  133. showTableSetting: false,
  134. showActionColumn: false,
  135. bordered: false,
  136. size: 'small',
  137. scroll: tableScroll,
  138. formConfig: {
  139. labelAlign: 'left',
  140. showAdvancedButton: false,
  141. // autoAdvancedCol: 2,
  142. schemas: [
  143. {
  144. field: 'startTime',
  145. label: '开始时间',
  146. component: 'DatePicker',
  147. defaultValue: dayjs().add(-30, 'day').format('YYYY-MM-DD HH:mm:ss'),
  148. required: true,
  149. componentProps: {
  150. showTime: true,
  151. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  152. getPopupContainer: getAutoScrollContainer,
  153. },
  154. colProps: {
  155. span: 4,
  156. },
  157. },
  158. {
  159. field: 'endTime',
  160. label: '结束时间',
  161. component: 'DatePicker',
  162. defaultValue: dayjs(),
  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. label: '设备类型',
  175. field: 'dataTypeName',
  176. component: 'ApiSelect',
  177. componentProps: {
  178. api: safetyDeviceList.bind(null, { devicetype: 'safetymonitor', code: 'dataTypeName' }),
  179. labelField: 'name',
  180. valueField: 'code',
  181. onChange: async (e, option) => {
  182. console.log('1111', e, option);
  183. dataTypeName.value = e;
  184. await getDeviceList();
  185. },
  186. },
  187. colProps: {
  188. span: 4,
  189. },
  190. },
  191. {
  192. label: '查询设备',
  193. field: 'deviceId',
  194. component: 'Select',
  195. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  196. componentProps: {
  197. showSearch: true,
  198. filterOption: (input: string, option: any) => {
  199. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  200. },
  201. options: deviceOptions,
  202. },
  203. colProps: {
  204. span: 4,
  205. },
  206. },
  207. ],
  208. },
  209. fetchSetting: {
  210. listField: 'records',
  211. },
  212. pagination: {
  213. current: 1,
  214. pageSize: 10,
  215. pageSizeOptions: ['10', '30', '50', '100'],
  216. },
  217. // beforeFetch(params) {
  218. // params.devicetype = props.deviceType + '*';
  219. // if (props.sysId) {
  220. // params.sysId = props.sysId;
  221. // }
  222. // },
  223. },
  224. exportConfig: {
  225. name: '预警历史列表',
  226. url: '/safety/ventanalyAlarmLog/exportXls',
  227. },
  228. });
  229. //注册table数据
  230. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  231. onMounted(async () => {
  232. await getDeviceList();
  233. });
  234. defineExpose({ setLoading });
  235. </script>
  236. <style scoped lang="less">
  237. @ventSpace: zxm;
  238. :deep(.ventSpace-table-body) {
  239. height: auto !important;
  240. }
  241. :deep(.zxm-picker) {
  242. height: 30px !important;
  243. }
  244. .alarm-history-table {
  245. width: 100%;
  246. :deep(.jeecg-basic-table-form-container) {
  247. .@{ventSpace}-form {
  248. padding: 0 !important;
  249. border: none !important;
  250. margin-bottom: 0 !important;
  251. .@{ventSpace}-picker,
  252. .@{ventSpace}-select-selector {
  253. width: 100% !important;
  254. background: #00000017;
  255. border: 1px solid #b7b7b7;
  256. input,
  257. .@{ventSpace}-select-selection-item,
  258. .@{ventSpace}-picker-suffix {
  259. color: #fff;
  260. }
  261. .@{ventSpace}-select-selection-placeholder {
  262. color: #ffffffaa;
  263. }
  264. }
  265. }
  266. .@{ventSpace}-table-title {
  267. min-height: 0 !important;
  268. }
  269. }
  270. }
  271. </style>