MonitorTable.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div class="vent-table">
  3. <BasicTable ref="ventTableRef" @register="registerTable" :rowSelection="rowSelection" :pagination="false" :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. </BasicTable>
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. //ts语法
  18. import { defineExpose, toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
  19. import { BasicTable } from '/@/components/Table';
  20. import { useListPage } from '/@/hooks/system/useListPage';
  21. import { list, deleteUser, batchDeleteUser, getImportUrl, getExportUrl, frozenBatch, syncUser } from '../../../system/user/user.api';
  22. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  23. import { findIndex } from 'lodash-es';
  24. import { computed } from '@vue/reactivity';
  25. const listApi = '/ventanaly-device/monitor/device';
  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. title: {
  42. type: String,
  43. },
  44. size: {
  45. type: String,
  46. default: 'small',
  47. },
  48. });
  49. const emits = defineEmits(['selectRow']);
  50. const dataTableSource = ref([]);
  51. const loading = ref(true);
  52. const ventTableRef = ref();
  53. // 默认初始是第一行
  54. const selectRowIndex = ref(0);
  55. const tableMaxHeight = 150;
  56. watch(
  57. () => {
  58. return props.dataSource;
  59. },
  60. (newVal, oldVal) => {
  61. if (oldVal.length < 1 && newVal.length > 0) {
  62. // 第一次
  63. setSelectedRowKeys([newVal[0].deviceID]);
  64. }
  65. const list = [];
  66. newVal.forEach((item) => {
  67. list.push(toRaw(item));
  68. });
  69. dataTableSource.value = list;
  70. loading.value = false;
  71. }
  72. );
  73. const columns = getTableHeaderColumns(props.columnsType);
  74. console.log('[ columns ] >', columns);
  75. // 列表页面公共参数、方法
  76. const { prefixCls, tableContext, doRequest } = useListPage({
  77. designScope: props.designScope,
  78. tableProps: {
  79. title: props.title,
  80. // api: list,
  81. dataSource: dataTableSource,
  82. columns: columns,
  83. rowSelection: { type: 'radio' },
  84. size: props.size,
  85. useSearchForm: false,
  86. showTableSetting: false,
  87. showActionColumn: false,
  88. maxHeight: tableMaxHeight,
  89. bordered: false,
  90. rowKey: 'deviceID',
  91. striped: true,
  92. actionColumn: {
  93. width: 180,
  94. },
  95. pagination: {
  96. current: 1,
  97. pageSize: 5,
  98. pageSizeOptions: ['5', '10', '20'],
  99. },
  100. beforeFetch: (params) => {
  101. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  102. },
  103. },
  104. });
  105. //注册table数据
  106. const [registerTable, { reload, setLoading, setSelectedRowKeys }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;
  107. watch(
  108. selectedRowKeys,
  109. (oldKeys, newKeys) => {
  110. const index = findIndex(dataTableSource.value, (data: any) => {
  111. return data.deviceID == selectedRowKeys.value[0];
  112. });
  113. emits('selectRow', selectedRows.value[0], index);
  114. },
  115. { immediate: false }
  116. );
  117. defineExpose({
  118. doRequest,
  119. setSelectedRowKeys,
  120. });
  121. onMounted(() => {
  122. // 如果是https
  123. // 反之是websocket
  124. });
  125. onUnmounted(() => {});
  126. </script>
  127. <style scoped lang="less">
  128. :deep(.ant-table-body) {
  129. height: auto !important;
  130. }
  131. :deep(.jeecg-basic-table .ant-table-wrapper .ant-table-title) {
  132. min-height: 0;
  133. }
  134. .jeecg-basic-table-row__striped {
  135. background: #97efff11 !important;
  136. }
  137. </style>