AlarmHistoryTable.vue 8.8 KB

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