alarmHistoryTable.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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(
  78. () => props.scroll.y,
  79. (newVal) => {
  80. if (newVal) {
  81. tableScroll.value = { y: newVal - 100 };
  82. } else {
  83. tableScroll.value = {};
  84. }
  85. }
  86. );
  87. // 列表页面公共参数、方法
  88. const { tableContext } = useListPage({
  89. tableProps: {
  90. api: warningHistoryList,
  91. columns: props.columnsType ? columns : (props.columns as any[]),
  92. canResize: true,
  93. showTableSetting: false,
  94. showActionColumn: false,
  95. bordered: false,
  96. size: 'small',
  97. scroll: tableScroll,
  98. formConfig: {
  99. labelAlign: 'left',
  100. showAdvancedButton: false,
  101. // autoAdvancedCol: 2,
  102. baseColProps: {
  103. // offset: 0.5,
  104. xs: 24,
  105. sm: 24,
  106. md: 24,
  107. lg: 9,
  108. xl: 7,
  109. xxl: 4,
  110. },
  111. schemas:
  112. props.formSchemas.length > 0
  113. ? props.formSchemas
  114. : [
  115. // {
  116. // label: '报警时间区间',
  117. // field: 'tickectDate',
  118. // component: 'TimeRangePicker',
  119. // componentProps: {
  120. // placeholder: ['报警开始时间', '报警结束时间'],
  121. // valueFormat: 'YYYY-MM-DD HH:mm:ss',
  122. // },
  123. // },
  124. {
  125. field: 'starttime_begin',
  126. label: '开始时间',
  127. component: 'DatePicker',
  128. defaultValue: dayjs().subtract(1, 'day'),
  129. required: true,
  130. labelWidth: 140,
  131. componentProps: {
  132. showTime: true,
  133. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  134. getPopupContainer: getAutoScrollContainer,
  135. },
  136. },
  137. {
  138. field: 'starttime_end',
  139. label: '结束时间',
  140. component: 'DatePicker',
  141. required: true,
  142. defaultValue: dayjs(),
  143. labelWidth: 140,
  144. componentProps: {
  145. showTime: true,
  146. valueFormat: 'YYYY-MM-DD HH:mm:ss',
  147. getPopupContainer: getAutoScrollContainer,
  148. },
  149. },
  150. ],
  151. // fieldMapToTime: [['tickectDate', ['starttime_begin', 'starttime_end'], '']],
  152. },
  153. fetchSetting: {
  154. listField: 'records',
  155. pageField: 'pages',
  156. sizeField: 'size',
  157. totalField: 'total',
  158. },
  159. beforeFetch(params) {
  160. params.strtype = props.deviceType + '*';
  161. if (props.sysId) {
  162. params.sysId = props.sysId;
  163. }
  164. if (params['datalist.pages']) params['pages'] = params['datalist.pages'];
  165. if (params['datalist.size']) params['pageSize'] = params['datalist.size'];
  166. },
  167. afterFetch(resultItems) {
  168. resultItems.map((item) => {
  169. Object.assign(item, item['readData']);
  170. });
  171. return resultItems;
  172. },
  173. },
  174. });
  175. //注册table数据
  176. const [registerTable, { getDataSource, reload, setLoading }] = tableContext;
  177. watchEffect(() => {
  178. if (historyTable.value && getDataSource) {
  179. const data = getDataSource() || [];
  180. emit('change', data);
  181. console.log('[ data ] >', data);
  182. }
  183. });
  184. defineExpose({ setLoading });
  185. </script>
  186. <style scoped lang="less">
  187. @import '/@/design/vent/color.less';
  188. :deep(.@{ventSpace}-table-body) {
  189. height: auto !important;
  190. }
  191. :deep(.zxm-picker) {
  192. height: 30px !important;
  193. }
  194. .history-table {
  195. width: 100%;
  196. :deep(.jeecg-basic-table-form-container) {
  197. .@{ventSpace}-form {
  198. padding: 0 !important;
  199. border: none !important;
  200. margin-bottom: 0 !important;
  201. .@{ventSpace}-picker,
  202. .@{ventSpace}-select-selector {
  203. width: 100% !important;
  204. height: 100%;
  205. background: #00000017;
  206. border: 1px solid #b7b7b7;
  207. input,
  208. .@{ventSpace}-select-selection-item,
  209. .@{ventSpace}-picker-suffix {
  210. color: #fff;
  211. }
  212. .@{ventSpace}-select-selection-placeholder {
  213. color: #ffffffaa;
  214. }
  215. }
  216. }
  217. .@{ventSpace}-table-title {
  218. min-height: 0 !important;
  219. }
  220. }
  221. }
  222. ::v-deep .zxm-table-content {
  223. overflow: hidden !important;
  224. }
  225. </style>