MonitorTable.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="vent-table">
  3. <BasicTable ref="ventTableRef" @register="registerTable" :rowSelection="props.isShowSelect ? rowSelection: undefined">
  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 && newVal && 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. if(ventTableRef.value) setLoading(false)
  86. },
  87. {
  88. immediate: true
  89. }
  90. );
  91. watch(
  92. () => {
  93. return props.columnsType;
  94. },
  95. (newVal) => {
  96. const column = getTableHeaderColumns(newVal)
  97. if(column && column.length < 1){
  98. const arr = newVal.split('_')
  99. const columnKey = arr.reduce((prev, cur, index) => {
  100. if(index !== arr.length - 2){
  101. return prev + '_' + cur
  102. }else {
  103. return prev
  104. }
  105. })
  106. columns.value = getTableHeaderColumns(arr[0]+'_monitor');
  107. }else{
  108. columns.value = column
  109. }
  110. },
  111. {
  112. immediate: true
  113. }
  114. );
  115. // 列表页面公共参数、方法
  116. const { prefixCls, tableContext, doRequest } = useListPage({
  117. designScope: props.designScope,
  118. tableProps: {
  119. title: props.title,
  120. dataSource: dataTableSource,
  121. columns: columns,
  122. rowSelection: { type: props.isShowSelect? 'radio': undefined },
  123. size: props.size,
  124. useSearchForm: false,
  125. showTableSetting: false,
  126. showActionColumn: props.isShowActionColumn,
  127. maxHeight: tableMaxHeight,
  128. bordered: false,
  129. scroll: props.scroll,
  130. rowKey: 'deviceID',
  131. // striped: true,
  132. loading: true,
  133. actionColumn: {
  134. width: 180,
  135. },
  136. pagination: props.isShowPagination ? {
  137. current: 1,
  138. pageSize: 5,
  139. pageSizeOptions: ['5', '10', '20'],
  140. } : false,
  141. beforeFetch: (params) => {
  142. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  143. },
  144. },
  145. });
  146. //注册table数据
  147. const [registerTable, { reload, setLoading, setSelectedRowKeys }, { rowSelection, selectedRowKeys, }] = tableContext;
  148. watch(
  149. selectedRowKeys,
  150. (oldKeys, newKeys) => {
  151. const index = findIndex(dataTableSource.value, (data: any) => {
  152. return data.deviceID == selectedRowKeys.value[0];
  153. });
  154. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  155. },
  156. { immediate: false }
  157. );
  158. defineExpose({
  159. doRequest,
  160. setSelectedRowKeys,
  161. setLoading
  162. });
  163. onMounted(() => {
  164. // 如果是https
  165. // 反之是websocket
  166. });
  167. onUnmounted(() => {});
  168. </script>
  169. <style scoped lang="less">
  170. @ventSpace: zxm;
  171. :deep(.@{ventSpace}-table-body) {
  172. height: auto !important;
  173. tr > td {
  174. background: #ffffff00 !important;
  175. }
  176. tr.@{ventSpace}-table-row-selected {
  177. td {
  178. background: #007cc415 !important;
  179. }
  180. }
  181. }
  182. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  183. min-height: 0;
  184. }
  185. </style>