1
0

MonitorTable.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="vent-table">
  3. <BasicTable ref="ventTableRef" @register="registerTable" :rowSelection="props.isShowSelect ? rowSelection: undefined" :loading="loading">
  4. <template #tableTitle>
  5. <div></div>
  6. </template>
  7. <template #tableTop>
  8. <div></div>
  9. </template>
  10. <template #bodyCell="{ column, record }">
  11. <slot name="filterCell" v-bind="{ column, record }"></slot>
  12. </template>
  13. <template #action="{ record }">
  14. <slot name="action" v-bind="{ record }"></slot>
  15. </template>
  16. </BasicTable>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. //ts语法
  21. import { defineExpose, toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
  22. import { BasicTable } from '/@/components/Table';
  23. import { useListPage } from '/@/hooks/system/useListPage';
  24. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  25. import { findIndex } from 'lodash-es';
  26. const props = defineProps({
  27. columnsType: {
  28. type: String,
  29. required: true,
  30. },
  31. dataSource: {
  32. type: Array,
  33. required: true,
  34. },
  35. deviceType: {
  36. type: String,
  37. },
  38. designScope: {
  39. type: String,
  40. },
  41. isShowSelect: {
  42. type: Boolean,
  43. default:true,
  44. },
  45. isShowPagination: {
  46. type: Boolean,
  47. default: true,
  48. },
  49. isShowActionColumn: {
  50. type: Boolean,
  51. default: false,
  52. },
  53. scroll: {
  54. type: Object,
  55. default: () => null
  56. },
  57. title: {
  58. type: String,
  59. },
  60. size: {
  61. type: String,
  62. default: 'small',
  63. },
  64. });
  65. const emits = defineEmits(['selectRow']);
  66. const dataTableSource = ref<any[]>([]);
  67. const loading = ref(true);
  68. const ventTableRef = ref();
  69. const tableMaxHeight = 150;
  70. const columns = ref([])
  71. watch(
  72. () => {
  73. return props.dataSource;
  74. },
  75. (newVal, oldVal) => {
  76. if (oldVal.length < 1 && newVal.length > 0) {
  77. // 第一次
  78. setSelectedRowKeys([newVal[0].deviceID]);
  79. }
  80. const list = <any[]>[];
  81. newVal.forEach((item) => {
  82. list.push(toRaw(item));
  83. });
  84. dataTableSource.value = list;
  85. loading.value = false;
  86. }
  87. );
  88. watch(
  89. () => {
  90. return props.columnsType;
  91. },
  92. (newVal) => {
  93. columns.value = getTableHeaderColumns(newVal);
  94. },
  95. {
  96. immediate: true
  97. }
  98. );
  99. // 列表页面公共参数、方法
  100. const { prefixCls, tableContext, doRequest } = useListPage({
  101. designScope: props.designScope,
  102. tableProps: {
  103. title: props.title,
  104. dataSource: dataTableSource,
  105. columns: columns,
  106. rowSelection: { type: props.isShowSelect? 'radio': undefined },
  107. size: props.size,
  108. useSearchForm: false,
  109. showTableSetting: false,
  110. showActionColumn: props.isShowActionColumn,
  111. maxHeight: tableMaxHeight,
  112. bordered: false,
  113. scroll: props.scroll,
  114. rowKey: 'deviceID',
  115. // striped: true,
  116. actionColumn: {
  117. width: 180,
  118. },
  119. pagination: props.isShowPagination ? {
  120. current: 1,
  121. pageSize: 5,
  122. pageSizeOptions: ['5', '10', '20'],
  123. } : false,
  124. beforeFetch: (params) => {
  125. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  126. },
  127. },
  128. });
  129. //注册table数据
  130. const [registerTable, { reload, setLoading, setSelectedRowKeys }, { rowSelection, selectedRowKeys }] = tableContext;
  131. watch(
  132. selectedRowKeys,
  133. (oldKeys, newKeys) => {
  134. const index = findIndex(dataTableSource.value, (data: any) => {
  135. return data.deviceID == selectedRowKeys.value[0];
  136. });
  137. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  138. },
  139. { immediate: false }
  140. );
  141. defineExpose({
  142. doRequest,
  143. setSelectedRowKeys,
  144. });
  145. onMounted(() => {
  146. // 如果是https
  147. // 反之是websocket
  148. });
  149. onUnmounted(() => {});
  150. </script>
  151. <style scoped lang="less">
  152. @ventSpace: zxm;
  153. :deep(.@{ventSpace}-table-body) {
  154. height: auto !important;
  155. tr > td {
  156. background: #ffffff00 !important;
  157. }
  158. tr.@{ventSpace}-table-row-selected {
  159. td {
  160. background: #007cc415 !important;
  161. }
  162. }
  163. }
  164. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  165. min-height: 0;
  166. }
  167. </style>