AlarmHistoryTable.vue 9.4 KB

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