AlarmHistoryTable.vue 10 KB

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