AlarmHistoryTable.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="alarm-history-table">
  3. <BasicTable ref="alarmHistory" @register="registerTable" />
  4. </div>
  5. </template>
  6. <script lang="ts" name="system-user" setup>
  7. //ts语法
  8. import { watch, ref, defineExpose } from 'vue'
  9. import { BasicTable } from '/@/components/Table';
  10. import { useListPage } from '/@/hooks/system/useListPage';
  11. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  12. import { defHttp } from '/@/utils/http/axios';
  13. import dayjs from 'dayjs';
  14. const props = defineProps({
  15. columnsType: {
  16. type: String,
  17. required: true,
  18. },
  19. columns: {
  20. type: Array,
  21. // required: true,
  22. default: () => [],
  23. },
  24. deviceType: {
  25. type: String,
  26. required: true,
  27. },
  28. deviceListApi: {
  29. type: Function,
  30. required: true,
  31. },
  32. designScope: {
  33. type: String,
  34. },
  35. sysId: {
  36. type: String,
  37. },
  38. scroll: {
  39. type: Object,
  40. default: { y: 0 }
  41. },
  42. list: {
  43. type: Function,
  44. default: (params) => defHttp.get({ url: '/safety/ventanalyAlarmLog/list', params })
  45. }
  46. });
  47. const alarmHistory = ref()
  48. const columns = ref([])
  49. let deviceOptions = <any[]>[]
  50. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({})
  51. async function getDeviceList() {
  52. let result;
  53. result = await props.deviceListApi()
  54. if (result && result['records'] && result['records'].length > 0) {
  55. const deviceList = result['records']
  56. deviceOptions = []
  57. deviceOptions = deviceList.map((item) => {
  58. return { label: item['strinstallpos'], value: item['id'], strtype: item['strtype'], strinstallpos: item['strinstallpos'], devicekind: item['devicekind'] }
  59. })
  60. }
  61. }
  62. await getDeviceList()
  63. watch(
  64. () => {
  65. return props.columnsType;
  66. },
  67. (newVal) => {
  68. if (!newVal) return
  69. const column = getTableHeaderColumns(newVal + '_history')
  70. if (column && column.length < 1) {
  71. const arr = newVal.split('_')
  72. const columnKey = arr.reduce((prev, cur, index) => {
  73. if (index !== arr.length - 2) {
  74. return prev + '_' + cur
  75. } else {
  76. return prev
  77. }
  78. })
  79. columns.value = getTableHeaderColumns(arr[0] + '_history');
  80. } else {
  81. columns.value = column
  82. }
  83. if (alarmHistory.value) reload()
  84. },
  85. {
  86. immediate: true
  87. }
  88. );
  89. watch(() => props.scroll.y, (newVal) => {
  90. if (newVal) {
  91. tableScroll.value = { y: newVal - 100 }
  92. } else {
  93. tableScroll.value = {}
  94. }}
  95. )
  96. // 列表页面公共参数、方法
  97. const { tableContext } = useListPage({
  98. tableProps: {
  99. api: props.list,
  100. columns: props.columnsType ? columns : (props.columns as any[]),
  101. canResize: true,
  102. showTableSetting: false,
  103. showActionColumn: false,
  104. bordered: false,
  105. size: 'small',
  106. scroll: tableScroll,
  107. formConfig: {
  108. labelAlign: 'left',
  109. showAdvancedButton: false,
  110. // autoAdvancedCol: 2,
  111. schemas: [
  112. {
  113. label: '时间范围',
  114. field: 'createTime',
  115. component: 'RangePicker',
  116. defaultValue: [
  117. dayjs().subtract(1, 'day'),
  118. dayjs(),
  119. ],
  120. componentProps: {
  121. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  122. },
  123. },
  124. {
  125. label: '查询设备',
  126. field: 'gdeviceid',
  127. component: 'Select',
  128. defaultValue: deviceOptions[0] ? deviceOptions[0]['value'] : '',
  129. required: true,
  130. componentProps: {
  131. options: deviceOptions,
  132. onChange: (e, option) => {
  133. if (option && (option['strinstallpos'] || option['strtype'] || option['devicekind'])) historyType.value = option['strtype'] || option['devicekind']
  134. },
  135. },
  136. // componentProps: {
  137. // api: props.deviceListApi,
  138. // resultField: 'records',
  139. // labelField: 'strname',
  140. // valueField: 'id',
  141. // },
  142. },
  143. ],
  144. fieldMapToTime: [['createTime', ['createTime_begin', 'createTime_end'], '']],
  145. },
  146. fetchSetting: {
  147. listField: 'records',
  148. },
  149. pagination: {
  150. current: 1,
  151. pageSize: 10,
  152. pageSizeOptions: ['10', '30', '50', '100'],
  153. },
  154. beforeFetch(params) {
  155. params.devicetype = props.deviceType + '*';
  156. if (props.sysId) {
  157. params.sysId = props.sysId;
  158. }
  159. },
  160. },
  161. });
  162. //注册table数据
  163. const [registerTable, { reload, setLoading }] = tableContext;
  164. defineExpose({ setLoading })
  165. </script>
  166. <style scoped lang="less">
  167. @ventSpace: zxm;
  168. :deep(.ventSpace-table-body) {
  169. height: auto !important;
  170. }
  171. :deep(.zxm-picker){
  172. height: 30px !important;
  173. }
  174. .alarm-history-table {
  175. width: 100%;
  176. :deep(.jeecg-basic-table-form-container) {
  177. .@{ventSpace}-form {
  178. padding: 0 !important;
  179. border: none !important;
  180. margin-bottom: 0 !important;
  181. .@{ventSpace}-picker,
  182. .@{ventSpace}-select-selector {
  183. width: 100% !important;
  184. background: #00000017;
  185. border: 1px solid #b7b7b7;
  186. input,
  187. .@{ventSpace}-select-selection-item,
  188. .@{ventSpace}-picker-suffix {
  189. color: #fff;
  190. }
  191. .@{ventSpace}-select-selection-placeholder {
  192. color: #ffffffaa;
  193. }
  194. }
  195. }
  196. .@{ventSpace}-table-title {
  197. min-height: 0 !important;
  198. }
  199. }
  200. }
  201. </style>