1
0

AlarmHistoryTable.vue 8.2 KB

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