AlarmHistoryTable.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. showIndexColumn: true,
  167. formConfig: {
  168. labelAlign: 'left',
  169. showAdvancedButton: false,
  170. // autoAdvancedCol: 2,
  171. schemas: [
  172. {
  173. field: 'createTime_begin',
  174. label: '开始时间',
  175. component: 'DatePicker',
  176. defaultValue: dayjs().add(-30, 'day').format('YYYY-MM-DD HH:mm:ss'),
  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. field: 'createTime_end',
  189. label: '结束时间',
  190. component: 'DatePicker',
  191. defaultValue: dayjs(),
  192. required: true,
  193. componentProps: {
  194. showTime: true,
  195. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  196. getPopupContainer: getAutoScrollContainer,
  197. },
  198. colProps: {
  199. span: 4,
  200. },
  201. },
  202. {
  203. label: '查询设备',
  204. field: 'deviceid',
  205. component: 'Select',
  206. defaultValue: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
  207. componentProps: {
  208. showSearch: true,
  209. filterOption: (input: string, option: any) => {
  210. return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  211. },
  212. options: deviceOptions,
  213. },
  214. colProps: {
  215. span: 4,
  216. },
  217. },
  218. {
  219. label: '是否解决',
  220. field: 'isok',
  221. component: 'Select',
  222. componentProps: {
  223. options: [
  224. {
  225. label: '未解决',
  226. value: '0',
  227. },
  228. {
  229. label: '已解决',
  230. value: '1',
  231. },
  232. ],
  233. },
  234. colProps: { span: 4 },
  235. },
  236. ],
  237. // fieldMapToTime: [['createTime', ['createTime_begin', 'createTime_end'], '']],
  238. },
  239. fetchSetting: {
  240. listField: 'records',
  241. },
  242. pagination: {
  243. current: 1,
  244. pageSize: 10,
  245. pageSizeOptions: ['10', '30', '50', '100'],
  246. },
  247. beforeFetch(params) {
  248. params.devicetype = props.deviceType + '*';
  249. if (props.sysId) {
  250. params.sysId = props.sysId;
  251. }
  252. },
  253. },
  254. exportConfig: {
  255. name: '预警历史列表',
  256. url: '/safety/ventanalyAlarmLog/exportXls',
  257. },
  258. });
  259. //注册table数据
  260. const [registerTable, { reload, setLoading, getForm }] = tableContext;
  261. onMounted(async () => {
  262. await getDeviceList();
  263. });
  264. defineExpose({ setLoading });
  265. </script>
  266. <style scoped lang="less">
  267. @ventSpace: zxm;
  268. :deep(.ventSpace-table-body) {
  269. height: auto !important;
  270. }
  271. :deep(.zxm-picker) {
  272. height: 30px !important;
  273. }
  274. .alarm-history-table {
  275. width: 100%;
  276. :deep(.jeecg-basic-table-form-container) {
  277. .@{ventSpace}-form {
  278. padding: 0 !important;
  279. border: none !important;
  280. margin-bottom: 0 !important;
  281. .@{ventSpace}-picker,
  282. .@{ventSpace}-select-selector {
  283. width: 100% !important;
  284. background: #00000017;
  285. border: 1px solid #b7b7b7;
  286. input,
  287. .@{ventSpace}-select-selection-item,
  288. .@{ventSpace}-picker-suffix {
  289. color: #fff;
  290. }
  291. .@{ventSpace}-select-selection-placeholder {
  292. color: #ffffffaa;
  293. }
  294. }
  295. }
  296. .@{ventSpace}-table-title {
  297. min-height: 0 !important;
  298. }
  299. }
  300. }
  301. </style>