GroupMonitorTable.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="vent-table">
  3. <a-radio-group v-model:value="selectRowIndex" @change="setSelectedRowKeys" style="width: 100%">
  4. <a-table :columns="columns" :pagination="false" :data-source="dataTableSource" bordered style="margin-top: 5px">
  5. <template #bodyCell="{ column, record, index }">
  6. <template v-if="column.dataIndex === 'isCheck'">
  7. <a-radio :value="record.deviceID" />
  8. </template>
  9. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == 0 ? 'green' : 'red'">{{
  10. record.warnFlag == 0 ? '正常' : '报警'
  11. }}</a-tag>
  12. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == 0 ? 'default' : 'green'">{{
  13. record.netStatus == 0 ? '断开' : '连接'
  14. }}</a-tag>
  15. </template>
  16. </a-table>
  17. </a-radio-group>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. //ts语法
  22. import { defineExpose, toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
  23. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  24. const props = defineProps({
  25. columnsType: {
  26. type: String,
  27. required: true,
  28. },
  29. dataSource: {
  30. type: Array,
  31. required: true,
  32. },
  33. deviceType: {
  34. type: String,
  35. },
  36. designScope: {
  37. type: String,
  38. },
  39. title: {
  40. type: String,
  41. },
  42. });
  43. const emits = defineEmits(['selectRow']);
  44. const dataTableSource = ref<any[]>([]);
  45. const loading = ref(true);
  46. // 默认初始是第一行
  47. const selectRowIndex = ref(0);
  48. const setSelectedRowKeys = (target) => {
  49. console.log(target, Object.prototype.toString.call(target));
  50. if (Object.prototype.toString.call(target) === '[object String]') {
  51. selectRowIndex.value = target;
  52. emits('selectRow', target);
  53. } else if (Object.prototype.toString.call(target) === '[object Object]') {
  54. const data = target.target.value;
  55. selectRowIndex.value = data;
  56. emits('selectRow', data);
  57. }
  58. };
  59. /** 定义table Columns */
  60. function setColumns() {
  61. const isCheckColumn = {
  62. title: '',
  63. dataIndex: 'isCheck',
  64. width: 60,
  65. align: 'center',
  66. customCell: (_, index) => {
  67. if (index % 2 == 0) {
  68. return { rowSpan: 2 };
  69. } else {
  70. return { rowSpan: 0 };
  71. }
  72. },
  73. };
  74. const runDevice = {
  75. title: '运行风机',
  76. dataIndex: 'runDevice',
  77. width: 80,
  78. align: 'center',
  79. };
  80. let columns: any[] = getTableHeaderColumns(props.columnsType);
  81. const strinstallpos = columns.find((item) => {
  82. return item.dataIndex === 'strinstallpos' || item.dataIndex === 'strname';
  83. });
  84. if (strinstallpos) {
  85. strinstallpos.customCell = (_, index) => {
  86. if (index % 2 == 0) {
  87. return { rowSpan: 2 };
  88. } else {
  89. return { rowSpan: 0 };
  90. }
  91. };
  92. }
  93. columns.splice(1, 0, runDevice);
  94. columns = [isCheckColumn, ...columns];
  95. return columns;
  96. }
  97. const columns = setColumns();
  98. console.log('[ columns ] >', columns);
  99. watch(
  100. () => {
  101. return props.dataSource;
  102. },
  103. (newVal, oldVal) => {
  104. const list: unknown[] = [];
  105. newVal.forEach((item) => {
  106. const data: any = toRaw(item);
  107. const resultData1 = {};
  108. const resultData2 = {};
  109. // 将主风机、备风机的数据进行拆分
  110. columns.forEach((column) => {
  111. const columnKey = column.dataIndex;
  112. // data.f
  113. if (columnKey.startsWith('Fan')) {
  114. const key1 = columnKey.replace('Fan', 'Fan1');
  115. const key2 = columnKey.replace('Fan', 'Fan2');
  116. resultData1[columnKey] = data[key1];
  117. resultData2[columnKey] = data[key2];
  118. } else {
  119. resultData1[columnKey] = resultData2[columnKey] = data[columnKey];
  120. }
  121. });
  122. resultData1['deviceID'] = resultData2['deviceID'] = data['deviceID'];
  123. resultData1['runDevice'] = '主机';
  124. resultData2['runDevice'] = '备机';
  125. list.push(resultData1, resultData2);
  126. // const emptyData = new Object();
  127. // for (const key in data) {
  128. // if (
  129. // Object.prototype.hasOwnProperty.call(data, key) &&
  130. // key !== 'deviceID' &&
  131. // key !== 'Fan1StartStatus' &&
  132. // key !== 'Fan2StartStatus' &&
  133. // key !== 'strinstallpos' &&
  134. // key !== 'readTime'
  135. // ) {
  136. // emptyData[key] = '-';
  137. // } else {
  138. // emptyData[key] = data[key];
  139. // }
  140. // }
  141. // if (data.Fan1StartStatus == 1) {
  142. // // 主风机启动
  143. // data['runDevice'] = '主机';
  144. // emptyData['runDevice'] = '备机';
  145. // list.push(data, emptyData);
  146. // } else if (data.Fan2StartStatus == 1) {
  147. // // 备风机启动
  148. // data['runDevice'] = '备机';
  149. // emptyData['runDevice'] = '主机';
  150. // list.push(emptyData, data);
  151. // } else {
  152. // list.push({ ...emptyData, runDevice: '主机' }, { ...emptyData, runDevice: '备机' });
  153. // }
  154. });
  155. if (oldVal.length < 1) {
  156. // 第一次
  157. setSelectedRowKeys(list[0]['deviceID']);
  158. }
  159. dataTableSource.value = list;
  160. loading.value = false;
  161. }
  162. );
  163. onMounted(() => {
  164. // 如果是https
  165. // 反之是websocket
  166. });
  167. onUnmounted(() => {});
  168. </script>
  169. <style scoped lang="less">
  170. :deep(.ant-table-body) {
  171. height: auto !important;
  172. }
  173. :deep(.jeecg-basic-table .ant-table-wrapper .ant-table-title) {
  174. min-height: 0;
  175. }
  176. </style>