AlarmHistoryTable.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="history-table">
  3. <BasicTable ref="historyTable" @register="registerTable" >
  4. <template #bodyCell="{ column, record }">
  5. <slot name="filterCell" v-bind="{ column, record }"></slot>
  6. </template>
  7. </BasicTable>
  8. </div>
  9. </template>
  10. <script lang="ts" name="system-user" setup>
  11. //ts语法
  12. import { watchEffect, ref, watch, defineExpose } from 'vue';
  13. import { FormSchema } from '/@/components/Form/index';
  14. import { BasicTable } from '/@/components/Table';
  15. import { useListPage } from '/@/hooks/system/useListPage';
  16. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  17. import { warningHistoryList } from './alarm.api'
  18. import dayjs from 'dayjs';
  19. import { getAutoScrollContainer } from '/@/utils/common/compUtils';
  20. const historyTable = ref();
  21. const emit = defineEmits(['change']);
  22. const props = defineProps({
  23. columnsType: {
  24. type: String,
  25. },
  26. columns: {
  27. type: Array,
  28. // required: true,
  29. default: () => [],
  30. },
  31. deviceType: {
  32. type: String,
  33. },
  34. designScope: {
  35. type: String,
  36. },
  37. sysId: {
  38. type: String,
  39. },
  40. scroll: {
  41. type: Object,
  42. default: { y: 0 }
  43. },
  44. formSchemas: {
  45. type: Array<FormSchema>,
  46. default: () => []
  47. }
  48. });
  49. const columns = ref([])
  50. const tableScroll = props.scroll.y ? ref({ y: props.scroll.y - 100 }) : ref({})
  51. watch(
  52. () => {
  53. return props.columnsType;
  54. },
  55. (newVal) => {
  56. if (!newVal) return
  57. const column = getTableHeaderColumns(newVal + '_history')
  58. if (column && column.length < 1) {
  59. const arr = newVal.split('_')
  60. const columnKey = arr.reduce((prev, cur, index) => {
  61. if (index !== arr.length - 2) {
  62. return prev + '_' + cur
  63. } else {
  64. return prev
  65. }
  66. })
  67. columns.value = getTableHeaderColumns(arr[0] + '_history');
  68. } else {
  69. columns.value = column
  70. }
  71. if(historyTable.value) reload()
  72. },
  73. {
  74. immediate: true
  75. }
  76. );
  77. watch(() => props.scroll.y, (newVal) => {
  78. if(newVal){
  79. tableScroll.value = {y: newVal - 100 }
  80. }else{
  81. tableScroll.value = {}
  82. }
  83. })
  84. // 列表页面公共参数、方法
  85. const { tableContext } = useListPage({
  86. tableProps: {
  87. api: warningHistoryList,
  88. columns: props.columnsType ? columns : (props.columns as any[]),
  89. canResize: true,
  90. showTableSetting: false,
  91. showActionColumn: false,
  92. bordered: false,
  93. size: 'small',
  94. scroll: tableScroll,
  95. formConfig: {
  96. labelAlign: 'left',
  97. showAdvancedButton: false,
  98. // autoAdvancedCol: 2,
  99. baseColProps: {
  100. // offset: 0.5,
  101. xs: 24,
  102. sm: 24,
  103. md: 24,
  104. lg: 9,
  105. xl: 7,
  106. xxl: 4,
  107. },
  108. schemas: props.formSchemas.length > 0 ? props.formSchemas : [
  109. // {
  110. // label: '报警时间区间',
  111. // field: 'tickectDate',
  112. // component: 'TimeRangePicker',
  113. // componentProps: {
  114. // placeholder: ['报警开始时间', '报警结束时间'],
  115. // valueFormat: 'YYYY-MM-DD HH:mm:ss',
  116. // },
  117. // },
  118. {
  119. field: 'starttime_begin',
  120. label: '开始时间',
  121. component: 'DatePicker',
  122. required: true,
  123. componentProps: {
  124. showTime: true,
  125. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  126. getPopupContainer: getAutoScrollContainer,
  127. },
  128. },
  129. {
  130. field: 'starttime_end',
  131. label: '结束时间',
  132. component: 'DatePicker',
  133. required: true,
  134. componentProps: {
  135. showTime: true,
  136. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  137. getPopupContainer: getAutoScrollContainer,
  138. },
  139. },
  140. ],
  141. // fieldMapToTime: [['tickectDate', ['starttime_begin', 'starttime_end'], '']],
  142. },
  143. fetchSetting: {
  144. listField: 'records',
  145. pageField: 'pages',
  146. sizeField: 'size',
  147. totalField: 'total',
  148. },
  149. beforeFetch(params) {
  150. params.strtype = props.deviceType + '*';
  151. if(props.sysId){
  152. params.sysId = props.sysId;
  153. }
  154. if(params['datalist.pages'])params['pages'] = params['datalist.pages']
  155. if (params['datalist.size']) params['pageSize'] = params['datalist.size']
  156. },
  157. afterFetch(resultItems) {
  158. resultItems.map((item) => {
  159. Object.assign(item, item['readData']);
  160. });
  161. return resultItems;
  162. },
  163. },
  164. });
  165. //注册table数据
  166. const [registerTable, { getDataSource, reload, setLoading }] = tableContext;
  167. watchEffect(() => {
  168. if (historyTable.value && getDataSource) {
  169. const data = getDataSource() || [];
  170. emit('change', data);
  171. console.log('[ data ] >', data);
  172. }
  173. });
  174. defineExpose({ setLoading })
  175. </script>
  176. <style scoped lang="less">
  177. @import '/@/design/vent/color.less';
  178. :deep(.@{ventSpace}-table-body) {
  179. height: auto !important;
  180. }
  181. :deep(.zxm-picker){
  182. height: 30px !important;
  183. }
  184. .history-table {
  185. width: 100%;
  186. :deep(.jeecg-basic-table-form-container) {
  187. .@{ventSpace}-form {
  188. padding: 0 !important;
  189. border: none !important;
  190. margin-bottom: 0 !important;
  191. .@{ventSpace}-picker,
  192. .@{ventSpace}-select-selector {
  193. width: 100% !important;
  194. height: 100%;
  195. background: #00000017;
  196. border: 1px solid #b7b7b7;
  197. input,
  198. .@{ventSpace}-select-selection-item,
  199. .@{ventSpace}-picker-suffix {
  200. color: #fff;
  201. }
  202. .@{ventSpace}-select-selection-placeholder {
  203. color: #ffffffaa;
  204. }
  205. }
  206. }
  207. .@{ventSpace}-table-title {
  208. min-height: 0 !important;
  209. }
  210. }
  211. }
  212. ::v-deep .zxm-table-content{
  213. overflow: hidden !important;
  214. }
  215. </style>