AlarmHistoryTable.vue 8.9 KB

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