AlarmHistoryTable.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. actionColOptions: {
  148. xs: 4, // <576px
  149. sm: 14, // ≥576px
  150. md: 4, // ≥768px
  151. lg: 4, // ≥992px
  152. xl: 4, // ≥1200px
  153. xxl: 4, // ≥1600px
  154. style: { textAlign: 'left' },
  155. },
  156. schemas: [
  157. {
  158. field: 'startTime',
  159. label: '开始时间',
  160. component: 'DatePicker',
  161. defaultValue: dayjs().startOf('date'),
  162. required: true,
  163. componentProps: {
  164. showTime: true,
  165. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  166. getPopupContainer: getAutoScrollContainer,
  167. },
  168. colProps: {
  169. span: 4,
  170. },
  171. },
  172. {
  173. field: 'endTime',
  174. label: '结束时间',
  175. component: 'DatePicker',
  176. defaultValue: dayjs(),
  177. required: true,
  178. componentProps: {
  179. showTime: true,
  180. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  181. getPopupContainer: getAutoScrollContainer,
  182. },
  183. colProps: {
  184. span: 4,
  185. },
  186. },
  187. {
  188. label: '设备类型',
  189. field: 'dataTypeName',
  190. component: 'ApiSelect',
  191. componentProps: {
  192. api: safetyDeviceList.bind(null, { devicetype: 'safetymonitor', code: 'dataTypeName' }),
  193. labelField: 'name',
  194. valueField: 'code',
  195. onChange: async (e, option) => {
  196. console.log('1111', e, option);
  197. dataTypeName.value = e;
  198. await getDeviceList();
  199. },
  200. },
  201. colProps: {
  202. span: 4,
  203. },
  204. },
  205. {
  206. label: '查询设备',
  207. field: 'deviceId',
  208. component: 'Select',
  209. defaultValue: deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  210. componentProps: {
  211. showSearch: true,
  212. filterOption: (input: string, option: any) => {
  213. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  214. },
  215. options: deviceOptions,
  216. },
  217. colProps: {
  218. span: 4,
  219. },
  220. },
  221. {
  222. label: '是否解决',
  223. field: 'isok',
  224. component: 'Select',
  225. componentProps: {
  226. options: [
  227. {
  228. label: '未解决',
  229. value: '0',
  230. },
  231. {
  232. label: '已解决',
  233. value: '1',
  234. },
  235. ],
  236. },
  237. colProps: { span: 4 },
  238. },
  239. ],
  240. },
  241. fetchSetting: {
  242. listField: 'records',
  243. },
  244. pagination: {
  245. current: 1,
  246. pageSize: 10,
  247. pageSizeOptions: ['10', '30', '50', '100'],
  248. },
  249. // beforeFetch(params) {
  250. // params.devicetype = props.deviceType + '*';
  251. // if (props.sysId) {
  252. // params.sysId = props.sysId;
  253. // }
  254. // },
  255. },
  256. exportConfig: {
  257. name: '预警历史列表',
  258. url: '/safety/ventanalyAlarmLog/exportXls',
  259. },
  260. });
  261. //注册table数据
  262. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  263. onMounted(async () => {
  264. await getDeviceList();
  265. });
  266. defineExpose({ setLoading });
  267. </script>
  268. <style scoped lang="less">
  269. @ventSpace: zxm;
  270. :deep(.ventSpace-table-body) {
  271. height: auto !important;
  272. }
  273. :deep(.zxm-picker) {
  274. height: 30px !important;
  275. }
  276. .alarm-history-table {
  277. width: 100%;
  278. :deep(.jeecg-basic-table-form-container) {
  279. .@{ventSpace}-form {
  280. padding: 0 !important;
  281. border: none !important;
  282. margin-bottom: 0 !important;
  283. .@{ventSpace}-picker,
  284. .@{ventSpace}-select-selector {
  285. width: 100% !important;
  286. background: #00000017;
  287. border: 1px solid #b7b7b7;
  288. input,
  289. .@{ventSpace}-select-selection-item,
  290. .@{ventSpace}-picker-suffix {
  291. color: #fff;
  292. }
  293. .@{ventSpace}-select-selection-placeholder {
  294. color: #ffffffaa;
  295. }
  296. }
  297. }
  298. .@{ventSpace}-table-title {
  299. min-height: 0 !important;
  300. }
  301. }
  302. }
  303. </style>