MonitorTable.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. const listApi = '/ventanaly-device/monitor/device';
  25. const props = defineProps({
  26. columnsType: {
  27. type: String,
  28. required: true,
  29. },
  30. dataSource: {
  31. type: Array,
  32. required: true,
  33. },
  34. deviceType: {
  35. type: String,
  36. },
  37. designScope: {
  38. type: String,
  39. },
  40. title: {
  41. type: String,
  42. },
  43. });
  44. const emits = defineEmits(['selectRow']);
  45. const dataTableSource = ref([]);
  46. const loading = ref(true);
  47. const ventTableRef = ref();
  48. // 默认初始是第一行
  49. const selectRowIndex = ref(0);
  50. const tableMaxHeight = 150;
  51. watch(
  52. () => {
  53. return props.dataSource;
  54. },
  55. (newVal, oldVal) => {
  56. if (oldVal.length < 1) {
  57. // 第一次
  58. setSelectedRowKeys([newVal[0].deviceID]);
  59. }
  60. const list = [];
  61. newVal.forEach((item) => {
  62. list.push(toRaw(item));
  63. });
  64. dataTableSource.value = list;
  65. loading.value = false;
  66. }
  67. );
  68. const columns = getTableHeaderColumns(props.columnsType);
  69. // 列表页面公共参数、方法
  70. const { prefixCls, tableContext, doRequest } = useListPage({
  71. designScope: props.designScope,
  72. tableProps: {
  73. title: props.title,
  74. // api: list,
  75. dataSource: dataTableSource,
  76. columns: columns,
  77. rowSelection: { type: 'radio' },
  78. size: 'small',
  79. useSearchForm: false,
  80. showTableSetting: false,
  81. showActionColumn: false,
  82. maxHeight: tableMaxHeight,
  83. bordered: false,
  84. rowKey: 'deviceID',
  85. actionColumn: {
  86. width: 180,
  87. },
  88. beforeFetch: (params) => {
  89. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  90. },
  91. },
  92. });
  93. //注册table数据
  94. const [registerTable, { reload, setLoading, setSelectedRowKeys }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;
  95. watch(selectedRowKeys, (oldKeys, newKeys) => {
  96. const index = findIndex(dataTableSource.value, (data: any) => {
  97. return data.deviceID == selectedRowKeys.value[0];
  98. });
  99. emits('selectRow', selectedRows.value[0], index);
  100. });
  101. defineExpose({
  102. doRequest,
  103. });
  104. onMounted(() => {
  105. // 如果是https
  106. // 反之是websocket
  107. });
  108. onUnmounted(() => {});
  109. </script>
  110. <style scoped lang="less">
  111. :deep(.ant-table-body) {
  112. height: auto !important;
  113. }
  114. :deep(.jeecg-basic-table .ant-table-wrapper .ant-table-title) {
  115. min-height: 0;
  116. }
  117. </style>